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

Revision history [back]

Okay, there a few thing you need to fix in your code to get it to perform the way you want.

At the moment, the node doesn't do anything, the main function initialises the node then spins forever. You're not creating an instance of you nodo_control class so none of the code in there is getting executed. This is the first thing to fix.

Your laserCallback function includes the following lines:

while not rospy.is_shutdown():
          current_time = rospy.Time.now()

This is going to loop forever until the node shuts down setting the current_time variable, meaning the callback function will block the first time it is run until you kill the node.

You'll want to create your publisher at the same time as you register the callback function for the laser scans, you can't create it and instantly use it in the same function. These publishers should be setup once and used for the lifetime of the node.

I'd recommend not using a class for this until you're more familiar with python, maybe copy and paste the subscriber example here and add the global variables to store the averages as a start.

Hope this helps.