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

how to get the linear velocity in the robot heading direction with gazebo/link_states?

asked 2023-08-01 09:38:03 -0500

I try to get the heading linear velocity from the /odom message which contains the twist message about the robot, but what the velocity shows in the twist message is along the x and y direction in the wolrd frame. I try to get the heading velocity with twist.linear.x / cos(yaw)[yaw is the robot heading obtained from /odom also ], I also try to compute the twist.linear.y/sin(alpha), and sqrt(vxvx + vyvy), these three result are not the at some point, I am confused about it. Besides, I have a urdf model in gazebo which is a diff drive robot, I found if can only set the twist.linear.x and twist.angular.z in the cmd_vel, the model can operate correctly in gazebo, how does it works without providing velocity in the y direction? how doest it know if the twist.linear.x I set is heading velocity of the robot or the one in the x direction of world frame?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2023-08-02 07:35:15 -0500

bluegiraffe-sc gravatar image

updated 2023-08-02 07:41:41 -0500

Hi!

I see a bit of confusion in your question. I see that, in both cases, you want to get/set the heading velocity of your robot. I try to expand on the two topics you are describing.

  • odom: you are looking at the estimated pose and velocity of the robot, expressed in the map reference frame. To get the heading velocity, the three methods you are trying to use (sqrt(twist.linear.x ** 2 + twist.linear.y ** 2) or twist.linear.x / cos(yaw) or twist.linear.t / sin(yaw)) are good and should give the same result. If it is not the case, the problem might be due to how you get the yaw angle from the pose quaternion. Can you give some more detail about it?

  • cmd_vel: these are the commands you are sending to your wheels, expressed in base_link. Such a reference frame has (by convention) the x pointing in front of the robot, the z pointing upward, and the y oriented accordingly. As you have a differential drive robot, all you can do with your wheels is a combination of rotation in-place (i.e. rotating around the vertical axis, which you can set with twist.angular.z), and moving straight forward (which you can set with twist.linear.x). Explicitly answering your question, it can work without setting the y direction as a movement toward left (or right) results from a 90° rotation around z combined with a linear movement along x.

Hope this helps you with your robot!

edit flag offensive delete link more

Comments

hi! Thanks for you detail explanation! the code that I try to get the robot heading is as below

void localizationStateCallback(const nav_msgs::Odometry::ConstPtr& msg) { cur_pose_.x = msg->pose.pose.position.x; cur_pose_.y = msg->pose.pose.position.y; cur_pose_.yaw = tf::getYaw(msg->pose.pose.orientation); cur_pose_.v = sqrt(msg->twist.twist.linear.x * msg->twist.twist.linear.x + msg->twist.twist.linear.y * msg->twist.twist.linear.y); // this way would loose the information about the forward or reverse of robot cur_pose_.w = msg->twist.twist.angular.z; }

so like I said, I try to get the heading velocity with the twist.linear.x / cos(yaw), this way can have the information about the robot is driving forward or backward. Unfortunately, when the robot is movinfg, the log shows that the velocity is correct at some point, like the max velocity shold be less than 3m/s, but the log shows the velocity

sean-youhaochan gravatar image sean-youhaochan  ( 2023-08-07 01:57:04 -0500 )edit

I try to look into the yaw and the twist.linear.x , twist.linear.y, and compute the heading velocity by calculator..., indeed, the result is the same the one in the log. So I am confused about where is the problem?

sean-youhaochan gravatar image sean-youhaochan  ( 2023-08-07 01:58:36 -0500 )edit

by the way, the /odom message comes from directly from /gazebo/link_states, I write a python scrupt to read the base_link states and publsh it in the /odom topic. I think the data coming from gazebo/link_states should be the accurate pose of robot. looking forward to your reply! ^ ^

sean-youhaochan gravatar image sean-youhaochan  ( 2023-08-07 03:59:02 -0500 )edit

Question Tools

Stats

Asked: 2023-08-01 09:38:03 -0500

Seen: 296 times

Last updated: Aug 02 '23