Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added confirm command and allow for labels in live graphs #1200

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions MAVProxy/mavproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

#The MAVLink version being used (None, "1.0", "2.0")
mavversion = None
mpstate = None

class MPStatus(object):
'''hold status information about the mavproxy'''
Expand Down Expand Up @@ -1326,8 +1327,8 @@ def set_mav_version(mav10, mav20, autoProtocol, mavversionArg):
mpstate.command_map = command_map
mpstate.continue_mode = opts.continue_mode
# queues for logging
mpstate.logqueue = Queue.Queue()
mpstate.logqueue_raw = Queue.Queue()
mpstate.logqueue = multiproc.Queue()
mpstate.logqueue_raw = multiproc.Queue()


if opts.speech:
Expand Down Expand Up @@ -1425,7 +1426,7 @@ def quit_handler(signum = None, frame = None):
heartbeat_period = mavutil.periodic_event(1)
heartbeat_check_period = mavutil.periodic_event(0.33)

mpstate.input_queue = Queue.Queue()
mpstate.input_queue = multiproc.Queue()
mpstate.input_count = 0
mpstate.empty_input_count = 0
if opts.setup:
Expand Down
13 changes: 8 additions & 5 deletions MAVProxy/modules/lib/live_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def __init__(self,
timespan=20.0,
tickresolution=0.2,
colors=[ 'red', 'green', 'blue', 'orange', 'olive', 'cyan', 'magenta', 'brown',
'violet', 'purple', 'grey', 'black']):
'violet', 'purple', 'grey', 'black'],
labels=None):
self.fields = fields
self.labels = labels
self.colors = colors
self.title = title
self.timespan = timespan
Expand Down Expand Up @@ -79,10 +81,11 @@ def is_alive(self):
import time, math
import live_graph
livegraph = live_graph.LiveGraph(['sin(t)', 'cos(t)', 'sin(t+1)',
'cos(t+1)', 'sin(t+2)', 'cos(t+2)',
'cos(t+1)', 'sin(t+2)', 'cos(t+2)', 'x'],
timespan=30,
title='Graph Test')
'cos(t+1)', 'sin(t+2)', 'cos(t+2)',
'cos(t+1)', 'sin(t+2)', 'cos(t+2)', 'x'],
timespan=30,
title='Graph Test',
labels=['a','b','c','d'])
while livegraph.is_alive():
t = time.time()
livegraph.add_values([math.sin(t), math.cos(t),
Expand Down
11 changes: 9 additions & 2 deletions MAVProxy/modules/lib/live_graph_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@ def init_plot(self):
max_y = min_y = 0
else:
max_y = min_y = self.data[0][0]
num_labels = 0 if not self.state.labels else len(self.state.labels)
labels = []
for i in range(len(self.data)):
if i < num_labels and self.state.labels[i] is not None:
label = self.state.labels[i]
else:
label = self.state.fields[i]
labels.append(label)
p = self.axes.plot(
self.data[i],
linewidth=1,
color=self.state.colors[i],
label=self.state.fields[i],
label=label
)[0]
self.plot_data.append(p)
if len(self.data[i]) != 0:
Expand All @@ -101,7 +108,7 @@ def init_plot(self):
self.axes.set_xbound(lower=self.xdata[0], upper=0)
if min_y == max_y:
self.axes.set_ybound(min_y, max_y+0.1)
self.axes.legend(self.state.fields, loc='upper left', bbox_to_anchor=(0, 1.1))
self.axes.legend(labels, loc='upper left', bbox_to_anchor=(0, 1.1))

def draw_plot(self):
""" Redraws the plot
Expand Down
20 changes: 20 additions & 0 deletions MAVProxy/modules/lib/mp_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,26 @@ def call(self):
return None
return dlg.GetValue()

class MPMenuConfirmDialog(object):
'''used to create a confirmation dialog'''
def __init__(self, title='Confirmation', message='', callback=None, args=None):
self.title = title
self.message = message
self.callback = callback
self.args = args
t = multiproc.Process(target=self.thread)
t.start()

def thread(self):
mp_util.child_close_fds()
from MAVProxy.modules.lib import wx_processguard
from MAVProxy.modules.lib.wx_loader import wx
app = wx.App(False)
dlg = wx.MessageDialog(None, self.title, self.message, wx.YES|wx.NO)
ret = dlg.ShowModal()
if ret == wx.ID_YES and self.callback is not None:
self.callback(self.args)

class MPMenuChildMessageDialog(object):
'''used to create a message dialog in a child process'''
def __init__(self, title='Information', message='', font_size=18):
Expand Down
2 changes: 1 addition & 1 deletion MAVProxy/modules/mavproxy_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def cmd_menu_add(self, args):
if len(args) < 2:
print("Usage: console menu add MenuPath command")
return
menupath = args[0].split(':')
menupath = args[0].strip('"').split(':')
name = menupath[-1]
cmd = '# ' + ' '.join(args[1:])
self.menu.add_to_submenu(menupath[:-1], MPMenuItem(name, name, cmd))
Expand Down
14 changes: 13 additions & 1 deletion MAVProxy/modules/mavproxy_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,24 @@ def __init__(self, state, fields):
print("Adding graph: %s" % self.fields)

fields = [ self.pretty_print_fieldname(x) for x in fields ]
labels = []
for i in range(len(fields)):
f = fields[i]
f1 = f.find("<")
f2 = f.find(">")
if f1 > 0 and f2 > f1:
labels.append(f[f1+1:f2])
fields[i] = f[:f1]
else:
labels.append(None)

self.fields = fields[:]
self.values = [None] * len(self.fields)
self.livegraph = live_graph.LiveGraph(fields,
timespan=state.timespan,
tickresolution=state.tickresolution,
title=self.fields[0])
title=fields[0] if labels[0] is None else labels[0],
labels=labels)

def pretty_print_fieldname(self, fieldname):
if fieldname in self.state.legend:
Expand Down
15 changes: 15 additions & 0 deletions MAVProxy/modules/mavproxy_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from pymavlink import mavutil

from MAVProxy.modules.lib import mp_module
from MAVProxy.modules.lib import mp_util

class ModeModule(mp_module.MPModule):
def __init__(self, mpstate):
super(ModeModule, self).__init__(mpstate, "mode", public=True)
self.add_command('mode', self.cmd_mode, "mode change", self.available_modes())
self.add_command('guided', self.cmd_guided, "fly to a clicked location on map")
self.add_command('confirm', self.cmd_confirm, "confirm a command")

def cmd_mode(self, args):
'''set arbitrary mode'''
Expand All @@ -31,6 +33,19 @@ def cmd_mode(self, args):
modenum = mode_mapping[mode]
self.master.set_mode(modenum)

def cmd_confirm(self, args):
'''confirm a command'''
if len(args) < 2:
print('Usage: confirm "Question to display" command <arguments>')
return
question = args[0].strip('"')
command = ' '.join(args[1:])
if not mp_util.has_wxpython:
print("No UI available for confirm")
return
from MAVProxy.modules.lib import mp_menu
mp_menu.MPMenuConfirmDialog(question, callback=self.mpstate.functions.process_stdin, args=command)

def available_modes(self):
if self.master is None:
print('No mode mapping available')
Expand Down