- Joined
- Feb 7, 2020
- Messages
- 4
- Reaction score
- 0
I am new in tello and in python also.
I am trying to programm a software to command and fly tello over my computer.
I send 'command' over the socket when i inititalize the tello.py and then i dont send it any more. The dronne only takes of and lands when i press the button i programmed. But i think the dronne dosnt listen to the othe commands for moving it as it should.
I am wandering if i have to send allways the command 'command' before i send anything else for ex. like 'up x'
Here is the code:
>> tello.py
class Tello:
localIP = ''"
localPort = 8890
local_video_port = 11111
localAddr = (localIP, localPort)
telloIP = '192.168.10.1'
telloUDPPort = 8889
sock = None
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.telloAddress = (self.telloIP, self.telloUDPPort)
self.sock.bind(self.localAddr)
self.telCommand()
logging.basicConfig(level=logging.INFO)
self.video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.video_socket.bind((self.localIP, self.local_video_port))
loggingThread = threading.Thread(target=self.loging, args=())
loggingThread.daemon = True # Daemonize loggingThread
loggingThread.start() # Start the execution
def telCommand(self):
self.sock.sendto("command".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello command")
# Takeoff
def telTakeoff(self):
self.sock.sendto("takeoff".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello takeoff")
# Rotate clockwise
def telRotateCw(self, degrees):
self.sock.sendto(("cw %s" % degrees).encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello rotate cw %s" % degrees)
# Rotate reverse clockwise 360
def telRotateCcw(self, degrees):
self.sock.sendto(("ccw %s" % degrees).encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello rotate ccw %s" % degrees)
# Land
def telLand(self):
self.sock.sendto("land".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello land")
# streamon
def telStreamon(self):
self.sock.sendto("streamon".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello streamon")
# streamoff
def telStreamoff(self):
self.sock.sendto("streamoff".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello streamoff")
.
.
.
>> ui_control.py
...
...
class Form(QWidget):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
# controlling vars
self.distance = 5
self.degree = 30
self.stream = 0
self.drone = Tello()
.
.
.
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_W:
self.drone.telMove(direction=dir.UP, distance=self.distance)
if key == Qt.Key_S:
self.drone.telMove(direction=dir.DOWN, distance=self.distance)
if key == Qt.Key_A:
self.drone.telRotateCcw(self.degree)
if key == Qt.Key_D:
self.drone.telRotateCw(self.degree)
if key == Qt.Key_Space:
self.drone.telLand()
if key == Qt.Key_Escape:
self.drone.telEmergency()
if key == Qt.Key_Return:
self.drone.telTakeoff()
if key == Qt.Key_Up:
self.drone.telMove(direction=dir.FORWARD, distance=self.distance)
if key == Qt.Key_Down:
self.drone.telMove(direction=dir.BACK, distance=self.distance)
if key == Qt.Key_Left:
self.drone.telMove(direction=dir.LEFT, distance=self.distance)
if key == Qt.Key_Right:
self.drone.telMove(direction=dir.RIGHT, distance=self.distance)
print('Key Press Event fired %s' % (event.key()))
def streamVideo(self):
if self.stream == 0:
self.drone.telStreamon()
print("[ui]streaming video..")
self.b_streamVideo.setText("stop streaming")
self.stream = 1
else:
self.drone.telStreamoff()
print("[ui]stop streaming")
self.b_streamVideo.setText("start streaming")
self.stream = 0
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())
I am trying to programm a software to command and fly tello over my computer.
I send 'command' over the socket when i inititalize the tello.py and then i dont send it any more. The dronne only takes of and lands when i press the button i programmed. But i think the dronne dosnt listen to the othe commands for moving it as it should.
I am wandering if i have to send allways the command 'command' before i send anything else for ex. like 'up x'
Here is the code:
>> tello.py
class Tello:
localIP = ''"
localPort = 8890
local_video_port = 11111
localAddr = (localIP, localPort)
telloIP = '192.168.10.1'
telloUDPPort = 8889
sock = None
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.telloAddress = (self.telloIP, self.telloUDPPort)
self.sock.bind(self.localAddr)
self.telCommand()
logging.basicConfig(level=logging.INFO)
self.video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.video_socket.bind((self.localIP, self.local_video_port))
loggingThread = threading.Thread(target=self.loging, args=())
loggingThread.daemon = True # Daemonize loggingThread
loggingThread.start() # Start the execution
def telCommand(self):
self.sock.sendto("command".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello command")
# Takeoff
def telTakeoff(self):
self.sock.sendto("takeoff".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello takeoff")
# Rotate clockwise
def telRotateCw(self, degrees):
self.sock.sendto(("cw %s" % degrees).encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello rotate cw %s" % degrees)
# Rotate reverse clockwise 360
def telRotateCcw(self, degrees):
self.sock.sendto(("ccw %s" % degrees).encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello rotate ccw %s" % degrees)
# Land
def telLand(self):
self.sock.sendto("land".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello land")
# streamon
def telStreamon(self):
self.sock.sendto("streamon".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello streamon")
# streamoff
def telStreamoff(self):
self.sock.sendto("streamoff".encode(encoding="utf-8"), self.telloAddress)
print("[tello] tello streamoff")
.
.
.
>> ui_control.py
...
...
class Form(QWidget):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
# controlling vars
self.distance = 5
self.degree = 30
self.stream = 0
self.drone = Tello()
.
.
.
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_W:
self.drone.telMove(direction=dir.UP, distance=self.distance)
if key == Qt.Key_S:
self.drone.telMove(direction=dir.DOWN, distance=self.distance)
if key == Qt.Key_A:
self.drone.telRotateCcw(self.degree)
if key == Qt.Key_D:
self.drone.telRotateCw(self.degree)
if key == Qt.Key_Space:
self.drone.telLand()
if key == Qt.Key_Escape:
self.drone.telEmergency()
if key == Qt.Key_Return:
self.drone.telTakeoff()
if key == Qt.Key_Up:
self.drone.telMove(direction=dir.FORWARD, distance=self.distance)
if key == Qt.Key_Down:
self.drone.telMove(direction=dir.BACK, distance=self.distance)
if key == Qt.Key_Left:
self.drone.telMove(direction=dir.LEFT, distance=self.distance)
if key == Qt.Key_Right:
self.drone.telMove(direction=dir.RIGHT, distance=self.distance)
print('Key Press Event fired %s' % (event.key()))
def streamVideo(self):
if self.stream == 0:
self.drone.telStreamon()
print("[ui]streaming video..")
self.b_streamVideo.setText("stop streaming")
self.stream = 1
else:
self.drone.telStreamoff()
print("[ui]stop streaming")
self.b_streamVideo.setText("start streaming")
self.stream = 0
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())