-
Notifications
You must be signed in to change notification settings - Fork 5
/
recording_car.py
45 lines (38 loc) · 1.36 KB
/
recording_car.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
38
39
40
41
42
43
44
45
import datetime
import numpy as np
import car_config
import parts
my_car = car_config.my_car()
bluepill = parts.BluePill(**car_config.bluepill_configs[my_car])
timer = parts.Timer(frequency=20)
cam = parts.PiCamera()
web_status = parts.WebStatus()
# add tub to save data
inputs = ['user_angle', 'user_throttle', 'distance', 'image_array', 'timestamp']
types = ['float', 'float', 'float', 'image_array', 'str']
# single tub
tub = parts.TubWriter(path='./recording_car_tub', inputs=inputs, types=types)
is_recording = False
try:
print("Car loop started. Start driving to record.")
while True:
timer.tick()
timestamp = str(datetime.datetime.utcnow())
car_status = bluepill.get_status()
if not is_recording and car_status.user_throttle > 0.1:
is_recording = True
print(timestamp, "Recording enabled")
elif is_recording and car_status.user_throttle < -0.2:
is_recording = False
print(timestamp, "Recording disabled")
img = cam.get_image()
web_status.set_image(img)
web_status.set_car_status(car_status)
if is_recording:
tub.write(car_status.user_angle,
car_status.user_throttle,
car_status.distance,
img,
timestamp)
finally:
bluepill.stop_and_disengage_autonomy()