06. Dronekit in Raspberry Pi 3 bp - pineland/px4 GitHub Wiki
- ์ฐธ๊ณ : http://dronekit.io/
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์ ํ์ฉ ์์ ๋ฅผ ์๋ ํ๋ค.