Dronekit使用串口在Win10下控制pixhawk飞控教程

(一)Dronekit 环境搭建

DroneKit-Python是一个用于控制无人机的Python库。DroneKit提供了用于控制无人机的API,其代码独立于飞控,单独运行在机载电脑或其他设备之上,通过串口或者无线的方式经由MAVLink协议与飞控板通信。亦可在自行编译SITL模拟器上进行测试。

英文手册网址:https://dronekit-python.readthedocs.io/en/latest/about/index.html

代码网址:https://github.com/dronekit/dronekit-python

一 .安装Python2.7
DroneKit-Python可以安装在具有Python 2.7并且可以从Internet安装Python软件包的Linux,Mac OSX或Windows计算机上。

下载地址:python2.7.14
下载完成后。接下来就是进行python安装。一键点击运行,全部选择同意,默认安装路径即可在系统盘C盘看到自己的安装文件。此时剩余工作,就是把Python的安装路径添加到系统的环境变量Path中。(注意:下图划红线也要安装上)注意

接下来设置环境变量:我使用的Python默认安装路径,为C:\Python27,那么找到系统环境变量设置,点击Path,添加两个路径变量。
具体如下:
在这里插入图片描述

完成环境变量设置后:在CMD中直接输入python即可打开自带的编译环境,也可直接使用python命令

python --version

在这里插入图片描述

由于python安装包 自带pip。因此,只要设置对pip的环境变量。即可在cmd中输入

pip —V

即可查询相应的pip版本。
在这里插入图片描述

接下来就是安装DroneKit
确认Python已成功安装后,打开cmd,输入以下命令安装DroneKit

pip install dronekit

另外如果用pc直接飞控,要注意串口无法连接的问题 。因此还需安装端口插件

pip install pyserial

至此Dronekit-python环境安装完成。

接下来:用usb线将飞控接在pc上。然后再查看飞控在pc中的端口。最后,在桌面上新建名为connect.py代码脚本。此代码为读取飞控相关信息(注意:代码中端口要与PC中所读出来的端口号要对应,否则会无法连接)

from dronekit import connect

# Connect to the Vehicle (in this case a UDP endpoint)
vehicle = connect('com16', wait_ready=True)
# vehicle is an instance of the Vehicle class

print "Autopilot Firmware version: %s" % vehicle.version

print "Autopilot capabilities (supports ftp): %s" % vehicle.capabilities.ftp

print "Global Location: %s" % vehicle.location.global_frame

print "Global Location (relative altitude): %s" % vehicle.location.global_relative_frame

print "Local Location: %s" % vehicle.location.local_frame    #NED

print "Attitude: %s" % vehicle.attitude

print "Velocity: %s" % vehicle.velocity

print "GPS: %s" % vehicle.gps_0

print "Groundspeed: %s" % vehicle.groundspeed

print "Airspeed: %s" % vehicle.airspeed

print "Gimbal status: %s" % vehicle.gimbal

print "Battery: %s" % vehicle.battery

print "EKF OK?: %s" % vehicle.ekf_ok

print "Last Heartbeat: %s" % vehicle.last_heartbeat

print "Rangefinder: %s" % vehicle.rangefinder

print "Rangefinder distance: %s" % vehicle.rangefinder.distance

print "Rangefinder voltage: %s" % vehicle.rangefinder.voltage

print "Heading: %s" % vehicle.heading

print "Is Armable?: %s" % vehicle.is_armable

print "System status: %s" % vehicle.system_status.state

print "Mode: %s" % vehicle.mode.name    # settable

print "Armed: %s" % vehicle.armed    # settable

编辑完成后,在 CMD中运行相关代码

cd Desktop
python connect.py

在这里插入图片描述
至此,Dronekit在win10下环境搭建完成。

所借鉴的相关网址:

1.Dronekit安装

https://blog.csdn.net/liberatetheus/article/details/78004762?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

2.python2.7安装

https://www.cnblogs.com/liuzhen1995/p/8092996.html

  • 1
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值