Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/mavproxy_modules/magcal_graph.py
Views: 1798
# Copyright (C) 2016 Intel Corporation. All rights reserved.1#2# This file is free software: you can redistribute it and/or modify it3# under the terms of the GNU General Public License as published by the4# Free Software Foundation, either version 3 of the License, or5# (at your option) any later version.6#7# This file is distributed in the hope that it will be useful, but8# WITHOUT ANY WARRANTY; without even the implied warranty of9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.10# See the GNU General Public License for more details.11#12# You should have received a copy of the GNU General Public License along13# with this program. If not, see <http://www.gnu.org/licenses/>.14'''15This module shows the geodesic sections hit by the samples collected during16compass calibration, and also some status data. The objective of this module is17to provide a reference on how to interpret the field `completion_mask` from the18MAG_CAL_PROGRESS mavlink message. That information can be used in order to19guide the vehicle user during calibration.2021The plot shown by this module isn't very helpful to the end user, but it might22help developers during development of internal calibration support in ground23control stations.24'''25from MAVProxy.modules.lib import mp_module, mp_util26import multiprocessing2728class MagcalGraph():29def __init__(self):30self.parent_pipe, self.child_pipe = multiprocessing.Pipe()31self.ui_process = None32self._last_mavlink_msgs = {}3334def start(self):35if self.is_active():36return37if self.ui_process:38self.ui_process.join()3940for l in self._last_mavlink_msgs.values():41for m in l:42if not m:43continue44self.parent_pipe.send(m)4546self.ui_process = multiprocessing.Process(target=self.ui_task)47self.ui_process.start()4849def stop(self):50if not self.is_active():51return5253self.parent_pipe.send('close')54self.ui_process.join()5556def ui_task(self):57mp_util.child_close_fds()5859from MAVProxy.modules.lib import wx_processguard60from MAVProxy.modules.lib.wx_loader import wx61from lib.magcal_graph_ui import MagcalFrame6263app = wx.App(False)64app.frame = MagcalFrame(self.child_pipe)65app.frame.Show()66app.MainLoop()6768def is_active(self):69return self.ui_process is not None and self.ui_process.is_alive()7071def mavlink_packet(self, m):72if m.compass_id not in self._last_mavlink_msgs:73# Keep the two last messages so that, if one is the calibration74# report message, the previous one is the last progress message.75self._last_mavlink_msgs[m.compass_id] = [None, m]76else:77l = self._last_mavlink_msgs[m.compass_id]78l[0] = l[1]79l[1] = m8081if not self.is_active():82return83self.parent_pipe.send(m)8485class MagcalGraphModule(mp_module.MPModule):86def __init__(self, mpstate):87super(MagcalGraphModule, self).__init__(mpstate, 'magcal_graph')88self.add_command(89'magcal_graph',90self.cmd_magcal_graph,91'open a window to report magcal progress and plot geodesic ' +92'sections hit by the collected data in real time',93)9495self.graph = MagcalGraph()9697def cmd_magcal_graph(self, args):98self.graph.start()99100def mavlink_packet(self, m):101if m.get_type() not in ('MAG_CAL_PROGRESS', 'MAG_CAL_REPORT'):102return103self.graph.mavlink_packet(m)104105def unload(self):106self.graph.stop()107108def init(mpstate):109return MagcalGraphModule(mpstate)110111112