ros之odom的发布
odom就是所谓的里程计,是根据你所获得的线速度,角速度,积分获得机器人实际走的距离,里程计存在累计误差,用于后面多传感器输入,为建图,导航提供参数。
odom最重要的是积分和发布,下面是部分代码
while(1)
{
current_time=ros::Time::now().toSec();
current_time1=ros::Time::now();
dt=(current_time-last_time);
de_th=vth*dt;//积分
de_x=(vx*cos(th)-vy*sin(th))*dt;
de_y=(vx*sin(th)-vy*cos(th))*dt;
x+=de_x;
y+=de_y;
th+=de_th;
last_time=current_time;
usleep(1000);
geometry_msgs::Quaternion odom_quat =tf::createQuaternionMsgFromYaw(th);
geometry_msgs::TransformStamped transform;
transform.transform.rotation=odom_quat;
transform.header.stamp=current_time1;
transform.header.frame_id="odom";
transform.child_frame_id="base_footprint";
transform.transform.translation.x=x;