-
Notifications
You must be signed in to change notification settings - Fork 1
/
DrivingRecorder.py
68 lines (55 loc) · 2.8 KB
/
DrivingRecorder.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'''
This is meant to generate data for ML training
It will:
* Send out requests for data from the car over CAN bus (using an M2 connected via serial)
* Recieve the data back from the CAN bus
* Filter out unwanted data
* Save data by the epoch at which it happened, down to the mili-second
* * The macchina M2 sends time back in micro-seconds
* Capture a frame from a camera at 5 Hz
'''
from SerialCANBus import SerialCANBus
from RecordWebcam import RecordWebCam
import time
import datetime
import sys
import os
# Settings:
printEvery = 0.5 # seconds
outDir = "/home/neil/car/DrivingData/"
dateString = datetime.datetime.now().replace(microsecond=0).isoformat()
CANDataFile = os.path.join(outDir,dateString,"CANData.csv")
imageDir = os.path.join(outDir,dateString,"imgs")
dataRequestMaxFrequency = 0.05 # seconds
writeFrequency = 100 #number of packets to build up before saving to disk
captureFrequency = 5.0 # Hz
camId = 1
showImages = True
CANData = [{"id":b'\x30\x07\x00\x00',"responseId":b'\x38\x07\x00\x00','data':b'\x03\x22\x33\x02\x00\x00\x00\x00'}, # steering angle
{"id":b'\x30\x07\x00\x00',"responseId":b'\x38\x07\x00\x00','data':b'\x03\x22\x33\x0B\x00\x00\x00\x00'}, # steering torque
{"id":b'\x30\x07\x00\x00',"responseId":b'\x38\x07\x00\x00','data':b'\x03\x22\x33\x01\x00\x00\x00\x00'}, # steering speed
{"id":b'\xE0\x07\x00\x00',"responseId":b'\xE8\x07\x00\x00','data':b'\x03\x22\xF4\x45\x00\x00\x00\x00'}, # throttle position
{"id":b'\x60\x07\x00\x00',"responseId":b'\x68\x07\x00\x00','data':b'\x03\x22\x2B\x0D\x00\x00\x00\x00'}, # brake pressure
{"id":b'\x31\x07\x00\x00',"responseId":b'\x39\x07\x00\x00','data':b'\x03\x22\xD9\x80\x00\x00\x00\x00'}, # turn signal
{"id":b'\xE0\x07\x00\x00',"responseId":b'\xE8\x07\x00\x00','data':b'\x03\x22\xF4\x0D\x00\x00\x00\x00'}, # vehicle speed
{"id":b'\xE0\x07\x00\x00',"responseId":b'\xE8\x07\x00\x00','data':b'\x03\x22\x03\x2B\x00\x00\x00\x00'}] # accelerator position
#CANData= []
# initalize objects:
carData = SerialCANBus(CANDataFile,CANData=CANData,dataRequestMaxFrequency=dataRequestMaxFrequency,writeFrequency=writeFrequency,hexExplicit=False)
imageRecorder = RecordWebCam(imageDir,captureFrequency=captureFrequency,camId=camId,show=showImages)
lastPrint = 0
startTime = time.time()
try:
while True:
time.sleep(.02)
currentTime = time.time()
if currentTime - printEvery > lastPrint:
lastPrint = currentTime
print("\rRecording data at {:.3f} Elapsed Time: {:.1f} minutes".format(currentTime,(currentTime-startTime)/60),end="")
carData()
imageRecorder()
except(KeyboardInterrupt,SystemExit):
print("\nShutting down by user request...")
carData.saveParsedData()
imageRecorder.shutDown()
print("Exiting!")