|
@@ -1,7 +1,7 @@
|
|
|
#!/usr/bin/env python
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
|
-# Copyright: 2016-2019 https://www.corvin.cn ROS小课堂
|
|
|
+# Copyright: 2016-2021 https://www.corvin.cn ROS小课堂
|
|
|
# Author: corvin
|
|
|
# Description: 为树莓派IMU扩展板所使用的配套代码,由于默认
|
|
|
# 扩展板与树莓派使用IIC连接。所以这里的代码是直接从IIC接口
|
|
@@ -21,9 +21,15 @@ class MyIMU(object):
|
|
|
|
|
|
def get_YPRAG(self):
|
|
|
try:
|
|
|
+ #roll_tmp = self.i2c.read_i2c_block_data(self.addr, 0x3d, 6)
|
|
|
+ #pitch_tmp = self.i2c.read_i2c_block_data(self.addr, 0x3e, 2)
|
|
|
+ #yaw_tmp = self.i2c.read_i2c_block_data(self.addr, 0x3f, 2)
|
|
|
roll_tmp = self.i2c.read_i2c_block_data(self.addr, 0x3d, 2)
|
|
|
pitch_tmp = self.i2c.read_i2c_block_data(self.addr, 0x3e, 2)
|
|
|
yaw_tmp = self.i2c.read_i2c_block_data(self.addr, 0x3f, 2)
|
|
|
+ #rospy.loginfo("Read roll_tmp:%#x %#x", roll_tmp[0], roll_tmp[1])
|
|
|
+ #rospy.loginfo("Read pitch_tmp:%#x %#x", roll_tmp[2], roll_tmp[3])
|
|
|
+ #rospy.loginfo("Read yaw_tmp:%#x %#x", roll_tmp[4], roll_tmp[5])
|
|
|
|
|
|
ax_tmp = self.i2c.read_i2c_block_data(self.addr, 0x34, 2)
|
|
|
ay_tmp = self.i2c.read_i2c_block_data(self.addr, 0x35, 2)
|
|
@@ -38,9 +44,12 @@ class MyIMU(object):
|
|
|
except IOError:
|
|
|
rospy.logerr("Read IMU YPRAG date error !")
|
|
|
else:
|
|
|
- self.raw_roll = float(((roll_tmp[1]<<8) |roll_tmp[0])/32768.0*180.0)
|
|
|
- self.raw_pitch = float(((pitch_tmp[1]<<8)|pitch_tmp[0])/32768.0*180.0)
|
|
|
- self.raw_yaw = (yaw_tmp[1] << 8 | yaw_tmp[0])/32768.0*180
|
|
|
+ self.raw_roll = float(np.short(np.short(roll_tmp[1]<<8)|roll_tmp[0])/32768.0*180.0)
|
|
|
+ self.raw_pitch = float(np.short(np.short(pitch_tmp[1]<<8)|pitch_tmp[0])/32768.0*180.0)
|
|
|
+ self.raw_yaw = float(np.short(np.short(yaw_tmp[1]<<8)|yaw_tmp[0])/32768.0*180.0)
|
|
|
+ #self.raw_roll = float(np.short(np.short(roll_tmp[1]<<8)|roll_tmp[0])/32768.0*180.0)
|
|
|
+ #self.raw_pitch = float(np.short(np.short(roll_tmp[3]<<8)|roll_tmp[2])/32768.0*180.0)
|
|
|
+ #self.raw_yaw = float(np.short(np.short(roll_tmp[5]<<8)|roll_tmp[4])/32768.0*180.0)
|
|
|
|
|
|
self.raw_ax = float(np.short(np.short(ax_tmp[1]<<8)|ax_tmp[0])/32768.0*16.0)
|
|
|
self.raw_ay = float(np.short(np.short(ay_tmp[1]<<8)|ay_tmp[0])/32768.0*16.0)
|