RobotSetup Odemetry tutorial tf confusion
After went through tf tutorial, I thought the transformation between two frames of a shall be fixed.
In the odometry tutorial in navigation/Tutorials/RobotSetup/Odom, the transformation is following the changes in odometry readings (x,y,th). I am lost here. I can't visualise "odometry frame". I was expecting that the odometry readings be used without any transform, i.e. if it says x=2m, y=1m, z=0m, th=1rad, then that indicates the position of the base_link, provided the odometry was initialised at the beginning. I am surely terribly wrong in this. I hope some one can help point me to the right direction.
Thanks.
EDIT 1:
@DimitriProsser Many thanks for the explanation.
If the odom transform was published once at startup, then I might understand it fixes the relationship between the odom measurements and world. However, in the navigation/Tutorials/RobotSetup/Odom, the odom transform is between odom and base_link, and it is in the while loop as below:
ros::Rate r(1.0);
while(n.ok()){
current_time = ros::Time::now();
//compute odometry in a typical way given the velocities of the robot
double dt = (current_time - last_time).toSec();
double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
double delta_th = vth * dt;
x += delta_x;
y += delta_y;
th += delta_th;
//since all odometry is 6DOF we'll need a quaternion created from yaw
geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(th);
//first, we'll publish the transform over tf
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
odom_broadcaster.sendTransform(odom_trans);
//next, we'll publish the odometry message over ROS
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
odom_pub.publish(odom);
last_time = current_time;
r.sleep();
}
May be I am unable to clearly explain my doubt (my wrong understanding). I am relating this to the explanation in navigation/Tutorials/RobotSetup/TF. I assume odometry is a sensor (encoder) like a laser range finder, hence a transform from odom frame to the base_link frame should be fixed just like the transform from base_laser to base_link. Where do I go wrong?
Thanks again.
EDIT 2:
@ahendrix Many thanks for the explanation. My understanding of "transform" has been wrong. I am thinking along this way now:
In the tf tutorial, the scan (laser) is a measure of distance (of points) from the robot (base_link). Since scan is with reference to lrf (base_laser), it has to be transformed to with reference to robot position (base_link). Since base_laser (lrf) is always fixed ...