Repository navigation
Expand file tree
/
Copy pathvisualize_sensor.py
More file actions
65 lines (51 loc) · 1.93 KB
/
Copy pathvisualize_sensor.py
File metadata and controls
65 lines (51 loc) · 1.93 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Visualise the Speck sensor output in real time.
Source: Speck Dev Kit Manual 2025.12 V2, section 3.4.
Press ENTER in the terminal to terminate.
"""
import time
import sinabs.backend.dynapcnn.io as sio
devkit = sio.open_device("speck2fdevkit:0")
import samna
samna_graph = samna.graph.EventFilterGraph()
_, _, streamer = samna_graph.sequential(
[
devkit.get_model_source_node(), # Specify the source of events to this graph as the devkit
"Speck2fDvsToVizConverter", # Convert the events to visualizer events
"VizEventStreamer", # Stream events to a visualizer via a streamer node
]
)
visualizer_port = "tcp://0.0.0.0:40001"
# Launch visualizer
gui_process = sio.launch_visualizer(
receiver_endpoint=visualizer_port, disjoint_process=True
)
time.sleep(1.0)
# Visualizer configuration branch of the graph.
visualizer_config, _ = samna_graph.sequential(
[samna.BasicSourceNode_ui_event(), streamer] # For generating UI commands
)
# Connect to the visualizer
streamer.set_streamer_destination(visualizer_port)
if streamer.wait_for_receiver_count() == 0:
raise Exception(f"Connecting to visualizer on {visualizer_port} fails.")
# Specify which plot is to be shown in the visualizer
plot1 = samna.ui.ActivityPlotConfiguration(
image_width=128, image_height=128, title="DVS Layer", layout=[0, 0, 1, 1]
)
visualizer_config.write([samna.ui.VisualizerConfiguration(plots=[plot1])])
time.sleep(1.0)
samna_graph.start()
time.sleep(1.0)
devkit_config = samna.speck2f.configuration.SpeckConfiguration()
# enable monitoring the inputs from the DVS sensor
devkit_config.dvs_layer.raw_monitor_enable = True
# Apply this configuration
devkit.get_model().apply_configuration(devkit_config)
print("Press ENTER to terminate…")
input()
# Stop the graph
samna_graph.stop()
# If we used a sub-process to launch the visualizer, use that to terminate the visualizer.
if gui_process:
gui_process.terminate()
gui_process.join()