Path: blob/master/Tools/mavproxy_modules/magcal_graph.py
9560 views
# 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/>.1415# flake8: noqa1617'''18This module shows the geodesic sections hit by the samples collected during19compass calibration, and also some status data. The objective of this module is20to provide a reference on how to interpret the field `completion_mask` from the21MAG_CAL_PROGRESS mavlink message. That information can be used in order to22guide the vehicle user during calibration.2324The plot shown by this module isn't very helpful to the end user, but it might25help developers during development of internal calibration support in ground26control stations.27'''28from MAVProxy.modules.lib import mp_module, mp_util29import multiprocessing3031class MagcalGraph():32def __init__(self):33self.parent_pipe, self.child_pipe = multiprocessing.Pipe()34self.ui_process = None35self._last_mavlink_msgs = {}3637def start(self):38if self.is_active():39return40if self.ui_process:41self.ui_process.join()4243for l in self._last_mavlink_msgs.values():44for m in l:45if not m:46continue47self.parent_pipe.send(m)4849self.ui_process = multiprocessing.Process(target=self.ui_task)50self.ui_process.start()5152def stop(self):53if not self.is_active():54return5556self.parent_pipe.send('close')57self.ui_process.join()5859def ui_task(self):60mp_util.child_close_fds()6162from MAVProxy.modules.lib import wx_processguard63from MAVProxy.modules.lib.wx_loader import wx64from lib.magcal_graph_ui import MagcalFrame6566app = wx.App(False)67app.frame = MagcalFrame(self.child_pipe)68app.frame.Show()69app.MainLoop()7071def is_active(self):72return self.ui_process is not None and self.ui_process.is_alive()7374def mavlink_packet(self, m):75if m.compass_id not in self._last_mavlink_msgs:76# Keep the two last messages so that, if one is the calibration77# report message, the previous one is the last progress message.78self._last_mavlink_msgs[m.compass_id] = [None, m]79else:80l = self._last_mavlink_msgs[m.compass_id]81l[0] = l[1]82l[1] = m8384if not self.is_active():85return86self.parent_pipe.send(m)8788class MagcalGraphModule(mp_module.MPModule):89def __init__(self, mpstate):90super(MagcalGraphModule, self).__init__(mpstate, 'magcal_graph')91self.add_command(92'magcal_graph',93self.cmd_magcal_graph,94'open a window to report magcal progress and plot geodesic ' +95'sections hit by the collected data in real time',96)9798self.graph = MagcalGraph()99100def cmd_magcal_graph(self, args):101self.graph.start()102103def mavlink_packet(self, m):104if m.get_type() not in ('MAG_CAL_PROGRESS', 'MAG_CAL_REPORT'):105return106self.graph.mavlink_packet(m)107108def unload(self):109self.graph.stop()110111def init(mpstate):112return MagcalGraphModule(mpstate)113114115