Skip to content

Instantly share code, notes, and snippets.

@HiromuKato
Created December 17, 2018 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HiromuKato/f34a83605723f2b73ae91278110e66a6 to your computer and use it in GitHub Desktop.
Save HiromuKato/f34a83605723f2b73ae91278110e66a6 to your computer and use it in GitHub Desktop.
3DS MAXからTELLOを操作するスクリプト
from PySide2 import QtWidgets
import MaxPlus
import socket
class Tello(QtWidgets.QDialog):
def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
super(Tello, self).__init__(parent)
self.setWindowTitle("Tello Controller")
self.initUI()
# TELLO move speed
self.__speed = 50
# Network Initialize
self.ConnectUdp()
MaxPlus.CUI.DisableAccelerators()
def initUI(self):
scale = 5
width = 10*scale
height = 10*scale
# Left
LU = QtWidgets.QPushButton("↑", self)
LU.setGeometry(20*scale, 10*scale, width, height)
LU.clicked.connect(self.LeftUp)
LR = QtWidgets.QPushButton("→", self)
LR.setGeometry(30*scale, 20*scale, width, height)
LR.clicked.connect(self.LeftRight)
LD = QtWidgets.QPushButton("↓", self)
LD.setGeometry(20*scale, 30*scale, width, height)
LD.clicked.connect(self.LeftDown)
LL = QtWidgets.QPushButton("←", self)
LL.setGeometry(10*scale, 20*scale, width, height)
LL.clicked.connect(self.LeftLeft)
# Center
CU = QtWidgets.QPushButton("↑", self)
CU.setGeometry(50*scale, 20*scale, width, height)
CU.clicked.connect(self.CenterUp)
CD = QtWidgets.QPushButton("↓", self)
CD.setGeometry(70*scale, 20*scale, width, height)
CD.clicked.connect(self.CenterDown)
# Right
RU = QtWidgets.QPushButton("↑", self)
RU.setGeometry(100*scale, 10*scale, width, height)
RU.clicked.connect(self.RightUp)
RR = QtWidgets.QPushButton("→", self)
RR.setGeometry(110*scale, 20*scale, width, height)
RR.clicked.connect(self.RightRight)
RD = QtWidgets.QPushButton("↓", self)
RD.setGeometry(100*scale, 30*scale, width, height)
RD.clicked.connect(self.RightDown)
RL = QtWidgets.QPushButton("←", self)
RL.setGeometry(90*scale, 20*scale, width, height)
RL.clicked.connect(self.RightLeft)
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)
#self.__sock.bind(locaddr)
try:
self.__sock.bind(locaddr)
except:
self.__sock.close()
#self.__sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
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))
if __name__ == "__main__":
try:
ui.close()
except:
pass
ui = Tello()
ui.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment