- Debugging/Logging - 飞行日志分析
- Debugging/Logging - ULog文件格式
- 教程
- 教程 - 地面站
- 教程 - 编写应用程序
- 教程 - QGC的视频流
- 教程 - 远距离视频流
- 教程 - u-blox M8P RTK
- 新手上路
- 新手上路 - 初始设置
- 新手上路 - 安装工具链
- 安装工具链 - Mac OS
- 安装工具链 - Linux
- Linux - Advanced Linux
- 安装工具链 - Windows
- 新手上路 - Fast RTPS installation
- 新手上路 - 代码编译
- 新手上路 - 高级配置
- 新手上路 - 贡献& 开发者电话会议
- 贡献& 开发者电话会议 - GIT例程
- 贡献& 开发者电话会议 - Documentation
- 新手上路 - Licenses
- 概念解读
- 概念解读 - 飞行模式
- 概念解读 - 结构概述
- 概念解读 - 飞行控制栈
- 概念解读 - 中间件
- 概念解读 - 混控和执行器
- 概念解读 - PWM限制状态机
- Hardware
- Hardware - 自驾仪硬件
- 机型 - 统一的基础代码
- 机型 - 参考机型
- 机型 - 添加一个新的机型
- Data Links - SiK Radio
- Data Links - Wifi数传
- Data Links - 数传
- I2C总线 - SF1XX lidar
- 传感器和执行机构总线 - UAVCAN总线
- UAVCAN总线 - UAVCAN Bootloader
- UAVCAN总线 - UAVCAN固件升级
- UAVCAN总线 - UAVCAN配置
- UAVCAN总线 - UAVCAN 的各种笔记
- 传感器和执行机构总线 - UART
- UART - uLanding Radar
- 传感器和执行机构总线 - 设置云台控制
- 传感器和执行机构总线 - 相机触发器
- Hardware - 协同电脑
- 仿真
- 仿真 - 基本仿真
- 仿真 - Gazebo仿真
- 仿真 - HITL仿真
- 仿真 - 连接到ROS
- 仿真 - AirSim仿真
- 仿真 - 多机仿真
- 中间件及架构
- 中间件及架构 - uORB消息机制
- 中间件及架构 - MAVLink消息机制
- 中间件及架构 - 守护程序
- 中间件及架构 - 驱动框架
- 模块 & 命令
- 模块 & 命令 - 命令
- 模块 & 命令 - 通信
- 模块 & 命令 - 驱动
- 模块 & 命令 - 系统
- Robotics
- Robotics - 用Linux进行外部控制
- Robotics - ROS
- ROS - 在RPi上安装ROS
- ROS - MAVROS (ROS上的MAVLink)
- ROS - MAVROS外部控制例程
- ROS - 外部位置估计
- ROS - Gazebo Octomap
- Robotics - DroneKit
- Debugging/Logging
- Debugging/Logging - FAQ
- Debugging/Logging - 系统控制台
- Debugging/Logging - 自驾仪调试
- Debugging/Logging - Sensor/Topic Debugging
- Debugging/Logging - 仿真调试
- Debugging/Logging - System-wide Replay
- Debugging/Logging - 发送调试的值
- Debugging/Logging - Profiling
- Debugging/Logging - 日志记录
- 教程 - 光流
- 教程 - ecl EKF
- 教程 - 飞行前检查
- 教程 - 着陆检测
- 教程 - Linux系统下使用S.Bus驱动
- Advanced Topics
- Advanced Topics - 系统启动
- Advanced Topics - 参数&配置
- Advanced Topics - 参考参数
- Advanced Topics - 安装Intel RealSense R200的驱动
- Advanced Topics - 切换状态估计器
- Advanced Topics - 外部模块
- Advanced Topics - STM32 Bootloader
- 测试和持续集成
- 测试和持续集成 - 持续集成
- 测试和持续集成 - Jenkins持续集成环境
- 测试和持续集成 - 综合测试
- 测试和持续集成 - Docker容器
- 测试和持续集成 - 维护
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Robotics - DroneKit
translated_page: https://github.com/PX4/Devguide/blob/master/en/dronekit/example.md
translated_sha: 95b39d747851dd01c1fe5d36b24e59ec865e323e
Using DroneKit to communicate with PX4
DroneKit 可以帮助创建强大的无人机应用。这些应用运行在无人机的协同计算机上,通过执行计算密集但又需要低延迟的任务(计算机视觉)来增强飞控计算机。
DroneKit和PX4目前致力于获得完全兼容。截止DroneKit-python 2.2.0,仅提供任务处理和状态监控这样的基本支持。
配置DroneKit
首先,从当前主分支安装DroneKit-python
git clone https://github.com/dronekit/dronekit-python.git
cd ./dronekit-python
sudo python setup.py build
sudo python setup.py install
创建一个新的python文件并导入DroneKit, pymavlink和基本模块
# Import DroneKit-Python
from dronekit import connect, Command, LocationGlobal
from pymavlink import mavutil
import time, sys, argparse, math
连接到无人机或模拟器的MAVLink端口
# Connect to the Vehicle
print "Connecting"
connection_string = '127.0.0.1:14540'
vehicle = connect(connection_string, wait_ready=True)
显示一些基本的状态信息
# Display basic vehicle state
print " Type: %s" % vehicle._vehicle_type
print " Armed: %s" % vehicle.armed
print " System status: %s" % vehicle.system_status.state
print " GPS: %s" % vehicle.gps_0
print " Alt: %s" % vehicle.location.global_relative_frame.alt
完整的任务示例
下面的python脚本文件给出了使用DroneKit和PX4的完整任务范例。目前还不完全支持模式切换,因此我们发送自定义的模式切换指令。
################################################################################################
# @File DroneKitPX4.py
# Example usage of DroneKit with PX4
#
# @author Sander Smeets <sander@droneslab.com>
#
# Code partly based on DroneKit (c) Copyright 2015-2016, 3D Robotics.
################################################################################################
# Import DroneKit-Python
from dronekit import connect, Command, LocationGlobal
from pymavlink import mavutil
import time, sys, argparse, math
################################################################################################
# Settings
################################################################################################
connection_string = '127.0.0.1:14540'
MAV_MODE_AUTO = 4
# https://github.com/PX4/Firmware/blob/master/Tools/mavlink_px4.py
# Parse connection argument
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--connect", help="connection string")
args = parser.parse_args()
if args.connect:
connection_string = args.connect
################################################################################################
# Init
################################################################################################
# Connect to the Vehicle
print "Connecting"
vehicle = connect(connection_string, wait_ready=True)
def PX4setMode(mavMode):
vehicle._master.mav.command_long_send(vehicle._master.target_system, vehicle._master.target_component,
mavutil.mavlink.MAV_CMD_DO_SET_MODE, 0,
mavMode,
0, 0, 0, 0, 0, 0)
def get_location_offset_meters(original_location, dNorth, dEast, alt):
"""
Returns a LocationGlobal object containing the latitude/longitude `dNorth` and `dEast` metres from the
specified `original_location`. The returned Location has the same `alt` value
as `original_location`.
The function is useful when you want to move the vehicle around specifying locations relative to
the current vehicle position.
The algorithm is relatively accurate over small distances (10m within 1km) except close to the poles.
For more information see:
http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
"""
earth_radius=6378137.0 #Radius of "spherical" earth
#Coordinate offsets in radians
dLat = dNorth/earth_radius
dLon = dEast/(earth_radius*math.cos(math.pi*original_location.lat/180))
#New position in decimal degrees
newlat = original_location.lat + (dLat * 180/math.pi)
newlon = original_location.lon + (dLon * 180/math.pi)
return LocationGlobal(newlat, newlon,original_location.alt+alt)
################################################################################################
# Listeners
################################################################################################
home_position_set = False
#Create a message listener for home position fix
@vehicle.on_message('HOME_POSITION')
def listener(self, name, home_position):
global home_position_set
home_position_set = True
################################################################################################
# Start mission example
################################################################################################
# wait for a home position lock
while not home_position_set:
print "Waiting for home position..."
time.sleep(1)
# Display basic vehicle state
print " Type: %s" % vehicle._vehicle_type
print " Armed: %s" % vehicle.armed
print " System status: %s" % vehicle.system_status.state
print " GPS: %s" % vehicle.gps_0
print " Alt: %s" % vehicle.location.global_relative_frame.alt
# Change to AUTO mode
PX4setMode(MAV_MODE_AUTO)
time.sleep(1)
# Load commands
cmds = vehicle.commands
cmds.clear()
home = vehicle.location.global_relative_frame
# takeoff to 10 meters
wp = get_location_offset_meters(home, 0, 0, 10);
cmd = Command(0,0,0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 1, 0, 0, 0, 0, wp.lat, wp.lon, wp.alt)
cmds.add(cmd)
# move 10 meters north
wp = get_location_offset_meters(wp, 10, 0, 0);
cmd = Command(0,0,0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 1, 0, 0, 0, 0, wp.lat, wp.lon, wp.alt)
cmds.add(cmd)
# move 10 meters east
wp = get_location_offset_meters(wp, 0, 10, 0);
cmd = Command(0,0,0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 1, 0, 0, 0, 0, wp.lat, wp.lon, wp.alt)
cmds.add(cmd)
# move 10 meters south
wp = get_location_offset_meters(wp, -10, 0, 0);
cmd = Command(0,0,0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 1, 0, 0, 0, 0, wp.lat, wp.lon, wp.alt)
cmds.add(cmd)
# move 10 meters west
wp = get_location_offset_meters(wp, 0, -10, 0);
cmd = Command(0,0,0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 1, 0, 0, 0, 0, wp.lat, wp.lon, wp.alt)
cmds.add(cmd)
# land
wp = get_location_offset_meters(home, 0, 0, 10);
cmd = Command(0,0,0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_LAND, 0, 1, 0, 0, 0, 0, wp.lat, wp.lon, wp.alt)
cmds.add(cmd)
# Upload mission
cmds.upload()
time.sleep(2)
# Arm vehicle
vehicle.armed = True
# monitor mission execution
nextwaypoint = vehicle.commands.next
while nextwaypoint < len(vehicle.commands):
if vehicle.commands.next > nextwaypoint:
display_seq = vehicle.commands.next+1
print "Moving to waypoint %s" % display_seq
nextwaypoint = vehicle.commands.next
time.sleep(1)
# wait for the vehicle to land
while vehicle.commands.next > 0:
time.sleep(1)
# Disarm vehicle
vehicle.armed = False
time.sleep(1)
# Close vehicle object before exiting script
vehicle.close()
time.sleep(1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论