If, soon after pursuing all These suggestions, you continue to have problems with RAM and CPU, then probably it’s simply because your application is really way too significant, and a Raspberry Pi isn't the right Resource for the work. In this case, you might like to evaluate alternative embedded board, https://stemrobot39506.acidblog.net/57982158/5-tips-about-ros-compatible-robot-you-can-use-today