plutoComms module¶
-
class
plutoComms.
COMMS
(IP='192.168.4.1', Port=23, debug=False)¶ Bases:
object
This is the class for all communication with the pluto drone.
It has two threads running in parallel:
1) The write Thread: which sends data to the drone based on the values of the parameter to be set and requests to be made.
2) The read Thread: which reads data from the drone and updates the parameters received based on the requests sent.- Attribute:
- TCP_IP: IP address of the drone.
Port: Port of the drone.
debug: a flag to enable prints in code for debugging.
mySocket: refers to the instance of socket connected to the drone at the specified IP and Port.
waitTime: variable to control sleep time after every command, so as to ensure that it is sent to the drone in the write thread.
inLoopSleepTime: variable to control sleep time in write thread, thus controlling publishing frequency.
outLoopSleepTime: variable to control sleep time in read thread, thus controlling subscribing frequency. writeLoop: variable to control writing loop i.e. if we want to write data or not.
readLoop: variable to control reading loop i.e. if we want to read data or not.
outServices: Dictionary of all the out packets we request for with their type of payload values.
requestMSPPackets: List of MSP requests for Out Packets.
paramSet: Dictionary of parameter to be set based on their values through IN Packets.
paramReceived: Dictionary of parameters received from the OUT Packets.
-
arm
()¶ Member Function to Arm the drone.
-
backFlip
()¶ Member Function to set command as Back Flip.
-
backward
()¶ Member function to decrease pitch so that the drone moves backward.
-
boxArm
()¶ Member Function to BoxArm the drone.
-
decreaseHeight
()¶ Member Function to decrease throttle so that height of drone is decreased.
-
disArm
()¶ Member Function to Disarm the drone.
-
disconnect
()¶ Member Function to disconnect communication and stop read and writing loops.
-
forward
()¶ Member Function to increase pitch so that the drone moves forward.
-
getAllRequestMsgs
()¶ Member Function to generate MSP Packets for all Out Packets mentioned in OUT services.
-
increaseHeight
()¶ Member Function to increase throttle so that height of drone is increased.
-
land
()¶ Member Function to set command as Land.
-
left
()¶ Member Function to decrease roll so that the drone moves towards left.
-
leftYaw
()¶ Member Function to decrease yaw so that the drone rotates left.
-
lowThrottle
()¶ Member Function to provide a low throttle, generally used for hardware testing.
-
printParams
()¶ Member Function to Print all the Parameters.
-
processBuffer
(buff, funDebug=False)¶ This function processes the current buffer and return the list of decoded values as out list, the OUT Packet payload corresponding to which the values are and the remaining buffer. Returns empty out list and 0 as payload if buffer does not contain the full message
-
read
(IMUQueue, imuLock)¶ Member Function which is target function to the Reading Thread. All the data sent by the drone is received in this function.
In the loop we wait for 2 seconds max, if we do not receive any data on the socket then we break out of the loop. While receiving we append that message at the end of the currently existing buffer. After this the current buffer is again and again processed and the parameter received are updated until the buffer can no longer be processed.
-
receiveMSPresponse
(buff)¶ Member Function to receive data and process it to return decoded values and updated buffer.
-
reset
()¶ Member Function to set all parameters to set to default values.
-
right
()¶ Member Function to increase roll so that the drone moves towards right.
-
rightYaw
()¶ Member Function to decrease yaw so that the drone rotates right.
-
takeOff
()¶ Member Function to set command as TakeOff.
-
updateBuffer
(buff)¶ Member Function to read data and appends it at the end of buffer.
-
updateParams
(out, idx)¶ Member Function to update the received parameters.
:param out: Decoded Values
:type out: List
:param idx: value of type of payload
:type idx: int
-
write
(commandLock)¶ Member Function which is the target of the Writing Thread. All writing to the drone takes place in this function until we set sendData to False
Before entering the loop we set the Roll and Pitch Trim, as it is to be done only once in the starting. In the loop we keep sending the SET_RAW_RC commands, we check if SET_COMMAND is not 0 then we send that also. In every iteration, we also request for all the messages we want as OUT Packets.
-
class
plutoComms.
MSPPacket
(debug=False)¶ Bases:
object
This is a class for MSP Packets.
- Attributes:
- header: a list containing the header of the MSP Packet i.e. [36, 77].
direction: a dictionart to store the value mapped to in and out direction of MSGS.
msg: a list to store the full message.
debug: a flag to enable prints in code for debugging.
-
appendCRC
()¶ Constructor for the MSP Packet Class. Initializes the header list and direction dictionary. Parameters:
debug: to pass in the flag for debugging, by default set to False.
-
getInMsgRequest
(msgLen, typeOfPayload, msgData)¶ This is a Member Function to return MSP Packet in direction for given message length, type of payload and data.
- Parameter:
- msgLen: length of message.
typeOfPayload: stores value assigned to that type of payload.
msgData: stores the data to be sent.
-
getOutMsgRequest
(msgLen, typeOfPayload, msgData)¶ This is a Member Function to return MSP Packet out direction for given message length, type of payload and data.
- Parameter:
- msgLen: length of message.
typeOfPayload: stores value assigned to that type of payload.
msgData: stores the data to be sent.