Skip to content

Instantly share code, notes, and snippets.

@tcr3dr
Created June 9, 2015 21:24
Show Gist options
  • Save tcr3dr/0197a0eeea602b2a8b41 to your computer and use it in GitHub Desktop.
Save tcr3dr/0197a0eeea602b2a8b41 to your computer and use it in GitHub Desktop.
Reads rangefinder distance
#
# This example shows how to use DroneKit-Python to get and set vehicle state, parameter and channel-override information.
# It also demonstrates how to observe vehicle attribute (state) changes.
#
# Usage:
# * mavproxy.py
# * module load api
# * api start range.py
#
from droneapi.lib import VehicleMode
from pymavlink import mavutil
import time, json
# First get an instance of the API endpoint
api = local_connect()
# Get the connected vehicle (currently only one vehicle can be returned).
v = api.get_vehicles()[0]
# Demo callback handler for raw MAVLink messages
def mavrx_debug_handler(message):
if message.get_type() == 'RANGEFINDER':
print 'received packet...'
print 'distance:', message.distance
print 'voltage:', message.voltage
# Set MAVLink callback handler (after getting Vehicle instance)
v.set_mavlink_callback(mavrx_debug_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment