38 from sensor_msgs.msg
import Imu
39 from tf.transformations
import euler_from_quaternion
41 rad2degrees = 180.0/math.pi
52 rospy.on_shutdown(shutdown_hook)
56 scene=display(title=
"9DOF Razor IMU Main Screen")
59 scene.forward = (1,0,-0.25)
66 scene2 = display(title=
'9DOF Razor IMU Roll, Pitch, Yaw',x=550, y=0, width=500, height=500,center=(0,0,0), background=(0,0,0))
72 cil_roll = cylinder(pos=(-0.5,0.3,0),axis=(0.2,0,0),radius=0.01,color=color.red)
73 cil_roll2 = cylinder(pos=(-0.5,0.3,0),axis=(-0.2,0,0),radius=0.01,color=color.red)
74 cil_pitch = arrow(pos=(0.5,0.3,0),axis=(0,0,-0.4),shaftwidth=0.02,color=color.green)
75 arrow_course = arrow(pos=(0.0,-0.4,0),color=color.cyan,axis=(0,0.2,0), shaftwidth=0.02, fixedwidth=1)
78 label(pos=(-0.5,0.6,0),text=
"Roll (degrees / radians)",box=0,opacity=0)
79 label(pos=(0.5,0.6,0),text=
"Pitch (degrees / radians)",box=0,opacity=0)
80 label(pos=(0.0,0.02,0),text=
"Yaw (degrees / radians)",box=0,opacity=0)
81 label(pos=(0.0,-0.16,0),text=
"N",box=0,opacity=0,color=color.yellow)
82 label(pos=(0.0,-0.64,0),text=
"S",box=0,opacity=0,color=color.yellow)
83 label(pos=(-0.24,-0.4,0),text=
"W",box=0,opacity=0,color=color.yellow)
84 label(pos=(0.24,-0.4,0),text=
"E",box=0,opacity=0,color=color.yellow)
85 label(pos=(0.18,-0.22,0),height=7,text=
"NE",box=0,color=color.yellow)
86 label(pos=(-0.18,-0.22,0),height=7,text=
"NW",box=0,color=color.yellow)
87 label(pos=(0.18,-0.58,0),height=7,text=
"SE",box=0,color=color.yellow)
88 label(pos=(-0.18,-0.58,0),height=7,text=
"SW",box=0,color=color.yellow)
90 rollLabel = label(pos=(-0.5,0.52,0),text=
"-",box=0,opacity=0,height=12)
91 pitchLabel = label(pos=(0.5,0.52,0),text=
"-",box=0,opacity=0,height=12)
92 yawLabel = label(pos=(0,-0.06,0),text=
"-",box=0,opacity=0,height=12)
95 label(pos=(0,0.9,0),text=
"Linear Acceleration x / y / z (m/s^2)",box=0,opacity=0)
96 label(pos=(0,-0.8,0),text=
"Angular Velocity x / y / z (rad/s)",box=0,opacity=0)
97 linAccLabel = label(pos=(0,0.82,0),text=
"-",box=0,opacity=0,height=12)
98 angVelLabel = label(pos=(0,-0.88,0),text=
"-",box=0,opacity=0,height=12)
105 arrow(color=color.green,axis=(1,0,0), shaftwidth=0.04, fixedwidth=1)
106 arrow(color=color.green,axis=(0,1,0), shaftwidth=0.04 , fixedwidth=1)
107 arrow(color=color.green,axis=(0,0,1), shaftwidth=0.04, fixedwidth=1)
110 label(pos=(0,0,-1.2),text=
"Press 'a' to align",box=0,opacity=0)
111 label(pos=(1,0.1,0),text=
"X",box=0,opacity=0)
112 label(pos=(0,1,-0.1),text=
"Y",box=0,opacity=0)
113 label(pos=(0,-0.1,1),text=
"Z",box=0,opacity=0)
115 platform =
box(length=1.0, height=0.05, width=0.65, color=color.red,up=(0,0,1),axis=(-1,0,0))
116 p_line =
box(length=1.1,height=0.08,width=0.1,color=color.yellow,up=(0,0,1),axis=(-1,0,0))
117 plat_arrow = arrow(length=-0.8,color=color.cyan,up=(0,0,1),axis=(-1,0,0), shaftwidth=0.06, fixedwidth=1)
118 plat_arrow_up = arrow(length=0.4,color=color.cyan,up=(-1,0,0),axis=(0,0,1), shaftwidth=0.06, fixedwidth=1)
119 rospy.init_node(
"display_3D_visualization_node")
129 imuMsg.orientation.x,
130 imuMsg.orientation.y,
131 imuMsg.orientation.z,
132 imuMsg.orientation.w)
133 (roll,pitch,yaw) = euler_from_quaternion(quaternion)
138 axis=(-cos(pitch)*cos(yaw),-cos(pitch)*sin(yaw),sin(pitch))
139 up=(sin(roll)*sin(yaw)+cos(roll)*sin(pitch)*cos(yaw),-sin(roll)*cos(yaw)+cos(roll)*sin(pitch)*sin(yaw),cos(roll)*cos(pitch))
143 plat_arrow_up.axis=up
144 plat_arrow_up.up=axis
145 plat_arrow_up.length=0.4
148 plat_arrow.length=-0.8
152 cil_roll.axis=(-0.2*cos(roll),0.2*sin(roll),0)
153 cil_roll2.axis=(0.2*cos(roll),-0.2*sin(roll),0)
154 cil_pitch.axis=(0,-0.4*sin(pitch),-0.4*cos(pitch))
156 arrow_course.axis=(-0.2*sin(yaw-yaw_offset),0.2*cos(yaw-yaw_offset),0)
159 rollLabel.text = str(round(roll*rad2degrees, precision)) +
" / " + str(round(roll,precision))
160 pitchLabel.text = str(round(pitch*rad2degrees, precision)) +
" / " + str(round(pitch, precision))
162 yawLabel.text = str(round((yaw-yaw_offset)*rad2degrees, precision)) +
" / " + str(round((yaw-yaw_offset), precision))
164 linAccLabel.text = str(round(imuMsg.linear_acceleration.x, precision)) +
" / " + str(round(imuMsg.linear_acceleration.y, precision)) +
" / " + str(round(imuMsg.linear_acceleration.z, precision))
165 angVelLabel.text = str(round(imuMsg.angular_velocity.x, precision)) +
" / " + str(round(imuMsg.angular_velocity.y, precision)) +
" / " + str(round(imuMsg.angular_velocity.z, precision))
170 s = scene.kb.getkey()
181 sub = rospy.Subscriber(
'imu', Imu, processIMU_message)
def processIMU_message(imuMsg)