DroneKit教程(二):控制Pixhawk示例
本篇提供了一个简单的示例,配以详细的注释说明不同语句的功能,希望能给各位一个总体的框架和印象。
- 该示例文件改写自DroneKit的官方示例。
- 在本示例中,我们使用SITL作为测试工具,MAVProxy进行数据转发
预先准备
根据“使用从源码编译的SITL测试DroneKit代码”中的要求,运行SITL和MAVProxy:
打开Cygwin Terminal,依次输入
.. -- -,,, --
新开一个cmd,运行
mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551
(可选)在MissionPlanner地面站中监控无人机的状态和轨迹。运行MissionPlanner地面站,右上角选择UDP,点击connect连接。端口填写14550
在测试过程中,请保持SITL和MAVProxy运行。
示例:simple_goto.py
本示例将展示如何连接到无人机,控制无人机解锁后升空到10m,依次朝两个方向飞行30s,最后返回出发点并降落。
"""
© Copyright 2015-2016, 3D Robotics.
simple_goto.py: GUIDED mode "simple goto" example (Copter Only)
Demonstrates how to arm and takeoff in Copter and how to navigate to points using Vehicle.simple_goto.
"""
from __future__ import print_function
import time
from dronekit import connect, VehicleMode, LocationGlobalRelative
connection_string = '127.0.0.1:14551'
print('Connecting to vehicle on: %s' % connection_string)
vehicle = connect(connection_string, wait_ready=True)
def arm_and_takeoff(aTargetAltitude):
print("Basic pre-arm checks")
while not vehicle.is_armable:
print(" Waiting for vehicle to initialise...")
time.sleep(1)
print("Arming motors")
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
while not vehicle.armed:
print(" Waiting for arming...")
time.sleep(1)
print("Taking off!")
vehicle.simple_takeoff(aTargetAltitude)
while True:
print(" Altitude: ", vehicle.location.global_relative_frame.alt)
if vehicle.location.global_relative_frame.alt >= aTargetAltitude * 0.95:
print("Reached target altitude")
break
time.sleep(1)
arm_and_takeoff(10)
print("Set default/target airspeed to 3")
vehicle.airspeed = 3
print("Going towards first point for 30 seconds ...")
point1 = LocationGlobalRelative(-35.361354, 149.165218, 20)
vehicle.simple_goto(point1)
time.sleep(30)
print("Going towards second point for 30 seconds (groundspeed set to 10 m/s) ...")
point2 = LocationGlobalRelative(-35.363244, 149.168801, 20)
vehicle.simple_goto(point2, groundspeed=10)
time.sleep(30)
print("Returning to Launch")
vehicle.mode = VehicleMode("RTL")
print("Close vehicle object")
vehicle.close()
测试示例
测试提示:
python simple_goto.py
你应该可以看到无人机升空到10m,依次朝两个方向飞行30s后,返回出发点并降落。
版本信息
1.0 20170914 initial commit
本作品采用知识共享署名-相同方式共享 3.0 未本地化版本许可协议进行许可。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)