ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

The CPU skyrockets when i launch a node.

asked 2021-10-22 21:28:08 -0500

Nick_JR gravatar image

updated 2021-10-26 08:55:29 -0500

lucasw gravatar image

Hello wise people of the Ros Answers realm,

I have a node that performs a random walk.In order to get the information i need(pose,laser readings etc) and keep my code somewhat clean, i created 2 classes which, i instanciate passing as an argument the namespace of the robot(robot_1,robot_2 etc). In the init function of the first class i start an odom subscriber and a cmd_vel publisher while in the other class i just subscribe to the /namespace/laser_scan topic.

I launch the said node for 4-5 robots in the stage simulator and everything seem to work fine.The node is runing correctly but the cpu usage skyrockets at 100% on all cores.This happens only when i launch this node for multiple robots. Why is this happening?Im sure that i am missing something but i cant figure out what it is. Thanks in advance.

The links to the node and classes.




edit retag flag offensive close merge delete


Hi Nick_JR would you be able to give more details on your hardware setup otherwise it’s hard to say. There are many factors your memory, if you have a GPU and your simulation is using it. Each robot is like opening a new session of the simulator -not quite but the simulator has to run all processes for each robot simultaneously

osilva gravatar image osilva  ( 2021-10-23 07:26:08 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-10-23 08:37:01 -0500

Mike Scheutzow gravatar image

One issue is that your while loops (in main() and fix_yaw()) are executing as fast as the cpu core can run. The proper fix is to sleep() inside these loops. Unless you have a very good reason, don't execute those loops more than 100 times a second.

You can use a rospy::Rate object to publish to cmd_vel with (mostly) fixed period. It depends on your hardware, but 10 or 20 Hz is usually fast enough for cmd_vel.

edit flag offensive delete link more

Question Tools



Asked: 2021-10-22 21:28:08 -0500

Seen: 138 times

Last updated: Oct 23 '21