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

Idiomatic way to tell whether code is on simulator or real robot

asked 2020-12-23 17:15:12 -0500

pitosalas gravatar image

The simulation (Gazebo) can differ from the actual robot (GoPiGo3) is particular ways, e.g the number of readings in a scan topic - in my case 360 in gazebo and 720 on Ydlidar X4. So I often have either a constant GAZEBO=True or an inline if True: both of which are kind of ugly. Is there a more typical way of making code behave a little differently depending on where it is running?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-24 06:49:35 -0500

gvdhoorn gravatar image

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.

edit flag offensive delete link more

Comments

I always tell "my" students to treat Gazebo as "just a piece of hw", and don't think of it as a special simulator or anything like that.

You really want to avoid embedding special cases / code paths "for this simulator I always use" in your code, as the minute someone else uses something else, those tend to break.

They also reduce the reuse potential of your code significantly.

gvdhoorn gravatar image gvdhoorn  ( 2020-12-24 06:50:54 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-12-23 17:15:12 -0500

Seen: 74 times

Last updated: Dec 24 '20