Pure-Python Wrapper for Pluto Drone
plutoPy is a pure python wrapper, which enables Python-based remote commands to be used to control the PLUTO drone. This includes connecting to drone through sockets, sending and receiving MSP data, all in python, just by writing simple high-level code
- Getting Started
- Pre-Requisites
- Installation
- How to Run
- Usage Instructions
- Connection
- Basic Commands
- Control
- State & Other Information
- Key binds
- Structure and Methodology
- Contents and Hierarchy
- Working
- Acknowledgements
plutoPy is a lightweight package, with its requirements already satisfied in the base installation of Python.
Python 3 (tested on ≥ 3.6)
Clone the GitHub repository given below, (plutopy is a package, can be copied as required) https://github.com/bhuvannarula/plutoPy
For global installation of package,
The package can be installed by running the following pip command, (requires Git)
pip install git+https://github.com/bhuvannarula/plutoPy.gitThe package, at its heart, creates a drone class that is used for doing any task. To import it, simply run the following code(s),
from plutopy import plutoDrone
For further use, refer to example_BasicControls.py script.
from plutopy import plutoSwarm,
For further use, refer to example_DroneSwarm.py script.
After you have imported plutoDrone, use the following commands to establish a connection and open the command line:
drone = plutoDrone(IP_ADDRESS, PORT)
All parameters are optional, and a single drone can be easily initialized on default values (IP : 192.168.4.1, PORT : 23)
drone = plutoDrone()
To start the connection to drone, and the threads for communicating with drone, just call the function,
drone.start()
If the connection fails you can use the following command to reconnect to the drone:
drone.reconnect()
If you wish to disconnect you can use:
drone.disconnect()
Arming
To pass any command to the motors, you need to arm the drone first. You can arm using:
drone.control.arm()
This will also set the throttle to 1000 by default.
Box Arm
Box Arm will set the throttle value to 1500 by default.
drone.control.boxarm()
Disarming
To disarm the drone:
done.control.disarm()
Take Off
Disarms the drone, and the drone takes off:
drone.control.take_off()
Land
Landing reduces the throttle speed at a constant rate before stopping them.
drone.control.land()
Reset
To reset the drone to its default configuration:
drone.control.reset()
Kill
To kill the motors:
drone.control.kill()
Following commands can be used to control the drone’s position. To change command values or to reconfigure them, you can find them in plutopy/commands.py file.
Forward
To move the drone forward:
drone.control.forward()
By default it will change the pitch value to 1600.
Backward
To move the drone backward:
drone.control.backward()
By default it will change the pitch value to 1400.
Left
To move the drone leftward:
drone.control.left()
By default it will change the roll value to 1400.
Right
To move the drone rightward:
drone.control.right()
By default it will change the roll value to 1600.
Increase Height
To increase height at constant acceleration:
drone.control.increase_height()
By default it will increase the throttle to 1800.
Decrease Height
To decrease height at constant acceleration:
drone.control.decrease_height()
By default it will decrease the throttle to 1300.
Throttle
To set the throttle to particular value:
drone.rc.rcThrottle = {value}
Pitch & Roll
To set the trim for pitch and roll:
drone.control.trimRollPitch({trim_roll_value}, {trim_pitch_value})
To set roll and pitch to a particular value:
drone.activeState.rcPitch = {value} drone.activeState.rcRoll = {value}
Yaw
To set the drone towards left or right:
drone.control.right_yaw() drone.control.left_yaw()
By default it sets yaw to 1800 & 1200 respectively.
To set the yaw to particular value:
drone.rc.rcYaw = {value}
State
To get the state of the drone:
drone.state.array()
Returns an array as [Roll,Pitch,Throttle,Yaw,AUX1,AUX2,AUX3,AUX4]. You can find more information regarding the AUX parameters here.
You can get other information by using drone.state.{X}()
- {X} can be:
- roll
- pitch
- yaw
- battery
- rssi
- accX
- accY
- accZ
- gyroX
- gyroY
- gyroZ
- magX
- magY
- magZ
- alt
- FC_versionMajor
- FC_versionMinor
- FC_versionPatchLevel
- rcRoll
- rcPitch
- rcYaw
- rcAUX1
- rcAUX2
- rcAUX3
- rcAUX4
- trim_roll
- trim_pitch
- commandType
- isAutoPilotOn
Sensor Information
All in order [x,y,z].
From Gyroscope:
drone.info.gyro()
From Accelerometer:
drone.info.acc()
From Magnetometer:
drone.info.mag()
From all the three sensors:
drone.info.all9()
Following are the contents of the wrapper:
-
init.py
Declaration for module.
-
common.py
Some commonly used functions.
-
plutostate.py
Contains plutoState class, which stores state data of drone.
-
plutoinfo.py
Sensor information.
-
reader.py
Serial Reader for response from the Drone.
-
plutosock.py
Class for connecting to drone through sockets.
-
protocol.py
Class for creating and receiving MSP Packets for communication.
-
commands.py
Class for Control commands.
-
pluto.py
Main plutoDrone class, which stitches all the classes together.
-
plutoswarm.py
Class for easy initialization of Pluto Drone Swarm.
This wrapper works through a multi-threaded method, in which different threads are responsible for sending and receiving the data from drone. The connection with the drone is implemented using the MSP protocol. Different aspects of the wrapper are explained below.
The communication with drone is through low-level sockets, in which requests are sent from client (computer) to host (drone), and response is received.
Mainly two threads are initialized for communication, one for sending requests with data to drone, and another thread for receiving response from drone. In this manner, independent two-way communication with drone is implemented.
A modified version of the Multiwii Serial Protocol (MSP) is used by Pluto. There are many packets designed specifically for flight based controllers in this protocol. These packets are manually created in the package, and sent to drone over sockets. More information on this protocol is available at Multiwii, or in this document.
All components are integrated using the pluto.py file through plutoDrone class which initialises the socket, necessary threads and states, and the control interface, which enable the package to control the drone.
The base logic of this wrapper has been derived from the C++ logic implemented in the Pluto ROS Package, and has been highly customized to make it reliable and easy to use.