< >
Home » DroneKit-Python教程 » DroneKit-python入门教程教程-安装DroneKit(linux)

DroneKit-python入门教程教程-安装DroneKit(linux)

DroneKit-python入门教程教程-安装DroneKit(linux)

说明:

  • 介绍如何在linux下安装DroneKit
  • 测试环境:ubuntu 16.04

步骤:

  • 安装依赖
sudo apt-get install python-pip python-dev
  • 安装
pip install dronekit
pip install dronekit-sitl
  • 编写例子,vim hello.py
print "Start simulator (SITL)"
import dronekit_sitl
sitl = dronekit_sitl.start_default()
connection_string = sitl.connection_string()

# Import DroneKit-Python
from dronekit import connect, VehicleMode

# Connect to the Vehicle.
print("Connecting to vehicle on: %s" % (connection_string,))
vehicle = connect(connection_string, wait_ready=True)

# Get some vehicle attributes (state)
print "Get some vehicle attribute values:"
print " GPS: %s" % vehicle.gps_0
print " Battery: %s" % vehicle.battery
print " Last Heartbeat: %s" % vehicle.last_heartbeat
print " Is Armable?: %s" % vehicle.is_armable
print " System status: %s" % vehicle.system_status.state
print " Mode: %s" % vehicle.mode.name    # settable

# Close vehicle object before exiting script
vehicle.close()

# Shut down simulator
sitl.stop()
print("Completed")
  • 运行
python hello.py
  • 效果
Start simulator (SITL)
Downloading SITL from http://dronekit-assets.s3.amazonaws.com/sitl/copter/sitl-win-copter-3.3.tar.gz
Extracted.
Connecting to vehicle on: 'tcp:127.0.0.1:5760'
>>> APM:Copter V3.3 (d6053245)
>>> Frame: QUAD
>>> Calibrating barometer
>>> Initialising APM...
>>> barometer calibration complete
>>> GROUND START
Get some vehicle attribute values:
 GPS: GPSInfo:fix=3,num_sat=10
 Battery: Battery:voltage=12.587,current=0.0,level=100
 Last Heartbeat: 0.713999986649
 Is Armable?: False
 System status: STANDBY
 Mode: STABILIZE
Complete
  • 下载示例

  • 获取DroneKit-Python示例源代码到本地计算机上

    git clone http://github.com/dronekit/dronekit-python.git

  • 运行显示车辆状态示例

cd dronekit-python/examples/vehicle_state/
python vehicle_state.py

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: dronekit-python入门教程教程