forked from Nate711/PupperPythonSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendUDPCommands.py
More file actions
51 lines (41 loc) · 1.81 KB
/
Copy pathsendUDPCommands.py
File metadata and controls
51 lines (41 loc) · 1.81 KB
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
import os
import time
import threading
from UDPComms import Publisher
import signal
drive_pub = Publisher(8870)
# prevents quiting on pi when run through systemd
def handler(signum, frame):
print("GOT singal", signum)
def send_message(message):
while True:
drive_pub.send(message)
signal.signal(signal.SIGHUP, handler)
# those two lines allow for running headless (hopefully)
os.environ["SDL_VIDEODRIVER"] = "dummy"
os.putenv('DISPLAY', ':0.0')
time.sleep(2)
# Prints the values for axis0
msg = {"command": ""}
message_thread = threading.Thread(target=send_message, args=[msg])
message_thread.daemon = True
message_thread.start()
while True:
command = input("Please enter an command (set_velocity, turn_radian, or turn_degrees or break): ")
if command == "set_velocity" or command[:3] == "set":
velocity_x = input("Please enter an x velocity: ")
velocity_y = input("Please enter an y velocity: ")
msg.update({"command": "set_velocity", "velocity_x": float(velocity_x), "velocity_y": float(velocity_y)})
elif command == "turn_radian" or command[:4] == "turn" and "radian" in command:
speed = input("Please enter an turn speed: ")
radians = input("Please enter the number of radians you wish to turn: ")
msg.update({"command": "turn_radians", "speed": float(speed), "radians": float(radians)})
elif command == "turn_degrees" or command[:4] == "turn" and "degrees" in command:
speed = input("Please enter an turn speed: ")
degrees = input("Please enter the number of degrees you wish to turn: ")
msg.update({"command": "turn_radians", "speed": float(speed), "degrees": float(degrees)})
elif command == "break":
break
#msg = {"command": "set_velocity", "velocity_x": 0.1, "velocity_y": 0.0}
print(msg)
#time.sleep(2)