ROS里程计的学习(odometry) (三)

机器人差分运动模型如上图:

假设我们知道左右轮的速度,则线速度为V=(Vl+Vr)/2     角速度为W=(Vr-Vl)/l     圆弧运动半径为r=V/W

公式①:机器人前进速度等于两轮速度之和的平均值

公式②:因为在采样周期非常短的时间内,两条虚线近似可以看成直线,角速度可以表示为(右轮速度-左轮速度)/轴长

公式③:根据以上2个公式整理得到的。

从公式③可以看出当左轮速度等于右轮时,半径无穷大,即机器人为直线运动。



言归正传,Vr与Vl怎么得到呢?采样时间内测得的编码值除以轮子一圈的总脉冲数就是速度,即将轮子分成无数份。

轴长怎么得到呢?测两电机直接摆放的距离。

就可以进行任意控制两轮机器人行走啦,还能通过计算获得里程计的信息。


里程计的计算:

已知以上的公式可以得到角速度和线速度,那么我们知道  采样时间内转过的角度=角速度*时间

那么对每一次采样得到的角度进行积分,就是转过的角度

得到角度值以后,

position_x= position_x +S*cos(θ)

position_y= position_y +S*sin(θ)


  • 4
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
好的,以下是一个简单的IMU里程计ROS程序的示例: ```python #!/usr/bin/env python import rospy from sensor_msgs.msg import Imu from nav_msgs.msg import Odometry from geometry_msgs.msg import Quaternion, Twist, Vector3 class ImuOdom: def __init__(self): rospy.init_node('imu_odom') self.imu_sub = rospy.Subscriber('/imu/data', Imu, self.imu_callback) self.odom_pub = rospy.Publisher('/odom', Odometry, queue_size=10) self.last_time = rospy.Time.now() self.x = 0 self.y = 0 self.th = 0 def imu_callback(self, msg): current_time = rospy.Time.now() dt = (current_time - self.last_time).to_sec() self.last_time = current_time # orientation quaternion to Euler angles q = msg.orientation roll, pitch, yaw = tf.transformations.euler_from_quaternion([q.x, q.y, q.z, q.w]) # angular velocity ang_vel = msg.angular_velocity.z # compute linear velocity linear_vel = Twist(Vector3(0, 0, 0), Vector3(0, 0, ang_vel)) # compute displacement self.x += linear_vel.linear.x * dt self.y += linear_vel.linear.y * dt self.th += ang_vel * dt # create odom message odom = Odometry() odom.header.stamp = current_time odom.header.frame_id = "odom" odom.child_frame_id = "base_link" # position odom.pose.pose.position.x = self.x odom.pose.pose.position.y = self.y odom.pose.pose.position.z = 0.0 # orientation odom.pose.pose.orientation = Quaternion(*tf.transformations.quaternion_from_euler(0, 0, self.th)) # velocity odom.twist.twist = linear_vel # publish odom message self.odom_pub.publish(odom) if __name__ == '__main__': try: imu_odom = ImuOdom() rospy.spin() except rospy.ROSInterruptException: pass ``` 这个程序订阅IMU数据,根据角速度计算线速度和位移,并发布里程计信息。你需要在程序中设置IMU话题的名称和发布里程计信息的话题名称以及坐标系的名称,以适应你的机器人系统。 注意,这只是一个示例程序,可能需要根据你的具体需求进行修改和优化。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值