-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharduino.py
32 lines (25 loc) · 861 Bytes
/
arduino.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
#from vjoy import vj, setJoy
import serial
import time
from threading import Thread
PWM_CENTER = 1487 # PWM center time
PWM_SCALE = 420.0 # PWM time range
EASE = 0.3 # Range limit for finer control
class ArduinoController(Thread):
def __init__(self):
Thread.__init__(self)
self.alive = True
self.serial = None
try:
self.serial = serial.Serial("COM3")
except serial.serialutil.SerialException:
print("Arduino not found!")
self.alive = False
# publicly accessible steering value
self.steering = 0.0
def stop(self):
self.alive = False
def run(self):
while self.alive:
pwm = int(self.serial.readline().decode("ansi"))
self.steering = ((PWM_CENTER - pwm) / PWM_SCALE) * EASE