-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathlaunch.py
More file actions
48 lines (39 loc) · 1.44 KB
/
launch.py
File metadata and controls
48 lines (39 loc) · 1.44 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
import time
class AiLaunch():
'''
This part will apply a large thrust on initial activation. This is to help
in racing to start fast and then the ai will take over quickly when it's
up to speed.
'''
def __init__(self, launch_duration=1.0, launch_throttle=1.0, keep_enabled=False):
self.active = False
self.enabled = False
self.timer_start = None
self.timer_duration = launch_duration
self.launch_throttle = launch_throttle
self.prev_mode = None
self.trigger_on_switch = keep_enabled
def enable_ai_launch(self):
self.enabled = True
print('AiLauncher is enabled.')
def run(self, mode, ai_throttle):
new_throttle = ai_throttle
if mode != self.prev_mode:
self.prev_mode = mode
if mode == "local" and self.trigger_on_switch:
self.enabled = True
if mode == "local" and self.enabled:
if not self.active:
self.active = True
self.timer_start = time.time()
else:
duration = time.time() - self.timer_start
if duration > self.timer_duration:
self.active = False
self.enabled = False
else:
self.active = False
if self.active:
print('AiLauncher is active!!!')
new_throttle = self.launch_throttle
return new_throttle