forked from augcog/ROAR_Jetson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsender.py
More file actions
23 lines (18 loc) · 706 Bytes
/
sender.py
File metadata and controls
23 lines (18 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import serial
MOTOR_MAX = 1750;
MOTOR_MIN = 800;
MOTOR_NEUTRAL = 1500;
THETA_MAX = 3000;
THETA_MIN = 0;
class Sender:
def __init__(self):
self.ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
def update(self):
pass
def run_threaded(self, throttle, steering, **args):
if throttle >= 0:
throttle_send = int(MOTOR_NEUTRAL + (MOTOR_MAX - MOTOR_NEUTRAL) * throttle + 0.5)
else:
throttle_send = int(MOTOR_NEUTRAL + (MOTOR_NEUTRAL - MOTOR_MIN) * throttle + 0.5)
steering_send = int(THETA_MIN + (steering / 2 + 0.5) * (THETA_MAX - THETA_MIN) + 0.5)
self.ser.write('{} {}\n'.format(throttle_send, steering_send).encode())