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

Revision history [back]

click to hide/show revision 1
initial version

Is there a more typical way of making code behave a little differently depending on where it is running?

I would say "no".

And I don't believe there should be one, as ideally your nodes (or other nodes) don't have to realise there is a simulation "on the other side" of topics/services/actions.

If you need different settings, which I believe is what you are asking for, then I would suggest creating multiple .launch files. For your simulation case, you'd load the .launch file which initialises your application with "simulation settings". For use with real hw, you'd create a similar .launch file, but then it loads settings which work for your real hw.

In your specific case, you'd have a setting for the nr of points in a LaserScan to the appropriate value.

(but I'm not entirely sure why you can't len(msg.ranges) or msg.ranges.size() instead)

So I often have either a constant GAZEBO=True or an inline if True: both of which are kind of ugly

yes, that is indeed really rather ugly, and I would really recommend you avoid doing that.