hi ,

i have a question about odometry , here is the code i'm using to get odometry from wheel encoder

i don't understand something , why vth unit is m/s ? if ' th' is an angle it should be in radians but since vth unit is m/s then 'th' is not in radian , i don't understant why it's working , because when i transform 'vth' to rd/s so that 'th' be in radian the odometry is not working so i'm really confuse

 dt=(current_time - last_time).toSec();
tick_Left = tick_l - _PreviousLeftEncoderCounts;
tick_Right = tick_f - _PreviousRightEncoderCounts;

speed_left = (tick_Left * DistancePerCount) / dt;  //speed left wheel   in m/s
speed_right = (tick_Right * DistancePerCount) / dt; // speed right wheel in m/s

vx = (speed_right + speed_left) / 2;   // vx in m/s
vy = 0;
vth = (speed_right - speed_left)/lengthBetweenWheels;

//position of the robot
double delta_x = (vx * cos(th)) * dt;
double delta_y = (vx * sin(th)) * dt;
double delta_th = vth * dt;   // what is the unit of delta_teta ?

x += delta_x;
y += delta_y;
th += delta_th; // teta should be in radian ?

geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(th);

geometry_msgs::TransformStamped odom_trans;

odom_trans.transform.translation.x = x;
odom_trans.transform.translation.y = y;
odom_trans.transform.translation.z = 0.0;
odom_trans.transform.rotation = odom_quat;

//send the transform

//Odometry message
nav_msgs::Odometry odom;

//set the position
odom.pose.pose.position.x = x;
odom.pose.pose.position.y = y;
odom.pose.pose.position.z = 0.0;
odom.pose.pose.orientation = odom_quat;

//set the velocity
odom.twist.twist.linear.x = vx;
odom.twist.twist.linear.y = vy;
odom.twist.twist.angular.z = vth;

//publish the message
odom_pub.publish(odom);
_PreviousLeftEncoderCounts = tick_x;
_PreviousRightEncoderCounts = tick_y;

last_time = current_time;

edit retag close merge delete

Sort by » oldest newest most voted dt unit is time (seconds) as you see it defined in the first line.

 dt=(current_time - last_time).toSec();


It might seem odd without some theoretical background but vth describes an angular speed and it's unit is rad/s

vth = (speed_right - speed_left)/lengthBetweenTwoWheels;


It is explained here , simple trigonometry.

And if you double check, vth unit as per that equation is not m/s but just s^-1 (or 1/s) which is actually correct, think about rpm (revolutions per minute) whose unit is 1/s (revolutions don't have a unit)

more

thank you for answering i know that answer but i'm confused why it's not working with navigation stack so i was wondering if i miss something with it but i guess my problem is no comming from odmetry

You are confused because you thing vth is m/s but it is 1/s, you compute v_left - v_right but then divide by a distance unit so the meter unit is removed.