06. Dronekit in Raspberry Pi 3 bp - pineland/px4 GitHub Wiki

1. ์„ค์น˜

sudo apt-get install python-pip python-dev  
sudo pip install dronekit  

2. ํ…Œ์ŠคํŠธ ํ”„๋กœ๊ทธ๋žจ(test.py) ์ž‘์„ฑ

# Import DroneKit-Python
from dronekit import connect, VehicleMode

# Connect to the Vehicle.
print"Connecting"
connection_string = '/dev/ttyAMA0'  # ์ „์ œ์กฐ๊ฑด : ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์™€ ํ”ฝ์Šคํ˜ธํฌ ๊ฐ„์— ์ง๋ ฌ ์—ฐ๊ฒฐ
vehicle = connect(connection_string, wait_ready=True, baud=921600)

# 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 " ARMED: %s" % vehicle.is_armable
print " Is Armable?: %s" % vehicle.is_armable
print " System status: %s" % vehicle.system_status.state
print " Mode: %s" % vehicle.mode.name    # settable

์ €์žฅํ•œ ํ›„์— $ python test.py๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•œ๋‹ค.

3. DroneKit-python ์„ค์น˜

cd $HOME
git clone https://github.com/dronekit/dronekit-python.git
cd ./dronekit-python
sudo python setup.py build
sudo python setup.py install

์ƒˆ๋กœ์šด ์˜ˆ์ œํŒŒ์ผ(test-dronekit-python.py)์„ ์ƒ์„ฑํ•˜๊ณ  DroneKit, pymavlink ๋ฐ ๊ธฐ๋ณธ ๋ชจ๋“ˆ์„ ๊ฐ€์ ธ์˜จ๋‹ค.

Import DroneKit-Python 
from dronekit import connect, Command, LocationGlobal
from pymavlink import mavutil 
import time, sys, argparse, math

# Connect to the Vehicle 
print "Connecting" 
# connection_string = '127.0.0.1:14540'
connection_string = '/dev/ttyAMA0' 
vehicle = connect(connection_string, wait_ready=True, baud=921600)

# 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 test-dronekit-python.py๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

https://dev.px4.io/v1.9.0/en/robotics/dronekit.html์˜ ๋‚ด์šฉ์„ ํ†ตํ•ด dronekit์˜ ํ™œ์šฉ ์˜ˆ์ œ๋ฅผ ์ˆ™๋…ํ•œ๋‹ค.