Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You're recreating the published vel_pub_ in the scan callback. This should only happen once and then you should use that one (i.e. then one you create in the main) unless there is some nifty stuff in ROS that automatically reuses the same publication when another publisher is created for the same topic.

Besides that your program flow seems wrong. You are doing everything in the scan callback. This means your whole behaviour will only consider that one scan and new scans will be ignored.

In addition you do your behaviour for each range of the scan, not for each scan.

The usual way for such a behaviour would be to first check the minimal range to the scan and then adapt the velocity that is sent out regularly. Any waiting/slowing down logic need to be done incrementally in the background as you'd probably want to react to new scans.

You're recreating the published vel_pub_ in the scan callback. This should only happen once and then you should use that one (i.e. then one you create in the main) unless there is some nifty stuff in ROS that automatically reuses the same publication when another publisher is created for the same topic.

Besides that your program flow seems wrong. You are doing everything in the scan callback. This means your whole behaviour will only consider that one scan and new scans will be ignored.

In addition you do your behaviour for each range of the scan, not for each scan.

The usual way for such a behaviour would be to first check the minimal range to the scan and then adapt the velocity that is sent out regularly. Any waiting/slowing down logic need to be done incrementally in the background as you'd probably want to react to new scans.

Update: In your new version you are not saving the speed that you reduce, but you always recalculate that. In addition you should also set a minimum speed for approaching. There is also no case for not slowing down when far away.