Beispiel #1
0
    def startTele(self):
        # UDP server socket to receive telemetry (tello is broadcasting on a client socket)
        self.tele_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.tele_sock.settimeout(self.tele_timeout)
        self.tele_sock.bind(self.tele_address)

        # thread to read the telemetry socket
        self.tele_thread = threading.Thread(target=self.teleLoop)
        self.tele_thread.start()
        monad.log('telemetry thread started')
Beispiel #2
0
 def __init__(self):
     server = http.server.HTTPServer(self.server_address, self.AjaxServer)
     thread = threading.Thread(target=server.serve_forever)
     thread.daemon = True
     try:
         thread.start()
     except KeyboardInterrupt:
         server.shutdown()
         sys.exit(0)
     monad.log('portal server thread started')
Beispiel #3
0
    def __init__(self):
        self.state = 'asleep'  # awake, shutdown
        self.wakestate = 'sleeping'  # waking, connected, ready, flying
        self.ctrAlive = 0
        self.ctrAwake = 0
        self.ctrLanding = 0
        self.ctrConnectWarning = 0

        thread = threading.Thread(target=self.loop)
        thread.start()
        monad.log('cortex thread started')
Beispiel #4
0
 def sendCommand(self, cmd, wait=False):
     global monad
     rmsg = ''
     try:
         msg = cmd.encode(encoding="utf-8")
         len = self.cmd_sock.sendto(msg, self.cmd_address)
         monad.log(f'command {cmd} sent')
     except Exception as ex:
         monad.log(cmd + ' sendto failed:' + str(ex))
         monad.cortex.command('kill')
     else:
         if wait:
             try:
                 data, server = self.cmd_sock.recvfrom(
                     self.cmd_maxlen)  # blocking
                 print(f'data: {data}')
                 print(f'server: {server}')
                 # why do we get this sometimes
                 # data: b'\xcc\x18\x01\xb9\x88V\x00\xe2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00I\x00\x00\xa7\x0f\x00\x06\x00\x00\x00\x00\x00W\xbe'
                 rmsg = data.decode(encoding='utf-8')
             except Exception as ex:
                 monad.log(cmd + ' recvfrom failed:' + str(ex))
                 monad.cortex.command('kill')
             else:
                 monad.log(cmd + ' : ' + rmsg)
     return rmsg
Beispiel #5
0
 def teleLoop(self):
     global monad
     count = 0
     while True:
         if monad.state == 'shutdown':
             break
             # thread stops on exit from this function
         try:
             data, server = self.tele_sock.recvfrom(self.tele_maxlen)
         except Exception as ex:
             monad.log('Telemetry recvfrom failed: ' + str(ex))
             monad.cortex.command('kill')
             continue
         count += 1
         self.storeTele(data)
         if count % 10 == 0:
             monad.log(data.decode(encoding="utf-8"))
Beispiel #6
0
    def connect(self):  # not used
        monad.log('eyes connecting')
        ret = True
        cmd = 'nmcli dev wifi list --rescan yes'
        try:
            s = subprocess.check_output(cmd, shell=True)
        except:
            pass

        cmd = 'nmcli dev wifi connect TELLO-591FFC'
        try:
            s = subprocess.check_output(cmd, shell=True)
        except:
            ret = False

        monad.log(f'connect to Tello: {ret}')
        return ret
Beispiel #7
0
    def loop(self):
        while True:
            time.sleep(self.interval)
            monad.log('thinking')
            self.ctrAlive += 1
            if self.state == 'shutdown':
                break  # end loop, stop thread
            if self.state == 'awake':
                self.ctrAwake += 1
            viable = self.checkVitals()
            if not viable:
                self.command('kill')
                break

            if self.wakestate == 'waking':
                connected = monad.eyes.checkConnection()
                if connected:
                    self.wakestate = 'connected'
                else:
                    if self.ctrAlive < self.connectTimeout:
                        if self.ctrConnectWarning <= 0:
                            monad.log('not connected.  Please connect now...')
                            self.ctrConnectWarning += 1
                    else:
                        monad.log('not connected timeout.')
                        self.command('kill')

            if self.wakestate == 'connected':
                eyesopen = monad.eyes.open()
                if eyesopen:
                    self.wakestate = 'ready'
                else:
                    monad.log('eyes open failed')
                    self.command('kill')
                #monad.wheels.wake()
        monad.log('exit cortex thread')
Beispiel #8
0
    def open(self):
        # open command socket
        self.startCmd()

        # start tello command processing
        rc = self.sendCommand('command', wait=True)
        if rc != 'ok':
            monad.log('tello command command failed')
            return False

        # start tello streaming, video and telemetry
        rc = self.sendCommand('streamon', wait=True)
        if rc != 'ok':
            monad.log('tello streamon command failed')
            return False

        # open sockets and start threads, to receive video and telemetry
        self.startTele()
        self.startVideo()

        monad.log('eyes connected')
        return True
Beispiel #9
0
 def __init__(self):
     monad.log('wheels object created')
Beispiel #10
0
 def checkVitals(self):
     rc = True
     if self.ctrAlive > self.maxAlive:
         monad.log('maxAlive exceeded')
         rc = False
     if self.state == 'ready' and self.ctrAlive > self.startTimeout:
         monad.log('bored')
         rc = False
     if self.ctrAwake > self.maxAwake:
         monad.log('maxAwake exceeded')
         rc = False
     if monad.eyes.checkBattery() == False:
         monad.log('low battery')
         rc = False
     if monad.eyes.checkTemperature() == False:
         monad.log(f'temp: {monad.telem["temph"]}')
         monad.log('high temperature')
         rc = False
     return rc
Beispiel #11
0
 def __init__(self):
     monad.log('eyes object created')
     self.tele_thread = None
     self.video_thread = None
Beispiel #12
0
 def startCmd(self):
     # UDP client socket to send and receive commands
     self.cmd_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     self.cmd_sock.settimeout(self.cmd_timeout)
     monad.log('cmd socket open')
Beispiel #13
0
 def startVideo(self):
     self.video_thread = threading.Thread(target=self.videoLoop)
     self.video_thread.start()
     monad.log('video thread started')