-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-command.py
58 lines (48 loc) · 1.69 KB
/
main-command.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
## Partial Credits: https://www.youtube.com/watch?v=rHY3T7-vK38
import socket
import threading
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tello_address = ('192.168.10.1', 8889)
sock.bind(('', 9000))
def get_current_yaw():
"""Reads the yaw value from the shared file."""
try:
with open("yaw_data.txt", "r") as file:
return int(file.read().strip())
except (FileNotFoundError, ValueError):
print("Yaw data not available")
return 0 # Default to 0 if file is missing or unreadable
def reset_yaw():
"""Adjusts yaw by 30 degrees in the appropriate direction."""
target_yaw = 19
adjustment_amount = 30 # Fixed adjustment in degrees
# Get the current yaw from the file
current_yaw = get_current_yaw()
if current_yaw < target_yaw:
# If yaw is negative, rotate clockwise by 30 degrees
print(f"Rotating clockwise by {adjustment_amount} degrees")
send_command(f'cw {adjustment_amount}')
elif current_yaw > target_yaw:
# If yaw is positive, rotate counterclockwise by 30 degrees
print(f"Rotating counterclockwise by {adjustment_amount} degrees")
send_command(f'ccw {adjustment_amount}')
else:
print("Yaw is already close to zero, no adjustment needed.")
while True:
try:
msg = input('')
if not msg:
break
if 'reset' in msg:
reset_yaw()
if 'end' in msg:
sock.close()
break
msg = msg.encode()
print(f"Sending message: {msg}")
sent = sock.sendto(msg, tello_address)
except Exception as e:
print(f"Error: {e}")
sock.close()
break