Skip to content

Commit

Permalink
mavflightview.py: correct plotting of GPS data
Browse files Browse the repository at this point in the history
the "type" variable was being over-written to include the instance number before we dropped down through the code which specially-treats messages based on the type variable.

So stop overwriting the variable before that switch statement, create a special string for when we need it.

Visible difference with this PR is that the GPS plots on the map no longer have lines starting from 0,0 if the GPS starts with no fix.
  • Loading branch information
peterbarker committed Apr 3, 2024
1 parent c3c97f4 commit ceafe35
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions MAVProxy/tools/mavflightview.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def mavflightview_mav(mlog, options=None, flightmode_selections=[]):
# may only be present for colour-source expressions to work
continue

type_with_instance = type
try:
# remember that "m" here might be a mavlink message.
instance_field = m.fmt.instance_field
Expand All @@ -393,7 +394,7 @@ def mavflightview_mav(mlog, options=None, flightmode_selections=[]):
):
continue

type = '%s[%u]' % (type, m_instance_field_value)
type_with_instance = '%s[%u]' % (type, m_instance_field_value)
except Exception:
pass

Expand Down Expand Up @@ -473,11 +474,11 @@ def mavflightview_mav(mlog, options=None, flightmode_selections=[]):
continue

# automatically add new types to instances
if type not in instances:
instances[type] = len(instances)
if type_with_instance not in instances:
instances[type_with_instance] = len(instances)
while len(instances) >= len(path):
path.append([])
instance = instances[type]
instance = instances[type_with_instance]

# only plot thing we have a valid-looking location for:
if abs(lat)<=0.01 and abs(lng)<=0.01:
Expand All @@ -490,8 +491,8 @@ def mavflightview_mav(mlog, options=None, flightmode_selections=[]):
tdays = grapher.timestamp_to_days(m._timestamp)
point = (lat, lng, colour, tdays)

if options.rate == 0 or not type in last_timestamps or m._timestamp - last_timestamps[type] > 1.0/options.rate:
last_timestamps[type] = m._timestamp
if options.rate == 0 or not type_with_instance in last_timestamps or m._timestamp - last_timestamps[type_with_instance] > 1.0/options.rate:
last_timestamps[type_with_instance] = m._timestamp
path[instance].append(point)
if len(path[0]) == 0:
print("No points to plot")
Expand Down

0 comments on commit ceafe35

Please # to comment.