Skip to content

Commit

Permalink
pymavlink: Allow headless operation in mavgraph by providing an outpu…
Browse files Browse the repository at this point in the history
…t file name.
  • Loading branch information
LorenzMeier authored and Andrew Tridgell committed May 30, 2014
1 parent 788c812 commit bd303e1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pymavlink/tools/mavgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import sys, struct, time, os, datetime
import math, re
import pylab, matplotlib
import matplotlib
from math import *

from pymavlink.mavextra import *
Expand Down Expand Up @@ -120,7 +120,6 @@ def plotit(x, y, fields, colors=[]):
linestyle = '-'
ax.plot_date(x[i], y[i], color=color, label=fields[i],
linestyle=linestyle, marker=marker, tz=None)
pylab.draw()
empty = False
if opts.flightmode is not None:
for i in range(len(modes)-1):
Expand Down Expand Up @@ -153,6 +152,7 @@ def plotit(x, y, fields, colors=[]):
parser.add_option("--zero-time-base", action='store_true', help="use Z time base for DF logs")
parser.add_option("--flightmode", default=None,
help="Choose the plot background according to the active flight mode of the specified type, e.g. --flightmode=apm for ArduPilot or --flightmode=px4 for PX4 stack logs. Cannot be specified with --xaxis.")
parser.add_option("--output",dest="output", default=None, help="provide an output format")
(opts, args) = parser.parse_args()

from pymavlink import mavutil
Expand All @@ -169,6 +169,12 @@ def plotit(x, y, fields, colors=[]):
print("Unknown flight controller '%s' in specification of --flightmode" % opts.flightmode)
sys.exit(1)


if opts.output is not None:
matplotlib.use('Agg')

import pylab

filenames = []
fields = []
for f in args:
Expand Down Expand Up @@ -271,6 +277,9 @@ def process_file(filename):
for i in range(0, len(x)):
x[i] = []
y[i] = []
pylab.show()
pylab.draw()
raw_input('press enter to exit....')
if opts.output is None:
pylab.show()
pylab.draw()
raw_input('press enter to exit....')
else:
pylab.savefig(opts.output, bbox_inches='tight')

0 comments on commit bd303e1

Please sign in to comment.