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/mavproxy_modules/magcal_graph.py
Views: 1798
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
This module shows the geodesic sections hit by the samples collected during
17
compass calibration, and also some status data. The objective of this module is
18
to provide a reference on how to interpret the field `completion_mask` from the
19
MAG_CAL_PROGRESS mavlink message. That information can be used in order to
20
guide the vehicle user during calibration.
21
22
The plot shown by this module isn't very helpful to the end user, but it might
23
help developers during development of internal calibration support in ground
24
control stations.
25
'''
26
from MAVProxy.modules.lib import mp_module, mp_util
27
import multiprocessing
28
29
class MagcalGraph():
30
def __init__(self):
31
self.parent_pipe, self.child_pipe = multiprocessing.Pipe()
32
self.ui_process = None
33
self._last_mavlink_msgs = {}
34
35
def start(self):
36
if self.is_active():
37
return
38
if self.ui_process:
39
self.ui_process.join()
40
41
for l in self._last_mavlink_msgs.values():
42
for m in l:
43
if not m:
44
continue
45
self.parent_pipe.send(m)
46
47
self.ui_process = multiprocessing.Process(target=self.ui_task)
48
self.ui_process.start()
49
50
def stop(self):
51
if not self.is_active():
52
return
53
54
self.parent_pipe.send('close')
55
self.ui_process.join()
56
57
def ui_task(self):
58
mp_util.child_close_fds()
59
60
from MAVProxy.modules.lib import wx_processguard
61
from MAVProxy.modules.lib.wx_loader import wx
62
from lib.magcal_graph_ui import MagcalFrame
63
64
app = wx.App(False)
65
app.frame = MagcalFrame(self.child_pipe)
66
app.frame.Show()
67
app.MainLoop()
68
69
def is_active(self):
70
return self.ui_process is not None and self.ui_process.is_alive()
71
72
def mavlink_packet(self, m):
73
if m.compass_id not in self._last_mavlink_msgs:
74
# Keep the two last messages so that, if one is the calibration
75
# report message, the previous one is the last progress message.
76
self._last_mavlink_msgs[m.compass_id] = [None, m]
77
else:
78
l = self._last_mavlink_msgs[m.compass_id]
79
l[0] = l[1]
80
l[1] = m
81
82
if not self.is_active():
83
return
84
self.parent_pipe.send(m)
85
86
class MagcalGraphModule(mp_module.MPModule):
87
def __init__(self, mpstate):
88
super(MagcalGraphModule, self).__init__(mpstate, 'magcal_graph')
89
self.add_command(
90
'magcal_graph',
91
self.cmd_magcal_graph,
92
'open a window to report magcal progress and plot geodesic ' +
93
'sections hit by the collected data in real time',
94
)
95
96
self.graph = MagcalGraph()
97
98
def cmd_magcal_graph(self, args):
99
self.graph.start()
100
101
def mavlink_packet(self, m):
102
if m.get_type() not in ('MAG_CAL_PROGRESS', 'MAG_CAL_REPORT'):
103
return
104
self.graph.mavlink_packet(m)
105
106
def unload(self):
107
self.graph.stop()
108
109
def init(mpstate):
110
return MagcalGraphModule(mpstate)
111
112