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

Question about odometry and radians unit

asked 2018-08-03 03:00:24 -0500

kesuke gravatar image

updated 2018-08-04 16:02:43 -0500

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.header.stamp = current_time;
    odom_trans.header.frame_id = "odom";
    odom_trans.child_frame_id = "base_link";

    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;
    odom.header.stamp = current_time;
    odom.header.frame_id = "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.child_frame_id = "base_link";
    odom.twist.twist.linear.x = vx;
    odom.twist.twist.linear.y = vy;
    odom.twist.twist.angular.z = vth;

    //publish the message
    _PreviousLeftEncoderCounts = tick_x;
    _PreviousRightEncoderCounts = tick_y;

    last_time = current_time;
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-03 03:44:21 -0500

Mehdi. gravatar image

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)

edit flag offensive delete link 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

kesuke gravatar image kesuke  ( 2018-08-03 04:24:21 -0500 )edit

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.

Mehdi. gravatar image Mehdi.  ( 2018-08-03 06:31:59 -0500 )edit

@Mehdi thank i got it

kesuke gravatar image kesuke  ( 2018-08-03 06:54:31 -0500 )edit

Question Tools



Asked: 2018-08-03 03:00:24 -0500

Seen: 585 times

Last updated: Aug 04 '18