If, after following all These guidelines, you continue to have problems with RAM and CPU, then maybe it’s simply because your software is de facto way too weighty, in addition to a Raspberry Pi isn't the suitable Software for that job. In such cases, you might want to check out https://juliuswuoam.blogsvila.com/27078016/ros-compatible-robot-an-overview