petrone for python / Drone
Modified : 2018.2.12
Introduce drone module
Drone classes
Drone class constructor
Drone classes constructor as follows :
def __init__(self, flagCheckBackground = True, flagShowErrorMessage = False, flagShowLogMessage = False, flagShowTransferData = False, flagShowReceiveData = False):
Name | Description |
---|---|
flagCheckBackground | Check received data in background |
flagShowErrorMessage | Show error message |
flagShowLogMessage | Show log message |
flagShowTransferData | Display the send data array |
flagShowReceiveData | Display the receive data array |
If Drone class constuctor does not call specify it's initial variable flagCheckBackground is True and all ohter value is False. If flagCheckBackground is True, Whenever receive data, Invoke check() function from inner class. If flagCheckBackground is False, Whenever receive data, You must manualy call check() function to process the received data.
Drone class's public methods
Drone class's public methods list.
Name | Description |
---|---|
isOpen() | Serial port connection status return |
isConnected() | BLE connection status return |
open(portName) | Open serial port. If you do not specify a port name, connect to the last detected device. Return True when port is opened |
connect(portName, deviceName, flagSystemReset) | If the serial port is not open, open the serial port, Search for PETRONE and connect it to the device with the strongest signal. If you specify a deviceName, Connect only when the specified device is discovered. flagSystemReset is use to reset and start the first PETRONE LINK after the serial communication connection. Default value is False. |
close() | Close serial port |
makeTransferDataArray(header, data) | Make transfer byte data array. |
transfer(header, data) | Trnasfer data(Internal call makeTransferDataArray function) |
check() | Check received data. Returns DataType when Data Received |
checkDetail() | Check received data. Return header and data to tuple |
setEventHandler(dataType, eventHandler) | Register a custom function to call when data of a specific type is received |
getHeader(dataType) | Returns the received header with the specified type of data |
getData(dataType) | Returns the received data (If does not have data, Return None.) |
getCount(dataType) | Returns the number of times the specified type was received (If never received data, Return 0.) |
Drone class data processing unit
Drone class's receive data processing unit is organized as follows
Name | Description |
---|---|
_receiving() | Data receiving Thread, Save received data to buffer. |
check() | Read 1-byte of data stored in the buffer and pass it to the receiver. If one data block received call _handler(), data parsing and return the datatype. Returns DataType.None_ if no data received. |
_handler() | Save header internally. Data parsing and saved internal class. If event handler is registered call function. |
Function list
Common
Name | Description |
---|---|
sendPing | Send Ping |
sendRequest | Send Request |
Control
Name | Description |
---|---|
sendTakeOff | Takeoff |
sendLanding | Landing |
sendStop | Stop |
sendControl | Send Flight control |
sendControlWhile | Send Flight control during the specified time |
sendControlDrive | Send Drive control |
sendControlDriveWhile | Send Drive control during the specified time |
Setting
Name | Description |
---|---|
sendCommand | Send command |
sendModeVehicle | Flight/Drive mode change |
sendHeadless | Headless mode setting |
sendTrim | Trim setting |
sendTrimFlight | Flight Trim setting |
sendTrimDrive | Drive Trim setting |
sendFlightEvent | Execute flight event |
sendDriveEvent | Execute drive event |
sendClearTrim | Clear Trim data |
sendClearGyroBias | Clear Gyro bias |
sendUpdateLookupTarget | Check firmware information |
Motor
Name | Description |
---|---|
sendMotor | Control motor |
IR
Name | Description |
---|---|
sendIrMessage | Send IR Message |
LED
Name | Description |
---|---|
sendLightMode | Mode setting(Pallet) |
sendLightModeCommand | Mode setting(Pallet), Command |
sendLightModeCommandIr | Mode setting(Pallet), Command, IR |
sendLightModeColor | Mode setting(RGB) |
sendLightEvent | Event setting(Pallet) |
sendLightEventCommand | Event setting(Pallet), Command |
sendLightEventCommandIr | Event setting(Pallet), Command, IR |
sendLightEventColor | Event setting(RGB) |
LINK
Name | Description |
---|---|
sendLinkModeBroadcast | LINK Broadcast mode change |
sendLinkSystemReset | LINK reset |
sendLinkDiscoverStart | PETRONE scan start |
sendLinkDiscoverStop | PETRONE scan stop |
sendLinkConnect | PETRONE connect |
sendLinkDisconnect | PETRONE disconnect |
sendLinkRssiPollingStart | RSSI polling start |
sendLinkRssiPollingStop | RSSI polling stop |
Function declaration.
sendPing
Send ping
Check drone connection status. Response is ack.
def sendPing(self):
sendRequest
Request data
For request data.
def sendRequest(self, dataType):
Variable name | Type and Range | Description |
---|---|---|
dataType | DataType | data type |
sendTakeOff
TakeOff
This function work only flight mode. ( In Ready state )
def sendTakeOff(self):
sendLanding
Landing
This function work only flight mode. ( In Flight state )
def sendLanding(self):
sendStop
Stop
Used to force stop of drone action.
def sendStop(self):
sendControl
Flight control
Can be used for both flight and drive mode.
def sendControl(self, roll, pitch, yaw, throttle):
Variable name | Type and Range | Description |
---|---|---|
roll | -100 ~ 100 | Roll |
pitch | -100 ~ 100 | Pitch |
yaw | -100 ~ 100 | Yaw |
throttle | -100 ~ 100 | Throttle |
sendControlWhile
Flight control
Can be used for both flight and drive mode. Sends the control commands for the ms specified in timeMs.
def sendControlWhile(self, roll, pitch, yaw, throttle, timeMs):
Variable name | Type and Range | Description |
---|---|---|
roll | -100 ~ 100 | Roll |
pitch | -100 ~ 100 | Pitch |
yaw | -100 ~ 100 | Yaw |
throttle | -100 ~ 100 | Throttle |
timeMs | 0 ~ 1,000,000 | Work time(ms) |
sendControlDrive
Drive control
This function work only drive mode.
def sendControlDrive(self, wheel, accel):
Variable name | Type and Range | Description |
---|---|---|
wheel | -100 ~ 100 | Wheel |
accel | -100 ~ 100 | Accel |
sendControlDriveWhile
Drive control
This function work only drive mode. Sends the control commands for the ms specified in timeMs.
def sendControlDriveWhile(self, wheel, accel, timeMs):
Variable name | Type and Range | Description |
---|---|---|
wheel | -100 ~ 100 | Wheel |
accel | -100 ~ 100 | Accel |
timeMs | 0 ~ 1,000,000 | Work time(ms) |
sendCommand
Send command
Send drone command.
The option must have a value or a enumerate value for each type.
def sendCommand(self, commandType, option = 0):
Variable name | Type and Range | Description |
---|---|---|
commandType | CommandType | Command type |
option | ModeVehicle | Option |
FlightEvent | ||
DriveEvent | ||
Headless | ||
Trim | ||
UInt8 |
sendModeVehicle
Vehicle mode setting
You can change the drone to flight or drive mode.
def sendModeVehicle(self, modeVehicle):
Variable name | Type and Range | Description |
---|---|---|
modeVehicle | ModeVehicle | Vehicle mode |
sendHeadless
Headless mode setting
def sendHeadless(self, headless):
Variable name | Type and Range | Description |
---|---|---|
headless | Headless | Headless mode |
sendTrim
Trim setting
def sendTrim(self, trim):
Variable name | Type and Range | Description |
---|---|---|
trim | Trim | Trim setting |
sendTrimFlight
Flight Trim setting
def sendTrimFlight(self, roll, pitch, yaw, throttle):
Variable name | Type and Range | Description |
---|---|---|
roll | -200 ~ 200 | Roll |
pitch | -200 ~ 200 | Pitch |
yaw | -200 ~ 200 | Yaw |
throttle | -200 ~ 200 | Throttle |
sendTrimDrive
Drive Trim setting
def sendTrimDrive(self, wheel):
Variable name | Type and Range | Description |
---|---|---|
wheel | -200 ~ 200 | Wheel |
sendFlightEvent
Send Flight event
def sendFlightEvent(self, flightEvent):
Variable name | Type and Range | Description |
---|---|---|
flightEvent | FlightEvent | Flight event |
sendDriveEvent
Send Drive event
def sendDriveEvent(self, driveEvent):
Variable name | Type and Range | Description |
---|---|---|
driveEvent | DriveEvent | Drive event |
sendClearTrim
Clear Flight and Drive Trim
def sendClearTrim(self):
sendClearGyroBias
Clear Accel and Gyro Bias
def sendClearGyroBias(self):
sendMotor
Rotate the 4 motors in a predefined direction
def sendMotor(self, motor0, motor1, motor2, motor3):
Variable name | Type and Range | Description |
---|---|---|
motor0 | 0 ~ 4095 | Front left moter speed |
motor1 | 0 ~ 4095 | Front right moter speed |
motor2 | 0 ~ 4095 | Rear right moter speed |
motor3 | 0 ~ 4095 | Rear left moter speed |
sendIrMessage
Send IR Message
def sendIrMessage(self, value):
Variable name | Type and Range | Description |
---|---|---|
value | 0x00000000 ~ 0xFFFFFFFF | IR Message value |