Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MAYAからTELLOを操作するスクリプト
# -*- coding: utf-8 -*-
import maya.cmds as cmds
import socket
import sys
import time
class Tello :
def __init__(self) :
# Create Window
if cmds.window("Obj_EditWindow",exists=True):
cmds.deleteUI(Set_Window)
scale=5
Set_Window = cmds.window("Obj_EditWindow", t="TELLO Controller",s=False, w=130*scale, h=50*scale)
form = cmds.formLayout()
LU = cmds.button(label=u"↑", command=self.LeftUp, width=10*scale, height =10*scale)
LR = cmds.button(label=u"→", command=self.LeftRight, width=10*scale, height =10*scale)
LD = cmds.button(label=u"↓", command=self.LeftDown, width=10*scale, height =10*scale)
LL = cmds.button(label=u"←", command=self.LeftLeft, width=10*scale, height =10*scale)
CU = cmds.button(label=u"↑", command=self.CenterUp, width=10*scale, height =10*scale)
CD = cmds.button(label=u"↓", command=self.CenterDown, width=10*scale, height =10*scale)
RU = cmds.button(label=u"↑", command=self.RightUp, width=10*scale, height =10*scale)
RR = cmds.button(label=u"→", command=self.RightRight, width=10*scale, height =10*scale)
RD = cmds.button(label=u"↓", command=self.RightDown, width=10*scale, height =10*scale)
RL = cmds.button(label=u"←", command=self.RightLeft, width=10*scale, height =10*scale)
cmds.formLayout(form, edit=True,\
attachForm=(
(LU, 'top', 10*scale), (LU, 'left', 20*scale), \
(LR, 'top', 20*scale), (LR, 'left', 30*scale), \
(LD, 'top', 30*scale), (LD, 'left', 20*scale), \
(LL, 'top', 20*scale), (LL, 'left', 10*scale), \
(CU, 'top', 20*scale), (CU, 'left', 50*scale), \
(CD, 'top', 20*scale), (CD, 'left', 70*scale), \
(RU, 'top', 10*scale), (RU, 'left', 100*scale), \
(RR, 'top', 20*scale), (RR, 'left', 110*scale), \
(RD, 'top', 30*scale), (RD, 'left', 100*scale), \
(RL, 'top', 20*scale), (RL, 'left', 90*scale)))
cmds.showWindow(Set_Window)
# TELLO move speed
self.__speed = 50
# Network Initialize
self.ConnectUdp()
def __del__(self) :
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)
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
You can’t perform that action at this time.