Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/mavproxy_modules/magcal_graph.py
9560 views
1
# Copyright (C) 2016 Intel Corporation. All rights reserved.
2
#
3
# This file is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the
5
# Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This file is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
# See the GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
# flake8: noqa
17
18
'''
19
This module shows the geodesic sections hit by the samples collected during
20
compass calibration, and also some status data. The objective of this module is
21
to provide a reference on how to interpret the field `completion_mask` from the
22
MAG_CAL_PROGRESS mavlink message. That information can be used in order to
23
guide the vehicle user during calibration.
24
25
The plot shown by this module isn't very helpful to the end user, but it might
26
help developers during development of internal calibration support in ground
27
control stations.
28
'''
29
from MAVProxy.modules.lib import mp_module, mp_util
30
import multiprocessing
31
32
class MagcalGraph():
33
def __init__(self):
34
self.parent_pipe, self.child_pipe = multiprocessing.Pipe()
35
self.ui_process = None
36
self._last_mavlink_msgs = {}
37
38
def start(self):
39
if self.is_active():
40
return
41
if self.ui_process:
42
self.ui_process.join()
43
44
for l in self._last_mavlink_msgs.values():
45
for m in l:
46
if not m:
47
continue
48
self.parent_pipe.send(m)
49
50
self.ui_process = multiprocessing.Process(target=self.ui_task)
51
self.ui_process.start()
52
53
def stop(self):
54
if not self.is_active():
55
return
56
57
self.parent_pipe.send('close')
58
self.ui_process.join()
59
60
def ui_task(self):
61
mp_util.child_close_fds()
62
63
from MAVProxy.modules.lib import wx_processguard
64
from MAVProxy.modules.lib.wx_loader import wx
65
from lib.magcal_graph_ui import MagcalFrame
66
67
app = wx.App(False)
68
app.frame = MagcalFrame(self.child_pipe)
69
app.frame.Show()
70
app.MainLoop()
71
72
def is_active(self):
73
return self.ui_process is not None and self.ui_process.is_alive()
74
75
def mavlink_packet(self, m):
76
if m.compass_id not in self._last_mavlink_msgs:
77
# Keep the two last messages so that, if one is the calibration
78
# report message, the previous one is the last progress message.
79
self._last_mavlink_msgs[m.compass_id] = [None, m]
80
else:
81
l = self._last_mavlink_msgs[m.compass_id]
82
l[0] = l[1]
83
l[1] = m
84
85
if not self.is_active():
86
return
87
self.parent_pipe.send(m)
88
89
class MagcalGraphModule(mp_module.MPModule):
90
def __init__(self, mpstate):
91
super(MagcalGraphModule, self).__init__(mpstate, 'magcal_graph')
92
self.add_command(
93
'magcal_graph',
94
self.cmd_magcal_graph,
95
'open a window to report magcal progress and plot geodesic ' +
96
'sections hit by the collected data in real time',
97
)
98
99
self.graph = MagcalGraph()
100
101
def cmd_magcal_graph(self, args):
102
self.graph.start()
103
104
def mavlink_packet(self, m):
105
if m.get_type() not in ('MAG_CAL_PROGRESS', 'MAG_CAL_REPORT'):
106
return
107
self.graph.mavlink_packet(m)
108
109
def unload(self):
110
self.graph.stop()
111
112
def init(mpstate):
113
return MagcalGraphModule(mpstate)
114
115