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

The CPU skyrockets when i launch a node.

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

Nick_JR gravatar image

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

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.

Robot_Class

Laser_Class

Random_Walk_Node

edit retag flag offensive close merge delete

Comments

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 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

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

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

3 followers

Stats

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

Seen: 182 times

Last updated: Oct 23 '21