-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_actuator.py
38 lines (30 loc) · 1.06 KB
/
my_actuator.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
import time
import donkeycar as dk
class PWMThrottle:
"""
Wrapper over a PWM motor cotnroller to convert -1 to 1 throttle
values to PWM pulses.
"""
MIN_THROTTLE = -1
MAX_THROTTLE = 1
def __init__(self, controller=None,
max_pulse=300,
min_pulse=490,
zero_pulse=350):
self.controller = controller
self.max_pulse = max_pulse
self.min_pulse = min_pulse
self.zero_pulse = zero_pulse
time.sleep(1)
def run(self, throttle):
if throttle > 0:
pulse = dk.utils.map_range(throttle,
0, self.MAX_THROTTLE,
self.zero_pulse, self.max_pulse)
else:
pulse = dk.utils.map_range(throttle,
self.MIN_THROTTLE, 0,
self.min_pulse, self.zero_pulse)
self.controller.set_pulse(pulse)
def shutdown(self):
self.run(self.min_pulse) #stop vehicle