This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanual_override.py
74 lines (58 loc) · 2 KB
/
manual_override.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import getopt
import RTIMU
import os.path
import time
import math
import logging
import socket
import threading
class ManualOverride (threading.Thread):
# Manual override control
MANUAL_OVERRIDE_BUFFER_SIZE = 1024
MANUAL_OVERRIDE_LISTENING_IP = "0.0.0.0"
MANUAL_OVERRIDE_LISTENING_PORT = 5050
def __init__(self):
threading.Thread.__init__(self)
self.manual_override_socket = None
self.overriden = False
self.yaw_servo_pwm = 614
self.pitch_servo_pwm = 614
self.kill = False
self.latency = 0
self.ready = False
try:
self.manual_override_socket = socket.socket(
socket.AF_INET, socket.SOCK_DGRAM)
self.manual_override_socket.bind(
(self.MANUAL_OVERRIDE_LISTENING_IP, self.MANUAL_OVERRIDE_LISTENING_PORT))
self.ready = True
except IOError:
logging.warning(
"Cannot establish connection with external controller")
if self.ready:
logging.info(
"Connection with external controller succesfull. Manual override is now possible")
else:
logging.error(
"Can't establish connection. Please check if the external controller is sending data")
def run(self):
try:
while True:
t0 = time.time()
self.data, addr = self.manual_override_socket.recvfrom(
self.MANUAL_OVERRIDE_BUFFER_SIZE)
manual_override_json = json.loads(self.data)
print(self.data)
t1 = time.time()
self.latency = (t1 - t0) * 1000
self.pitch_servo_pwm = 614
self.yaw_servo_pwm = 614
if self.kill:
logging.info("Closing Manual Override")
break
except KeyboardInterrupt:
pass
def close(self):
""" Trigger thread closure """
self.kill = True