Skip to content

Instantly share code, notes, and snippets.

@HiromuKato
Created March 26, 2019 04:30
Show Gist options
  • Save HiromuKato/613746ccad6c3c96c87c2771e6f0bbbb to your computer and use it in GitHub Desktop.
Save HiromuKato/613746ccad6c3c96c87c2771e6f0bbbb to your computer and use it in GitHub Desktop.
HoudiniからTELLOを操作するスクリプト
from PySide2 import QtWidgets
import socket
def onCreateInterface():
widget = Tello()
return widget
class Tello(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
layout = QtWidgets.QHBoxLayout()
# Left
LU = QtWidgets.QPushButton("↑", self)
LU.clicked.connect(self.LeftUp)
LR = QtWidgets.QPushButton("→", self)
LR.clicked.connect(self.LeftRight)
LD = QtWidgets.QPushButton("↓", self)
LD.clicked.connect(self.LeftDown)
LL = QtWidgets.QPushButton("←", self)
LL.clicked.connect(self.LeftLeft)
# Center
CU = QtWidgets.QPushButton("↑", self)
CU.clicked.connect(self.CenterUp)
CD = QtWidgets.QPushButton("↓", self)
CD.clicked.connect(self.CenterDown)
# Right
RU = QtWidgets.QPushButton("↑", self)
RU.clicked.connect(self.RightUp)
RR = QtWidgets.QPushButton("→", self)
RR.clicked.connect(self.RightRight)
RD = QtWidgets.QPushButton("↓", self)
RD.clicked.connect(self.RightDown)
RL = QtWidgets.QPushButton("←", self)
RL.clicked.connect(self.RightLeft)
# 格子状にボタンを並べる
layout = QtWidgets.QGridLayout()
layout.addWidget(LU, 0, 1)
layout.addWidget(LR, 1, 2)
layout.addWidget(LD, 2, 1)
layout.addWidget(LL, 1, 0)
layout.addWidget(CU, 1, 3)
layout.addWidget(CD, 1, 4)
layout.addWidget(RU, 0, 1+5)
layout.addWidget(RR, 1, 2+5)
layout.addWidget(RD, 2, 1+5)
layout.addWidget(RL, 1, 0+5)
# TELLO move speed
self.__speed = 50
# Network Initialize
self.ConnectUdp()
self.setLayout(layout)
def closeEvent(self, e):
print("close")
self.SendMessage('end')
self.__sock.close()
MaxPlus.CUI.EnableAccelerators()
def __del__(self) :
print("destructor")
self.SendMessage('end')
self.__sock.close()
def ConnectUdp(self) :
host = ''
port = 9000
locaddr = (host, port)
# Create a UDP socket
self.__sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.__tello_address = ('192.168.10.1', 8889)
try:
self.__sock.bind(locaddr)
except:
self.__sock.close()
self.__sock.bind(locaddr)
self.SendMessage('command')
def SendMessage(self, msg) :
print msg
msg = msg.encode(encoding="utf-8")
sent = self.__sock.sendto(msg, self.__tello_address)
def LeftUp(*args) :
args[0].SendMessage('up ' + str(args[0].__speed))
def LeftRight(*args) :
args[0].SendMessage('cw ' + str(args[0].__speed))
def LeftDown(*args) :
args[0].SendMessage('down ' + str(args[0].__speed))
def LeftLeft(*args) :
args[0].SendMessage('ccw ' + str(args[0].__speed))
def CenterUp(*args) :
args[0].SendMessage('takeoff')
def CenterDown(*args) :
args[0].SendMessage('land')
def RightUp(*args) :
args[0].SendMessage('forward ' + str(args[0].__speed))
def RightRight(*args) :
args[0].SendMessage('right ' + str(args[0].__speed))
def RightDown(*args) :
args[0].SendMessage('back ' + str(args[0].__speed))
def RightLeft(*args) :
args[0].SendMessage('left ' + str(args[0].__speed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment