Skip to content

Commit 176a2d5

Browse files
committed
Serial Reader feels finished
1 parent 97ae5af commit 176a2d5

File tree

4 files changed

+74
-34
lines changed

4 files changed

+74
-34
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CameraReader.py

+11
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
import cv2
2+
3+
4+
class CameraReader:
5+
def __init__(self, output_file):
6+
pass
7+
8+
def start(self):
9+
pass
10+
11+
def stop(self):
12+
pass

SerialReader.py

+36-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# Serial Reader Threaded class
2-
#
3-
#
4-
#
1+
import csv
52
import struct
6-
from multiprocessing import Queue
7-
from threading import Thread
3+
from datetime import datetime
4+
85
from Frame import ShortRangeRadarFrameHeader, Frame, FrameError
6+
from threading import Thread
7+
from multiprocessing import Queue
98
from SerialInterface import SerialInterface
109

1110

@@ -28,14 +27,38 @@ def process_receiving(self):
2827
if frame:
2928
try:
3029
frame = Frame(frame, frame_type=self.interface.frame_type)
31-
pass
30+
31+
for tlv in frame.tlvs:
32+
objs = tlv.objects
33+
34+
if tlv.name == 'DETECTED_POINTS':
35+
self.received_queue.put(objs)
36+
3237
except(KeyError, struct.error, IndexError, FrameError, OverflowError) as e:
3338
print('Exception occurred: ', e)
3439
print('Skipping frame')
3540

3641
def process_storing(self):
37-
while self.running:
38-
pass
42+
# if running or received queue has stuff in it
43+
counter = 1
44+
with open(self.file, 'x+', newline='\n') as csvFile:
45+
writer = csv.writer(csvFile)
46+
writer.writerow(['time', 'frame_number', 'object_number', 'x (m)', 'y(m)', 'z(m)', 'doppler (m/s)'])
47+
48+
while self.running or not self.received_queue.empty():
49+
received_objs = self.received_queue.get()
50+
if received_objs.name == 'DETECTED_POINTS':
51+
inner = 1
52+
for obj in received_objs:
53+
x = obj.x
54+
y = obj.y
55+
z = obj.z
56+
speed = obj.doppler
57+
time_instant = datetime.now().isoformat()
58+
59+
writer.writerow([time_instant, counter, inner, x, y, z, speed])
60+
inner += 1
61+
counter += 1
3962

4063
def send_profile(self, profile_file):
4164
with open(profile_file) as f:
@@ -45,7 +68,10 @@ def send_profile(self, profile_file):
4568
else:
4669
self.interface.send_item(self.interface.control_tx_queue, line)
4770

71+
def start(self):
72+
self.running = True
73+
self.receiving_process.start()
74+
4875
def stop(self):
4976
self.running = False
50-
5177
self.receiving_process.join()

collect_data.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# pseudocode
88
# on launch
9-
# open serial interface + open camera interface in TWO seperate threads
9+
# open serial interface + open camera interface in TWO separate threads
1010
# BUT do NOT start recording
1111
# on gpio rising edge:
1212
# start serial recording
@@ -19,35 +19,31 @@
1919
# save_frame()
2020
# Camera Reader class: launch/open_camera() | process_frame() | close_camera()
2121
# save_frame()
22+
import signal
23+
import time
2224

25+
from SerialReader import SerialReader
26+
from CameraReader import CameraReader
2327

24-
from threading import Thread
25-
import SerialReader
26-
import CameraReader
2728

29+
def interrupt_handler(sig, frame):
30+
global kill
31+
kill = True
32+
stop_watching()
2833

29-
def open_files():
30-
pass
3134

35+
def stop_watching():
36+
camera.stop()
37+
serial.stop()
3238

33-
def watch_camera():
34-
with open('' + args.output_name + '.mp4', mode='wb+') as vid:
35-
# Create an instance of CameraReader and pass the file to it
36-
pass
3739

38-
pass
40+
def start_watching():
41+
global kill
42+
camera.start()
43+
serial.start()
3944

40-
41-
def watch_serial():
42-
with open('' + args.output_name + '.csv', mode='w+') as csv:
43-
# Create an instance of SerialReader and pass the file to it
44-
pass
45-
pass
46-
47-
48-
async def watch():
49-
camera_thread = Thread(target=watch_camera)
50-
serial_thread = Thread(target=watch_serial)
45+
while not kill:
46+
time.sleep(0.5)
5147

5248

5349
if __name__ == '__main__':
@@ -61,4 +57,11 @@ async def watch():
6157
parser.add_argument('--prof', help='Radar Chirp profile to use')
6258
args = parser.parse_args()
6359

64-
await watch()
60+
kill = False
61+
62+
signal.signal(signal.SIGINT, interrupt_handler)
63+
64+
camera = CameraReader(args.output_name + '.mp4')
65+
serial = SerialReader(args.output_name + '.csv', args.control_port, args.data_port)
66+
67+
start_watching()

0 commit comments

Comments
 (0)