Used for sending control setpoints to the Crazyflie
| 50 | |
| 51 | |
| 52 | class PlatformService(): |
| 53 | """ |
| 54 | Used for sending control setpoints to the Crazyflie |
| 55 | """ |
| 56 | |
| 57 | def __init__(self, crazyflie=None): |
| 58 | """ |
| 59 | Initialize the platform object. |
| 60 | """ |
| 61 | self._cf = crazyflie |
| 62 | |
| 63 | self._cf.add_port_callback(CRTPPort.PLATFORM, |
| 64 | self._platform_callback) |
| 65 | self._cf.add_port_callback(CRTPPort.LINKCTRL, |
| 66 | self._crt_service_callback) |
| 67 | |
| 68 | # Request protocol version. |
| 69 | # The semaphore makes sure that other module will wait for the version |
| 70 | # to be received before using it. |
| 71 | self._has_protocol_version = False |
| 72 | self._protocolVersion = -1 |
| 73 | self._callback = None |
| 74 | |
| 75 | def fetch_platform_informations(self, callback): |
| 76 | """ |
| 77 | Fetch platform info from the firmware |
| 78 | Should be called at the earliest in the connection sequence |
| 79 | """ |
| 80 | |
| 81 | self._protocolVersion = -1 |
| 82 | self._callback = callback |
| 83 | |
| 84 | self._request_protocol_version() |
| 85 | |
| 86 | def set_continous_wave(self, enabled): |
| 87 | """ |
| 88 | Enable/disable the client side X-mode. When enabled this recalculates |
| 89 | the setpoints before sending them to the Crazyflie. |
| 90 | """ |
| 91 | pk = CRTPPacket() |
| 92 | pk.set_header(CRTPPort.PLATFORM, PLATFORM_COMMAND) |
| 93 | pk.data = (0, enabled) |
| 94 | self._cf.send_packet(pk) |
| 95 | |
| 96 | def get_protocol_version(self): |
| 97 | """ |
| 98 | Return version of the CRTP protocol |
| 99 | """ |
| 100 | return self._protocolVersion |
| 101 | |
| 102 | def _request_protocol_version(self): |
| 103 | # Sending a sink request to detect if the connected Crazyflie |
| 104 | # supports protocol versioning |
| 105 | pk = CRTPPacket() |
| 106 | pk.set_header(CRTPPort.LINKCTRL, LINKSERVICE_SOURCE) |
| 107 | pk.data = (0,) |
| 108 | self._cf.send_packet(pk) |
| 109 |