Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/du32_change.py
9532 views
1
#!/usr/bin/env python3
2
3
"""
4
Parses a log file and shows how Copter's du32 changes over time
5
6
AP_FLAKE8_CLEAN
7
8
"""
9
10
import optparse
11
import sys
12
import time
13
14
from pymavlink import mavutil
15
16
17
class DU32Change(object):
18
def __init__(self, master):
19
self.master = master
20
21
def progress(self, text):
22
'''emit text with possible timestamps etc'''
23
print("%u: %s" % (time.time(), text))
24
25
def run(self):
26
27
self.progress("Creating connection")
28
self.conn = mavutil.mavlink_connection(master)
29
30
# this eas was generated from Copter.h's structure for ap_t:
31
bit_descriptions_list = [
32
"unused1",
33
"unused_was_simple_mode bit1",
34
"unused_was_simple_mode bit2",
35
"pre_arm_rc_check",
36
"pre_arm_check",
37
"auto_armed",
38
"logging_started",
39
"land_complete",
40
"new_radio_frame",
41
"usb_connected_unused",
42
"rc_receiver_present_unused",
43
"compass_mot",
44
"motor_test",
45
"initialised",
46
"land_complete_maybe",
47
"throttle_zero",
48
"system_time_set_unused",
49
"gps_glitching",
50
"using_interlock",
51
"land_repo_active",
52
"motor_interlock_switch",
53
"in_arming_delay",
54
"initialised_params",
55
"unused3",
56
"unused2",
57
"armed_with_airmode_switch",
58
"prec_land_active",
59
]
60
bit_descriptions = {}
61
count = 0
62
for bit in bit_descriptions_list:
63
bit_descriptions[bit] = count
64
count += 1
65
66
old_m = None
67
68
desired_type = "DU32"
69
while True:
70
m = self.conn.recv_match(type=desired_type)
71
if m is None:
72
break
73
if m.Id != 7:
74
# 7 is LOG_DATA_ID from AP_Logger.h
75
continue
76
if old_m is not None and m.Value == old_m.Value:
77
continue
78
line = ""
79
if old_m is None:
80
for bit in sorted(bit_descriptions.keys()):
81
bit_set = m.Value & (1 << bit_descriptions[bit])
82
if bit_set:
83
print("Original %s: 1" % bit)
84
else:
85
print("Original %s: 0" % bit)
86
else:
87
for bit in bit_descriptions.keys():
88
old_bit_set = old_m.Value & (1 << bit_descriptions[bit])
89
new_bit_set = m.Value & (1 << bit_descriptions[bit])
90
if new_bit_set and not old_bit_set:
91
line += " +%s" % bit
92
elif not new_bit_set and old_bit_set:
93
line += " -%s" % bit
94
95
timestamp = getattr(m, '_timestamp', 0.0)
96
formatted_timestamp = "%s.%02u" % (
97
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)),
98
int(timestamp * 100.0) % 100)
99
100
print("%s: %s" % (formatted_timestamp, line))
101
old_m = m
102
103
104
if __name__ == '__main__':
105
parser = optparse.OptionParser("du32_change.py [options]")
106
107
(opts, args) = parser.parse_args()
108
109
if len(args) < 1:
110
parser.print_help()
111
sys.exit(1)
112
113
master = args[0]
114
115
tester = DU32Change(master)
116
tester.run()
117
118