コーディングドローンで使用する送信機のボタン入力(押下)状態をリアルタイムで取得・出力します。
sendPing() を実行して、通信セッションを確立。setEventHandler(DataType.EventButton, 関数) を使って、ボタンイベントの受信時に呼び出される関数を設定。| ボタン名 | 値 (Hex) | 値 (Decimal) |
|---|---|---|
| ↑ ボタン | 0x0040 | 64 |
| ↓ ボタン | 0x0200 | 512 |
| → ボタン | 0x0100 | 256 |
| ← ボタン | 0x0080 | 128 |
| S ボタン | 0x0400 | 1024 |
| P ボタン | 0x0800 | 2048 |
| 電源ボタン | 0x0020 | 32 |
| H ボタン(トリム) | 0x0010 | 16 |
※複数ボタンが同時に押された場合、ビット演算の合計値になります。
from time import sleep
from CodingDrone.drone import *
from CodingDrone.protocol import *
def eventButton(button):
print("eventButton() / " +
"Button: 0b{0:16}, Event: {1:6}".format(bin(button.button)[2:].zfill(16),
button.event.name))
if __name__ == '__main__':
drone = Drone()
drone.open()
# イベントハンドリング関数登録
drone.setEventHandler(DataType.Button, eventButton)
drone.sendPing(DeviceType.Controller)
for i in range(10, 0, -1):
print(i)
sleep(1)
drone.close()
e.g : Button
e.g : sendping
sendPing() を適切に使用すると安定します。コーディングドローンで使用するコントローラのジョイスティック入力情報をリアルタイムで取得・出力します。