3 from std_msgs.msg
import String
4 from sensor_msgs.msg
import MagneticField
5 from math
import atan2, sin, cos, sqrt
9 xmag = data.magnetic_field.x
10 ymag = data.magnetic_field.y
11 zmag = data.magnetic_field.z
12 mag_norm=sqrt((xmag*xmag)+(ymag*ymag)+(zmag*zmag))
23 cos_pitch = cos(Pitch)
24 sin_pitch = sin(Pitch)
27 t_mag_x = magx * cos_pitch + magz * sin_pitch
28 t_mag_y = magx * sin_roll * sin_pitch + magy * cos_roll - magz * sin_roll * cos_pitch
31 yaw = atan2(head_x, head_y)
34 rospy.loginfo(rospy.get_caller_id() +
"yaw: %s", yaw)
38 rospy.init_node(
'test', anonymous=
True)
40 rospy.Subscriber(
"/mavros/imu/mag", MagneticField, callback)
45 if __name__ ==
'__main__':