4 rotate APMs on bench to test magnetometers 7 from __future__
import print_function
10 from math
import radians
12 from pymavlink
import mavutil
14 from argparse
import ArgumentParser
15 parser = ArgumentParser(description=__doc__)
17 parser.add_argument(
"--device1", required=
True, help=
"mavlink device1")
18 parser.add_argument(
"--device2", required=
True, help=
"mavlink device2")
19 parser.add_argument(
"--baudrate", type=int,
20 help=
"master port baud rate", default=115200)
21 args = parser.parse_args()
25 values = [ 65535 ] * 8
28 mav1.mav.rc_channels_override_send(mav1.target_system, mav1.target_component, *values)
29 mav2.mav.rc_channels_override_send(mav2.target_system, mav2.target_component, *values)
33 mav1 = mavutil.mavlink_connection(args.device1, baud=args.baudrate)
36 mav2 = mavutil.mavlink_connection(args.device2, baud=args.baudrate)
38 print(
"Waiting for HEARTBEAT")
41 print(
"Heartbeat from APM (system %u component %u)" % (mav1.target_system, mav1.target_system))
42 print(
"Heartbeat from APM (system %u component %u)" % (mav2.target_system, mav2.target_system))
44 print(
"Waiting for MANUAL mode")
45 mav1.recv_match(type=
'SYS_STATUS', condition=
'SYS_STATUS.mode==2 and SYS_STATUS.nav_mode==4', blocking=
True)
46 mav2.recv_match(type=
'SYS_STATUS', condition=
'SYS_STATUS.mode==2 and SYS_STATUS.nav_mode==4', blocking=
True)
48 print(
"Setting declination")
49 mav1.mav.param_set_send(mav1.target_system, mav1.target_component,
50 'COMPASS_DEC', radians(12.33))
51 mav2.mav.param_set_send(mav2.target_system, mav2.target_component,
52 'COMPASS_DEC', radians(12.33))
69 MAV_ACTION_CALIBRATE_GYRO = 17
70 mav1.mav.action_send(mav1.target_system, mav1.target_component, MAV_ACTION_CALIBRATE_GYRO)
71 mav2.mav.action_send(mav2.target_system, mav2.target_component, MAV_ACTION_CALIBRATE_GYRO)
73 print(
"Waiting for gyro calibration")
74 mav1.recv_match(type=
'ACTION_ACK')
75 mav2.recv_match(type=
'ACTION_ACK')
77 print(
"Resetting mag offsets")
78 mav1.mav.set_mag_offsets_send(mav1.target_system, mav1.target_component, 0, 0, 0)
79 mav2.mav.set_mag_offsets_send(mav2.target_system, mav2.target_component, 0, 0, 0)
82 p =
float(SERVO_OUTPUT_RAW.servo3_raw - rc3_min) / (rc3_max - rc3_min)
83 return 172 + p*(326 - 172)
93 if rc3 > rc3_max
or rc3 < rc3_min:
97 if rc4 > rc4_max
or rc4 < rc4_min:
100 print(
"hdg1: %3u hdg2: %3u ofs1: %4u, %4u, %4u ofs2: %4u, %4u, %4u" % (
101 mav1.messages[
'VFR_HUD'].heading,
102 mav2.messages[
'VFR_HUD'].heading,
103 mav1.messages[
'SENSOR_OFFSETS'].mag_ofs_x,
104 mav1.messages[
'SENSOR_OFFSETS'].mag_ofs_y,
105 mav1.messages[
'SENSOR_OFFSETS'].mag_ofs_z,
106 mav2.messages[
'SENSOR_OFFSETS'].mag_ofs_x,
107 mav2.messages[
'SENSOR_OFFSETS'].mag_ofs_y,
108 mav2.messages[
'SENSOR_OFFSETS'].mag_ofs_z,
def TrueHeading(SERVO_OUTPUT_RAW)
def set_attitude(rc3, rc4)