使用树莓派连接pixhawk飞控_Pixhawk无人机扩展教程(3)---树莓派安装Dronekit及读取飞控数据...

首先在树莓派根目录下新建一个名为test的文件夹用于存放测试代码文件。和使用windows系统存放文件一样,不过这是用命令操作,新手可能不太习惯,命令:mkdir ,输入以下命令:

mkdir -p  ~/test

可以输入 ls 命令,查看是否新建好这个文件夹,如下所示:

Pixhawk无人机扩展教程(3)---树莓派安装Dronekit及读取飞控数据-4.jpg (32.2 KB, 下载次数: 0)

2020-7-4 19:04 上传

通过cd命令切换到test文件夹下,创建名为connect.py的文件,测试树莓派能否连接飞控:

cd test

touch connect.py

可以输入 ls 命令,查看是否新建好这个文件,如下所示:

Pixhawk无人机扩展教程(3)---树莓派安装Dronekit及读取飞控数据-5.jpg (41.89 KB, 下载次数: 0)

2020-7-4 19:04 上传

用 vim编辑文件:

sudo vim connect.py

将以下代码复制到文件中:

from dronekit import connect

# Connect to the Vehicle (in this case a UDP endpoint)

vehicle = connect('/dev/ttyUSB0', wait_ready=True, baud=921600)

# 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

Pixhawk无人机扩展教程(3)---树莓派安装Dronekit及读取飞控数据-6.jpg (129.06 KB, 下载次数: 0)

2020-7-4 19:04 上传

保存代码并退出(如何保存编辑操作请参考《Pixhawk无人机扩展教程(2)》)

以上代码涵盖了大部分的无人机状态,通过执行以上代码就能读取当前飞控状态参数。

注意:不要急着执行以上脚本。可能提示权限不够出错。需要赋予USB0端口权限,以下逐步介绍。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值