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

There are many possible ways this could be achieved. Since you haven't specified what type of simulated robot you're using, I will assume that you're using Stage.

It sounds as if you don't want to use a loop, you just want to perform move_forward() and turn() one or more times... so there should be no reason to include that code in the while loop. An if (ros::ok()) might be in order though, just in case.

With stageros if you issue a twist message, the simulator will execute that command, and then timeout if no new communication is received. Otherwise, the robot will keep moving. For example, if the timeout is 2 seconds long, and no new twist messages are received in less than 2 seconds after the last message was received, and that last message was move with Vx=V an all other velocities == 0, then the robot would have moved 2*V meters forward (with a little error, of course).

In each of the movement methods you can include rostime references the API is here... sleepUntil seems useful. I presume that you've also checked the wiki before asking.

Finally, you haven't said what you're doing with the encoder values.. if you're not using them to determine when to stop moving (since you seem to want to use time), then they can be read/collected in a different node.