[ROS Q&A] How to move a robot to a certain point using Twist

Written by Ricardo Tellez

06/11/2017


Original questions here: https://answers.ros.org/question/273384/how-to-move-to-a-certain-point-in-space-using-twist-cmd_vel/

Q: How to move to a certain point in space using Twist /cmd_vel?

A: what you are talking about is called Robot navigation, that is, the ability of the robot to go from one place to another.

Then, in order to achieve that, you need to decide at least the following three things:

In which frame are you measuring the coordinates (0,0) and (5,5)?
Do you need to have obstacle avoidance (that is, avoid any obstacle that may appear between (0,0) and (5,5) when your robot is moving towards the end location)?
Is it the location where the robot moves known or unknown?

Let’s assume the simplest answer to the questions above:

We are measuring the coordinates in the odometry frame (I’m assuming you know what odometry is). The problem with this frame is that has a sift (an error) which increases over time. But for your example is good enough.
Let’s say, there are no obstacles in the path. Hence, we do not have to implement an obstacle avoidance algorithm like potential fields or else.
Let’s say it is and unknown environment, of which we are not going to build a map.

Even if this is a very simple setup, that setup can be used, for example, to move the robot to the position of a detected target. Imagine that the robot has a camera and a program that detects people. Then, once the program detects a person in 5 meters in front of the robot, it means that the robot can go to the person location using that simple framework we defined in the questions above.

Now, you need to built a controller that converts the distances from the current position AND orientation of the robot into velocity commands that are sent to the /cmd_vel of the robot to make it move towards the location. That controller can be built in many ways.

A simple controller to do that would be the following:

If the robot (odometry) orientation is not towards the target, then rotate only the robot until its orientation is towards the target.

speed = Twist()
speed.linear.x = 0.0
speed.angular.z = 0.2

Once the robot is headed towards the target, just move straight towards the goal until reached

speed = Twist()
speed.linear.x = 0.5
speed.angular.z = 0.0

I have created this video that shows how that controller works with a Husky robot in a Gazebo simulated environment.

More complex controllers can be implemented that optimize the time to reach the goal, or other factors like moving faster when far away from goal and moving slower when getting closer.

In case you want to make the robot include obstacle avoidance, navigation in bigger environments of which a map can be built, then you need to use the Navigation Stack of ROS which includes all that (and more).

Topics:
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This