Best way to define the odometry of the robot without sensors
Recently I put another question about odometry (you see it here).
Even if the question was answered with courtesy by aHendrix I ve geting more confused about the odometry of a robot. Let's start with an easy robot created just for fun and for simulation porpouses.
No data are collected by scanner, laser, GPS or whatever...
So: in absence of odometry data I must change the variable (line 12-18 of the tutorial) with other changing variables to "simulate" the encoder/decoder of my imaginary robot.
In my code I used to integrate the geometry_msgs/Twist
information of the /cmd_vel
(generated automatically by move_base)topic over time to see the robot moving in Rviz.
Here my code:
void updateVel( const geometry_msgs::TwistPtr& msg ) {
vel_x = msg->linear.x;
vel_y = msg->linear.y;
vel_z = msg->linear.z;
rot_x = msg->angular.x;
rot_y = msg->angular.y;
rot_z = msg->angular.z;
}
and here the broadcast of the odometry informations and transformations (running in a loop)
....
double position_x = vel_x;
double position_y = vel_y;
double position_z = vel_z;
while( ros::ok() ) {
position_x = vel_x;
position_y = vel_y;
position_z = vel_z;
geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw( rot_z );
odom_trans.header.stamp = current_time;
odom_trans.transform.translation.x = position_x;
odom_trans.transform.translation.y = position_y;
odom_trans.transform.translation.z = position_z;
odom_trans.transform.rotation = odom_quat;
/* broadcast the transform */
broadcaster.sendTransform( odom_trans );
/* broadcast the odom over ROS */
odom.header.stamp = current_time;
odom.header.frame_id = "odom";
odom.pose.pose.position.x = position_x;
odom.pose.pose.position.y = position_y;
odom.pose.pose.position.z = position_z;
odom.pose.pose.orientation = odom_quat;
odom.child_frame_id = "base_link";
odom.twist.twist.linear.x = vel_x;
odom.twist.twist.linear.y = vel_y;
odom.twist.twist.linear.z = vel_z;
odom.twist.twist.angular.x = rot_x;
odom.twist.twist.angular.y = rot_y;
odom.twist.twist.angular.z = rot_z;
odom_pub.publish( odom );
.............
please note the
+=
in the following code :
/* update position */
position_x += vel_x;
position_y += vel_y;
position_z += vel_z;
for a rude integration over time.
Is this the right way to get odometry information when no sensor or other instruments are available to read the position position of the robot? If not, how to extrapolate and convert the /cmd_vel information to geenrate the right movement of the robot? Many thanks in advance
You've got the right idea. Integrating the velocity command is the correct way to simulate motion over time and produce odometry messages. The math for the integration neglects the orientation of the robot.