|
@@ -8,6 +8,7 @@
|
|
|
# Author: corvin
|
|
|
# History:
|
|
|
# 20211122:Initial this file.
|
|
|
+# 20211203:增加imu_iic_bus,imu_iic_addr配置参数.
|
|
|
import rospy
|
|
|
import math
|
|
|
|
|
@@ -26,6 +27,8 @@ def return_yaw_data(req):
|
|
|
rospy.init_node("iic_6dof_imu_node")
|
|
|
|
|
|
# Get DIY config param
|
|
|
+imu_iic_bus = rospy.get_param('~iic_bus', 1)
|
|
|
+imu_iic_addr = rospy.get_param('~iic_addr', '0x50')
|
|
|
topic_pub_hz = rospy.get_param('~topic_pub_hz', '100')
|
|
|
data_topic_name = rospy.get_param('~pub_data_topic', 'imu_data')
|
|
|
link_name = rospy.get_param('~link_name', 'base_imu_link')
|
|
@@ -34,6 +37,7 @@ pitch_topic_name= rospy.get_param('~pitch_topic', 'pitch_topic')
|
|
|
roll_topic_name = rospy.get_param('~roll_topic', 'roll_topic')
|
|
|
get_yaw_srv = rospy.get_param('~get_yaw_service', '/iic_imu_service/getYawData_service')
|
|
|
|
|
|
+
|
|
|
#创建各话题发布者和自定义服务
|
|
|
data_pub = rospy.Publisher(data_topic_name, Imu, queue_size=1)
|
|
|
yaw_pub = rospy.Publisher(yaw_topic_name, Float32, queue_size=1)
|
|
@@ -47,31 +51,31 @@ yawMsg = Float32()
|
|
|
pitchMsg = Float32()
|
|
|
rollMsg = Float32()
|
|
|
|
|
|
-# Orientation covariance estimation
|
|
|
+#Orientation covariance estimation
|
|
|
imuMsg.orientation_covariance = [
|
|
|
-0.0025 , 0 , 0,
|
|
|
-0, 0.0025, 0,
|
|
|
-0, 0, 0.0025
|
|
|
+0, 0, 0,
|
|
|
+0, 0, 0,
|
|
|
+0, 0, 0
|
|
|
]
|
|
|
|
|
|
-# Angular velocity covariance estimation
|
|
|
+#Angular velocity covariance estimation
|
|
|
imuMsg.angular_velocity_covariance = [
|
|
|
-0.02, 0 , 0,
|
|
|
-0 , 0.02, 0,
|
|
|
-0 , 0 , 0.02
|
|
|
+0, 0, 0,
|
|
|
+0, 0, 0,
|
|
|
+0, 0, 0
|
|
|
]
|
|
|
|
|
|
-# linear acceleration covariance estimation
|
|
|
+#linear acceleration covariance estimation
|
|
|
imuMsg.linear_acceleration_covariance = [
|
|
|
-0.04 , 0 , 0,
|
|
|
-0 , 0.04, 0,
|
|
|
-0 , 0 , 0.04
|
|
|
+0, 0, 0,
|
|
|
+0, 0, 0,
|
|
|
+0, 0, 0
|
|
|
]
|
|
|
|
|
|
seq = 0
|
|
|
accel_factor = 9.806 #sensor accel g convert to m/s^2.
|
|
|
|
|
|
-myIMU = MyIMU(0x50)
|
|
|
+myIMU = MyIMU(imu_iic_bus, int(imu_iic_addr))
|
|
|
rate = rospy.Rate(topic_pub_hz)
|
|
|
|
|
|
rospy.loginfo("Now 6DOF IMU Module is working ...")
|
|
@@ -89,7 +93,7 @@ while not rospy.is_shutdown():
|
|
|
pitch = float(myIMU.raw_pitch)*degrees2rad
|
|
|
roll = float(myIMU.raw_roll)*degrees2rad
|
|
|
|
|
|
- #填充话题消息,然后通过话题发布
|
|
|
+ #填充话题消息内容,然后通过话题发布
|
|
|
yawMsg.data = yaw
|
|
|
pitchMsg.data = pitch
|
|
|
rollMsg.data = roll
|
|
@@ -97,7 +101,6 @@ while not rospy.is_shutdown():
|
|
|
pitch_pub.publish(pitchMsg)
|
|
|
roll_pub.publish(rollMsg)
|
|
|
|
|
|
- # Publish imu message
|
|
|
#rospy.loginfo("acc_x:%f acc_y:%f acc_z:%f", myIMU.raw_ax,
|
|
|
# myIMU.raw_ay, myIMU.raw_az)
|
|
|
imuMsg.linear_acceleration.x = -float(myIMU.raw_ax)*accel_factor
|