CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

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