ros2 机器人imu传感器 加速度计 陀螺仪精度和数据填充单位换算

起因,imu解算出了加速度 角速度,但原始数据是没有单位的,只是在一个精度范围的值,要使用这些数据,就需要把这些没有单位的数据换算成带单位的数据,下面解说一下换算原理。

imu读取数据代码参考上期的博客:

ros2 c++实现JY_95T IMU解算三轴 加速度 角速度 欧拉角 磁力计 四元数_JT_BOT的博客-CSDN博客

单位转换依据imu使用说明

277961342cda4b538417031d5b618828.png

b1e49db8ad414efb877bf5aa6ff96c71.png

ros2 ium数据填充要求:加速度单位:m/s^2  角速度: rad/sec  四元数没有单位

ros2 interface show sensor_msgs/msg/Imu

# This is a message to hold data from an IMU (Inertial Measurement Unit)
#
# Accelerations should be in m/s^2 (not in g's), and rotational velocity should be in rad/sec
#加速度应以m/s ^2为单位(而不是以g's为单位),旋转速度应以rad/sec为单位
#
# If the covariance of the measurement is known, it should be filled in (if all you know is the
# variance of each measurement, e.g. from the datasheet, just put those along the diagonal)
# A covariance matrix of all zeros will be interpreted as "covariance unknown", and to use the
# data a covariance will have to be assumed or gotten from some other source
#
# If you have no estimate for one of the data elements (e.g. your IMU doesn't produce an
# orientation estimate), please set element 0 of the associated covariance matrix to -1
# If you are interpreting this message, please check for a value of -1 in the first element of each
# covariance matrix, and disregard the associated estimate.

std_msgs/Header header

geometry_msgs/Quaternion orientation
float64[9] orientation_covariance # Row major about x, y, z axes

geometry_msgs/Vector3 angular_velocity
float64[9] angular_velocity_covariance # Row major about x, y, z axes

geometry_msgs/Vector3 linear_acceleration
float64[9] linear_acceleration_covariance # Row major x, y z

先拿加速度做示范,加速度的默认测量范围是-16G—+16G,G就是gravity,是重力加速度9.8m/s²,数据存储在2个字节一共16位2进制数据,扣除第一位符号位,2的15次方数据范围是-7FFF-7FFF (-32767~32767)

62876676685a4987823516e35d27217e.jpg

 所以在解算出加速度的原始数据要 acc/2048*9.8单位才是m/s^2,imu c++完整代码看上期博客。

 加速度解算代码:

// 加速度
acc_x = ((double)((short)(data[index + 5]<<8 | data[index + 4])))/2048 * 9.8;  //单位m/s^2
acc_y = ((double)((short)(data[index + 7]<<8 | data[index + 6])))/2048 * 9.8;
acc_z = ((double)((short)(data[index + 9]<<8 | data[index + 8])))/2048 * 9.8;

陀螺仪角速度和这个算法是一样的,正负2000对应正负32767,32767/2000 = 16.4

角速度解算代码:

// 陀螺仪角速度  
gyro_x = ((double)((short)(data[index + 11]<<8 | data[index + 10])))/16.4/57.3; //单位rad/sec 360/2.314=57.3
gyro_y = ((double)((short)(data[index + 13]<<8 | data[index + 12])))/16.4/57.3;  
gyro_z = ((double)((short)(data[index + 15]<<8 | data[index + 14])))/16.4/57.3;  

其他数据像磁力计解算原理是一样的,刻官可以自行推导。

这里要注意,因为每个数据都是2个字节拼出来的,拼出来的数据是short类型,需要整体加小括号变成double类型在进行乘除运算,否则会降低数据精度,表现在rviz2可视化数据的时候像动画一样卡顿。

猜你喜欢

转载自blog.csdn.net/m0_73694897/article/details/131589835