Created
June 9, 2015 21:24
-
-
Save tcr3dr/0197a0eeea602b2a8b41 to your computer and use it in GitHub Desktop.
Reads rangefinder distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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