YangLiu1021 commited on
Commit
394909b
·
1 Parent(s): c5a664b

Update Foxglove visualization example

Browse files
README.md CHANGED
@@ -90,8 +90,8 @@ metadata/tof_sensor.yaml # TOFSense-M cascade metadata
90
  quality/reports/ # generated quality reports
91
  calibration/robot_v1_template/ # calibration files
92
  docs/foxglove_visualization.md # Foxglove visualization guide
93
- scripts/foxglove_visualization_bridge.py # compact visualization bag builder
94
- examples/foxglove/run029_full_tof_odom_foxglove.bag # ready-to-open Foxglove example
95
  ```
96
 
97
  ## Sensor Coverage
@@ -141,7 +141,7 @@ examples/foxglove/run029_full_tof_odom_foxglove.bag # ready-to-open Foxglove ex
141
 
142
  ## Foxglove Visualization
143
 
144
- `scripts/foxglove_visualization_bridge.py` creates compact visualization-only bags. By default it keeps ToF/IMU/odometry/TF-static topics, writes a 15 Hz compressed TOFSense-M overview image with distance values, `dis_status`, and `signal_strength`, and injects dynamic TF from odometry. Use `--copy-mode custom --keep-topics ...` to choose exactly which original topics are retained. A ready-to-open example is available at `examples/foxglove/run029_full_tof_odom_foxglove.bag`. See `docs/foxglove_visualization.md`.
145
 
146
  ## Limitations
147
 
 
90
  quality/reports/ # generated quality reports
91
  calibration/robot_v1_template/ # calibration files
92
  docs/foxglove_visualization.md # Foxglove visualization guide
93
+ scripts/foxglove_visual.py # Foxglove visualization bag builder
94
+ examples/foxglove/visual_demo.bag # ready-to-open Foxglove example
95
  ```
96
 
97
  ## Sensor Coverage
 
141
 
142
  ## Foxglove Visualization
143
 
144
+ `scripts/foxglove_visual.py` creates Foxglove-ready visualization bags with compressed TOFSense-M overview images, optional RGB topics, standard `sensor_msgs/PointCloud2` output at `/foxglove/livox/points`, accumulated `nav_msgs/Path` output at `/foxglove/odom/path`, MAVROS IMU topics, and odometry TF. In Foxglove, use `Fixed frame = odom` and `Display frame = odom` for the 3D panel. A ready-to-open example is available at `examples/foxglove/visual_demo.bag`. See `docs/foxglove_visualization.md`.
145
 
146
  ## Limitations
147
 
calibration/robot_v1_template/README.md CHANGED
@@ -2,6 +2,17 @@
2
 
3
  This directory stores the calibration files published with the dataset.
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  ## Files
6
 
7
  - `tf_static.yaml`: consolidated static frame tree.
 
2
 
3
  This directory stores the calibration files published with the dataset.
4
 
5
+ ## Hardware
6
+
7
+ | Modality | Hardware |
8
+ | --- | --- |
9
+ | Flight controller | MicoAir / 微空 NxtPX4V2, label model `NXTPX4V2` |
10
+ | Flight-controller IMU | Bosch Sensortec BMI088 x2 |
11
+ | LiDAR | Livox MID360s |
12
+ | LiDAR IMU | Livox MID360s integrated IMU |
13
+ | Camera | Intel RealSense D435i |
14
+ | ToF | Nooploop TOFSense-M six-node cascade |
15
+
16
  ## Files
17
 
18
  - `tf_static.yaml`: consolidated static frame tree.
calibration/robot_v1_template/camera_color.yaml CHANGED
@@ -1,4 +1,6 @@
1
  camera_name: camera_color
 
 
2
  topic: /camera/color/image_raw
3
  camera_info_topic: /camera/color/camera_info
4
  frame_id: camera_color_optical_frame
 
1
  camera_name: camera_color
2
+ manufacturer: Intel RealSense
3
+ model: D435i
4
  topic: /camera/color/image_raw
5
  camera_info_topic: /camera/color/camera_info
6
  frame_id: camera_color_optical_frame
calibration/robot_v1_template/camera_depth.yaml CHANGED
@@ -1,4 +1,6 @@
1
  camera_name: camera_depth
 
 
2
  topic: /camera/depth/image_rect_raw
3
  camera_info_topic: /camera/depth/camera_info
4
  frame_id: camera_depth_optical_frame
 
1
  camera_name: camera_depth
2
+ manufacturer: Intel RealSense
3
+ model: D435i
4
  topic: /camera/depth/image_rect_raw
5
  camera_info_topic: /camera/depth/camera_info
6
  frame_id: camera_depth_optical_frame
calibration/robot_v1_template/camera_infra1.yaml CHANGED
@@ -1,4 +1,6 @@
1
  camera_name: camera_infra1
 
 
2
  topic: /camera/infra1/image_rect_raw
3
  camera_info_topic: /camera/infra1/camera_info
4
  frame_id: camera_infra1_optical_frame
 
1
  camera_name: camera_infra1
2
+ manufacturer: Intel RealSense
3
+ model: D435i
4
  topic: /camera/infra1/image_rect_raw
5
  camera_info_topic: /camera/infra1/camera_info
6
  frame_id: camera_infra1_optical_frame
calibration/robot_v1_template/camera_infra2.yaml CHANGED
@@ -1,4 +1,6 @@
1
  camera_name: camera_infra2
 
 
2
  topic: /camera/infra2/image_rect_raw
3
  camera_info_topic: /camera/infra2/camera_info
4
  frame_id: camera_infra2_optical_frame
 
1
  camera_name: camera_infra2
2
+ manufacturer: Intel RealSense
3
+ model: D435i
4
  topic: /camera/infra2/image_rect_raw
5
  camera_info_topic: /camera/infra2/camera_info
6
  frame_id: camera_infra2_optical_frame
calibration/robot_v1_template/imu_to_base.yaml CHANGED
@@ -1,4 +1,14 @@
1
  sensor: mavros_imu
 
 
 
 
 
 
 
 
 
 
2
  topic: /mavros/imu/data
3
  parent_frame: base_link
4
  child_frame: mavros_imu_frame
 
1
  sensor: mavros_imu
2
+ source_hardware:
3
+ flight_controller:
4
+ manufacturer: MicoAir
5
+ manufacturer_cn: 微空
6
+ model: NxtPX4V2
7
+ label_model: NXTPX4V2
8
+ imu:
9
+ manufacturer: Bosch Sensortec
10
+ model: BMI088
11
+ count: 2
12
  topic: /mavros/imu/data
13
  parent_frame: base_link
14
  child_frame: mavros_imu_frame
calibration/robot_v1_template/livox_to_base.yaml CHANGED
@@ -1,5 +1,9 @@
1
  sensor: livox_mid360
 
 
 
2
  topic: /livox/lidar
 
3
  parent_frame: base_link
4
  child_frame: livox_frame
5
  translation_xyz_m: [0.0, 0.0, 0.0]
 
1
  sensor: livox_mid360
2
+ manufacturer: Livox
3
+ model: MID360s
4
+ sensor_type: lidar_with_integrated_imu
5
  topic: /livox/lidar
6
+ imu_topic: /livox/imu
7
  parent_frame: base_link
8
  child_frame: livox_frame
9
  translation_xyz_m: [0.0, 0.0, 0.0]
dataset.yaml CHANGED
@@ -32,6 +32,7 @@ default_topics:
32
 
33
  sensor_metadata:
34
  tof: metadata/tof_sensor.yaml
 
35
 
36
  quality_status:
37
  - unchecked
 
32
 
33
  sensor_metadata:
34
  tof: metadata/tof_sensor.yaml
35
+ sensors: metadata/sensors.yaml
36
 
37
  quality_status:
38
  - unchecked
docs/foxglove_visualization.md CHANGED
@@ -1,172 +1,230 @@
1
- # Foxglove Visualization Bag
2
 
3
- Use `scripts/foxglove_visualization_bridge.py` to create a small visualization-only rosbag from a raw dataset bag.
4
 
5
- The raw bag remains the source of truth. Do not replace raw bags with generated visualization bags.
6
 
7
- ## Why the Old Script Made Huge Bags
8
 
9
- The previous script did three expensive things at the same time:
10
 
11
- 1. It copied every original topic by default, including large camera and lidar topics.
12
- 2. It wrote one raw RGB `sensor_msgs/Image` overview plus six raw RGB node images for each ToF message.
13
- 3. It wrote those images at the full ToF rate.
14
 
15
- That is the bad data structure. A visualization bag should not be a second full dataset plus uncompressed debug images.
 
 
 
 
 
 
 
 
16
 
17
- ## Compact Default
18
 
19
- The repository script changes the default:
20
 
21
- | Item | Default |
22
  | --- | --- |
23
- | Original topics | Compact ToF, IMU, odometry, and `/tf_static` only |
24
- | ToF image output | Overview image only |
25
- | ToF image format | `sensor_msgs/CompressedImage` JPEG |
26
- | ToF image rate | 15 Hz |
27
- | ToF image content | Distance values, `dis_status`, and `signal_strength` tables |
28
- | Dynamic TF | Injected from odometry at 10 Hz |
29
- | Output bag compression | `bz2` |
 
30
 
31
- The original `/nlink_tofsensem_cascade` topic is still copied in compact mode, so the numeric ToF data remains complete. The generated heatmap is compressed JPEG and can be rate-limited independently.
32
 
33
- ## Hugging Face Example Bag
 
 
 
34
 
35
- The Hugging Face dataset includes a ready-to-open Foxglove example:
36
 
37
  ```text
38
- examples/foxglove/run029_full_tof_odom_foxglove.bag
 
 
39
  ```
40
 
41
- It is generated from `odom_dataset_20260520_030414.bag` / session `2026-05-20_030414_odom_run029`.
42
 
43
- | Item | Value |
44
- | --- | --- |
45
- | Source duration | 409 s |
46
- | Example bag size | About 886 MB |
47
- | ToF raw messages | 6138 |
48
- | ToF overview images | 4047 |
49
- | Image topic | `/foxglove/tof/overview/compressed` |
50
- | Image size | 1794 x 878 |
51
 
52
- ## Generate A Bag
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- Run inside a ROS1 environment that can import this dataset's custom message types:
55
 
56
- ```bash
57
- python3 scripts/foxglove_visualization_bridge.py \
58
- --input-bag raw/sessions/2026-05-20_030414_odom_run029/bag.bag \
59
- --output-bag /tmp/run029_full_tof_odom_foxglove.bag \
60
- --force
 
61
  ```
62
 
63
- Open the output bag in Foxglove.
 
 
 
 
 
 
64
 
65
- Useful topics:
66
 
67
- | Topic | Purpose |
 
 
 
 
 
 
 
 
 
 
68
  | --- | --- |
69
- | `/foxglove/tof/overview/compressed` | Six-node TOFSense-M cascade heatmap |
70
- | `/tf` | Injected `map -> base_link` transform from odometry |
71
- | `/fusion_odometry/current_point_odom` | Primary odometry |
72
- | `/ekf_quat/ekf_odom` | EKF odometry when present |
73
- | `/mavros/imu/data` | IMU |
74
- | `/nlink_tofsensem_cascade` | Original ToF cascade message |
75
 
76
- ## Time Windows
77
 
78
- Use a time window when the raw bag is large and you only need a representative segment:
79
 
80
- ```bash
81
- python3 scripts/foxglove_visualization_bridge.py \
82
- --input-bag raw/sessions/2026-05-20_030414_odom_run029/bag.bag \
83
- --start-offset-sec 189.891 \
84
- --duration-sec 30 \
85
- --output-bag /tmp/run029_mid30s_tof_odom_foxglove.bag \
86
- --force
 
 
 
87
  ```
88
 
89
- The script also copies `/tf_static` into the window so Foxglove can resolve static frames in the clipped bag.
90
 
91
- ## Smaller Or Larger Outputs
 
 
92
 
93
- Only generated visualization topics:
94
 
95
- ```bash
96
- python3 scripts/foxglove_visualization_bridge.py \
97
- --input-bag raw/sessions/2026-05-13_024746_odom_run001/bag.bag \
98
- --copy-mode none \
99
- --output-bag /tmp/tof_odom_view_only.bag \
100
- --force
101
  ```
102
 
103
- Include per-node ToF images:
104
 
105
- ```bash
106
- python3 scripts/foxglove_visualization_bridge.py \
107
- --input-bag raw/sessions/2026-05-13_024746_odom_run001/bag.bag \
108
- --tof-image-mode both \
109
- --tof-rate-hz 15 \
110
- --output-bag /tmp/tof_nodes_view.bag \
111
- --force
 
112
  ```
113
 
114
- Write every ToF heatmap frame without throttling:
115
 
116
- ```bash
117
- python3 scripts/foxglove_visualization_bridge.py \
118
- --input-bag raw/sessions/2026-05-13_024746_odom_run001/bag.bag \
119
- --tof-rate-hz 0 \
120
- --output-bag /tmp/tof_full_rate_view.bag \
121
- --force
122
  ```
123
 
124
- Keep exactly the original topics you choose:
 
 
 
 
125
 
126
  ```bash
127
- python3 scripts/foxglove_visualization_bridge.py \
128
- --input-bag raw/sessions/2026-05-13_024746_odom_run001/bag.bag \
129
- --copy-mode custom \
130
- --keep-topics /tf_static,/mavros/imu/data,/nlink_tofsensem_cascade,/fusion_odometry/current_point_odom \
131
- --output-bag /tmp/custom_topics_view.bag \
132
- --force
133
  ```
134
 
135
- Hide the ToF numeric overlays when you need a smaller visualization bag:
136
 
137
  ```bash
138
- python3 scripts/foxglove_visualization_bridge.py \
139
  --input-bag raw/sessions/2026-05-20_030414_odom_run029/bag.bag \
140
- --tof-hide-distance-text \
141
- --tof-hide-tables \
142
- --output-bag /tmp/tof_heatmap_only.bag \
143
- --force
 
 
 
 
 
144
  ```
145
 
146
- Copy every original topic only when you really need it:
147
 
148
  ```bash
149
- python3 scripts/foxglove_visualization_bridge.py \
150
- --input-bag raw/sessions/2026-05-13_024746_odom_run001/bag.bag \
151
- --copy-mode all \
152
- --tof-rate-hz 1 \
153
- --output-bag /tmp/full_plus_foxglove.bag \
154
- --force
 
 
 
155
  ```
156
 
157
- `--copy-mode all` can still produce a large bag. That is expected.
158
-
159
- ## Foxglove Panel Setup
160
 
161
- Use an Image panel for `/foxglove/tof/overview/compressed`. The image contains six TOFSense-M nodes. Each node shows distance in millimeters, `dis_status`, and `signal_strength`.
162
-
163
- Use a 3D panel with:
164
-
165
- | Setting | Value |
 
 
 
 
 
 
 
 
 
 
 
 
166
  | --- | --- |
167
- | Fixed frame | `map` |
168
- | Dynamic frame | `base_link` |
169
- | Odometry | `/fusion_odometry/current_point_odom` or `/ekf_quat/ekf_odom` |
170
- | TF | `/tf` and `/tf_static` |
 
 
171
 
172
- If the trajectory looks wrong, first check the odometry topic and frame names. Do not patch the visualization bag until the source frame convention is clear.
 
 
 
 
 
1
+ # Foxglove Visualization
2
 
3
+ Language: English | [简体中文](foxglove_visualization.zh-CN.md)
4
 
5
+ This guide shows how to inspect the dataset in Foxglove with ToF heatmaps, RGB images, LiDAR point clouds, MAVROS IMU curves, and 3D odometry.
6
 
7
+ The raw rosbag remains the source data. The Foxglove bag is a visualization artifact generated with `scripts/foxglove_visual.py`.
8
 
9
+ ## Ready-To-Open Example
10
 
11
+ The Hugging Face dataset includes a Foxglove example:
 
 
12
 
13
+ ```text
14
+ examples/foxglove/visual_demo.bag
15
+ ```
16
+
17
+ It is generated from session:
18
+
19
+ ```text
20
+ raw/sessions/2026-05-20_030414_odom_run029/bag.bag
21
+ ```
22
 
23
+ Open the example bag in Foxglove, then create the panels below.
24
 
25
+ ## Recommended Layout
26
 
27
+ | Panel | Topic / setting |
28
  | --- | --- |
29
+ | Image | `/foxglove/tof/overview/compressed` |
30
+ | Image | `/camera/color/image_raw` |
31
+ | 3D | `Fixed frame = odom`, `Display frame = odom` |
32
+ | 3D point cloud | `/foxglove/livox/points` |
33
+ | 3D path | `/foxglove/odom/path` |
34
+ | 3D odometry | `/fusion_odometry/lazy_point_odom` or `/ekf_quat/ekf_odom` |
35
+ | Plot | `/mavros/imu/data_raw.angular_velocity.{x,y,z}` |
36
+ | Plot | `/mavros/imu/data_raw.linear_acceleration.{x,y,z}` |
37
 
38
+ For this dataset, set both 3D frame fields to:
39
 
40
+ ```text
41
+ Fixed frame: odom
42
+ Display frame: odom
43
+ ```
44
 
45
+ The visualization bag provides this TF chain:
46
 
47
  ```text
48
+ odom -> base_link -> livox_frame
49
+ base_link -> base_link_frd
50
+ odom -> odom_ned
51
  ```
52
 
53
+ Use `odom` for the main 3D view. `odom_ned` and `base_link_frd` are auxiliary frames for NED/FRD conventions.
54
 
55
+ ## Topic Guide
 
 
 
 
 
 
 
56
 
57
+ | Topic | Type | What it shows |
58
+ | --- | --- | --- |
59
+ | `/foxglove/tof/overview/compressed` | `sensor_msgs/CompressedImage` | Six-node Nooploop TOFSense-M 8x8 cascade heatmap |
60
+ | `/nlink_tofsensem_cascade` | `nlink_parser/TofsenseMCascade` | Original ToF numeric data |
61
+ | `/camera/color/image_raw` | `sensor_msgs/Image` | Intel RealSense D435i RGB stream |
62
+ | `/camera/color/camera_info` | `sensor_msgs/CameraInfo` | RGB camera intrinsics |
63
+ | `/livox/lidar` | `livox_ros_driver2/CustomMsg` | Original Livox MID360s packet topic |
64
+ | `/foxglove/livox/points` | `sensor_msgs/PointCloud2` | Foxglove-ready LiDAR point cloud |
65
+ | `/foxglove/odom/path` | `nav_msgs/Path` | Accumulated odometry trajectory for 3D display |
66
+ | `/mavros/imu/data` | `sensor_msgs/Imu` | Filtered flight-controller IMU |
67
+ | `/mavros/imu/data_raw` | `sensor_msgs/Imu` | Raw flight-controller IMU |
68
+ | `/fusion_odometry/lazy_point_odom` | `nav_msgs/Odometry` | Main odometry for 3D trajectory |
69
+ | `/ekf_quat/ekf_odom` | `nav_msgs/Odometry` | EKF odometry, when present |
70
+ | `/tf` | `tf2_msgs/TFMessage` | Dynamic odometry transform |
71
+ | `/tf_static` | `tf2_msgs/TFMessage` | Static camera, LiDAR, and frame transforms |
72
 
73
+ Foxglove does not reliably render Livox custom messages directly. Use `/foxglove/livox/points` for the 3D point cloud.
74
 
75
+ ## ToF Panel
76
+
77
+ Add an Image panel and select:
78
+
79
+ ```text
80
+ /foxglove/tof/overview/compressed
81
  ```
82
 
83
+ The overview image contains six TOFSense-M nodes. Each node shows:
84
+
85
+ | Field | Meaning |
86
+ | --- | --- |
87
+ | `dis` | distance in millimeters |
88
+ | `dis_status` | per-pixel distance status |
89
+ | `signal_strength` | per-pixel return strength |
90
 
91
+ Valid pixels are colorized by distance. Invalid or missing pixels are drawn in gray.
92
 
93
+ ## LiDAR Panel
94
+
95
+ Add a 3D panel and select:
96
+
97
+ ```text
98
+ /foxglove/livox/points
99
+ ```
100
+
101
+ Recommended point-cloud settings:
102
+
103
+ | Setting | Value |
104
  | --- | --- |
105
+ | Point size | `1.0` to `1.5` |
106
+ | Point shape | Circle |
107
+ | Color mode | Color map |
108
+ | Color field | `intensity` |
109
+ | Stixel view | Off |
 
110
 
111
+ If Stixel view is enabled, Foxglove draws pillar-like vertical structures. That is useful for obstacle-style views, but it is not the best mode for checking the raw point cloud.
112
 
113
+ ## Odometry And TF
114
 
115
+ Add odometry display in the same 3D panel:
116
+
117
+ ```text
118
+ /fusion_odometry/lazy_point_odom
119
+ ```
120
+
121
+ For the already-traveled trajectory line, add:
122
+
123
+ ```text
124
+ /foxglove/odom/path
125
  ```
126
 
127
+ If that topic is not available in a selected session, use:
128
 
129
+ ```text
130
+ /ekf_quat/ekf_odom
131
+ ```
132
 
133
+ The generated bag injects dynamic TF from odometry, so the 3D view can resolve:
134
 
135
+ ```text
136
+ odom -> base_link -> livox_frame
 
 
 
 
137
  ```
138
 
139
+ This is the frame path required to show the LiDAR point cloud together with the odometry trajectory.
140
 
141
+ ## IMU Plots
142
+
143
+ Add a Plot panel and select angular velocity:
144
+
145
+ ```text
146
+ /mavros/imu/data_raw.angular_velocity.x
147
+ /mavros/imu/data_raw.angular_velocity.y
148
+ /mavros/imu/data_raw.angular_velocity.z
149
  ```
150
 
151
+ For acceleration, add:
152
 
153
+ ```text
154
+ /mavros/imu/data_raw.linear_acceleration.x
155
+ /mavros/imu/data_raw.linear_acceleration.y
156
+ /mavros/imu/data_raw.linear_acceleration.z
 
 
157
  ```
158
 
159
+ Use `/mavros/imu/data` when you want the filtered MAVROS IMU stream, and `/mavros/imu/data_raw` when you want the raw flight-controller IMU stream.
160
+
161
+ ## Generate A Visualization Bag
162
+
163
+ Build the ROS1 helper image once:
164
 
165
  ```bash
166
+ make docker-build
 
 
 
 
 
167
  ```
168
 
169
+ Generate a 30 second all-modality example:
170
 
171
  ```bash
172
+ docker/ros1_noetic/run.sh 'python3 scripts/foxglove_visual.py \
173
  --input-bag raw/sessions/2026-05-20_030414_odom_run029/bag.bag \
174
+ --output-bag outputs_tmp/foxglove_samples/run029_mid30s_all_modalities_foxglove.bag \
175
+ --start-offset-sec 189.891 \
176
+ --duration-sec 30 \
177
+ --copy-mode custom \
178
+ --keep-topics /tf_static,/camera/color/image_raw,/camera/color/camera_info,/livox/lidar,/mavros/imu/data,/mavros/imu/data_raw,/nlink_tofsensem_cascade,/fusion_odometry/lazy_point_odom,/ekf_quat/ekf_odom \
179
+ --tof-rate-hz 15 \
180
+ --tf-rate-hz 30 \
181
+ --tf-parent-frame odom \
182
+ --force'
183
  ```
184
 
185
+ Generate a ToF + odometry focused bag:
186
 
187
  ```bash
188
+ docker/ros1_noetic/run.sh 'python3 scripts/foxglove_visual.py \
189
+ --input-bag raw/sessions/2026-05-20_030414_odom_run029/bag.bag \
190
+ --output-bag outputs_tmp/foxglove_samples/run029_tof_odom_foxglove.bag \
191
+ --copy-mode custom \
192
+ --keep-topics /tf_static,/mavros/imu/data,/mavros/imu/data_raw,/nlink_tofsensem_cascade,/fusion_odometry/lazy_point_odom,/ekf_quat/ekf_odom \
193
+ --tof-rate-hz 15 \
194
+ --tf-rate-hz 30 \
195
+ --tf-parent-frame odom \
196
+ --force'
197
  ```
198
 
199
+ ## Useful Options
 
 
200
 
201
+ | Option | Purpose |
202
+ | --- | --- |
203
+ | `--start-offset-sec` | Start from an offset relative to the raw bag start |
204
+ | `--duration-sec` | Convert only a time window |
205
+ | `--copy-mode custom` | Keep exactly the original topics listed in `--keep-topics` |
206
+ | `--keep-topics` | Original raw topics to copy into the visualization bag |
207
+ | `--tof-rate-hz` | ToF overview image rate; `15` matches the nominal TOFSense-M 8x8 rate |
208
+ | `--tof-image-mode overview` | Write only the six-node overview image |
209
+ | `--tof-image-mode both` | Write overview plus per-node ToF images |
210
+ | `--convert-livox-pointcloud2` | Convert `/livox/lidar` to `/foxglove/livox/points` |
211
+ | `--livox-calibration` | LiDAR-to-body calibration YAML used for `/tf_static` |
212
+ | `--tf-parent-frame odom` | Use `odom -> base_link` for injected dynamic TF |
213
+ | `--bag-compression bz2` | Compress the generated bag |
214
+
215
+ ## Troubleshooting
216
+
217
+ | Symptom | Check |
218
  | --- | --- |
219
+ | ToF image panel says waiting for messages | Make sure `/foxglove/tof/overview/compressed` exists in the bag |
220
+ | LiDAR topic has a warning icon | Use `/foxglove/livox/points`, not raw `/livox/lidar` |
221
+ | Point cloud does not appear in 3D | Confirm `Fixed frame = odom` and `Display frame = odom` |
222
+ | Point cloud looks like vertical pillars | Turn Stixel view off |
223
+ | Odometry and point cloud are not aligned | Confirm `/tf` and `/tf_static` are enabled |
224
+ | RGB panel is blank | Use an Image panel for `/camera/color/image_raw` |
225
 
226
+ To inspect the generated bag before opening it:
227
+
228
+ ```bash
229
+ docker/ros1_noetic/run.sh 'rosbag info outputs_tmp/foxglove_samples/run029_mid30s_all_modalities_foxglove.bag'
230
+ ```
examples/foxglove/{run029_full_tof_odom_foxglove.bag → visual_demo.bag} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:42b7e5ab3149230778076564cb9bb746366671bc893249b04ad0323064486fd2
3
- size 929220010
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:174da96d4abf8eb9eabd97f15c1120666ad32178607dd0c168ef06a85088e42b
3
+ size 817543913
metadata/sensors.yaml CHANGED
@@ -25,6 +25,31 @@ topic_categories:
25
  - /tf_static
26
 
27
  sensor_specs:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  tof:
29
  metadata_file: metadata/tof_sensor.yaml
30
  description_file: metadata/tof_sensor.md
 
25
  - /tf_static
26
 
27
  sensor_specs:
28
+ flight_controller:
29
+ manufacturer: MicoAir
30
+ manufacturer_cn: 微空
31
+ model: NxtPX4V2
32
+ label_model: NXTPX4V2
33
+ imu_model: Bosch Sensortec BMI088
34
+ imu_count: 2
35
+ topics:
36
+ - /mavros/imu/data
37
+ - /mavros/imu/data_raw
38
+ notes: "Flight-controller IMU stream from the MicoAir NxtPX4V2 autopilot."
39
+ lidar:
40
+ manufacturer: Livox
41
+ model: MID360s
42
+ sensor_type: lidar_with_integrated_imu
43
+ lidar_topic: /livox/lidar
44
+ imu_topic: /livox/imu
45
+ camera:
46
+ manufacturer: Intel RealSense
47
+ model: D435i
48
+ topics:
49
+ color: /camera/color/image_raw
50
+ depth: /camera/depth/image_rect_raw
51
+ infra1: /camera/infra1/image_rect_raw
52
+ infra2: /camera/infra2/image_rect_raw
53
  tof:
54
  metadata_file: metadata/tof_sensor.yaml
55
  description_file: metadata/tof_sensor.md
metadata/tof_sensor.md CHANGED
@@ -1,5 +1,7 @@
1
  # TOFSense-M ToF Sensor Metadata
2
 
 
 
3
  The dataset ToF topic is `/nlink_tofsensem_cascade`. It records a six-node Nooploop TOFSense-M cascade using UART query output in 8x8 mode.
4
 
5
  ## Collection Configuration
 
1
  # TOFSense-M ToF Sensor Metadata
2
 
3
+ Language: English | [简体中文](tof_sensor.zh-CN.md)
4
+
5
  The dataset ToF topic is `/nlink_tofsensem_cascade`. It records a six-node Nooploop TOFSense-M cascade using UART query output in 8x8 mode.
6
 
7
  ## Collection Configuration
metadata/tof_sensor.zh-CN.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TOFSense-M ToF 传感器元数据
2
+
3
+ 语言:[English](tof_sensor.md) | 简体中文
4
+
5
+ 本数据集的 ToF topic 是 `/nlink_tofsensem_cascade`。该 topic 记录的是六个 Nooploop TOFSense-M 传感器级联后的数据,采集时使用 UART 查询输出模式,像素模式为 8x8。
6
+
7
+ ## 采集配置
8
+
9
+ | 字段 | 数值 |
10
+ | --- | --- |
11
+ | 传感器型号 | Nooploop TOFSense-M |
12
+ | 传感器类型 | 飞行时间矩阵式激光测距传感器 |
13
+ | ROS topic | `/nlink_tofsensem_cascade` |
14
+ | ROS message | `nlink_parser/TofsenseMCascade` |
15
+ | 接口 | UART |
16
+ | 输出模式 | 查询模式 |
17
+ | 级联节点数 | 6 |
18
+ | 像素模式 | 8x8 |
19
+ | 每个节点像素数 | 64 |
20
+ | 每条级联消息的期望像素数 | 384 |
21
+ | 标称刷新率 | 8x8 模式下每个节点 15 Hz |
22
+ | UART 波特率 | 921600 bps |
23
+
24
+ ## 消息结构
25
+
26
+ `nlink_parser/TofsenseMCascade` 包含 `nodes` 字段,它是一个 `nlink_parser/TofsenseMFrame0` 数组。
27
+
28
+ 每个节点包含:
29
+
30
+ | 字段 | 类型 | 含义 |
31
+ | --- | --- | --- |
32
+ | `id` | `uint8` | 级联中的模块 ID |
33
+ | `system_time` | `uint32` | 传感器侧系统时间 |
34
+ | `pixel_count` | `uint8` | 在本数据集中期望为 64 |
35
+ | `pixels` | `TofsenseMFrame0Pixel[]` | 像素数据,按 index 0 到 63 排列 |
36
+
37
+ 每个像素包含:
38
+
39
+ | 字段 | 类型 | 单位 | 含义 |
40
+ | --- | --- | --- | --- |
41
+ | `dis` | `float32` | mm | 当前 `nlink_parser` 输出解码后的距离 |
42
+ | `dis_status` | `uint8` | code | 单个像素的距离状态码 |
43
+ | `signal_strength` | `uint16` | 原始计数 | 返回信号强度,数值越大表示回波越强 |
44
+
45
+ 做有效性检查时,只把 `dis_status == 0` 且 `dis > 0` 的像素视为可用。
46
+
47
+ ## 距离状态码
48
+
49
+ | Code | 含义 |
50
+ | --- | --- |
51
+ | 0 | 测量数据可用 |
52
+ | 1 | 信号强度过低 |
53
+ | 2 | 阶段目标 |
54
+ | 3 | 目标噪声估值过高 |
55
+ | 4 | 目标一致性检测失败 |
56
+ | 5 | 测量数据未更新 |
57
+ | 6 | 未执行环绕操作,通常出现在第一次测量 |
58
+ | 7 | 速率不一致 |
59
+ | 8 | 当前目标信号强度低 |
60
+ | 9 | 大脉冲有效范围,可能由合并目标导致 |
61
+ | 10 | 测量数据可用,但在之前的检测中未检测到目标 |
62
+ | 11 | 测量结果不一致 |
63
+ | 12 | 目标被模糊 |
64
+ | 13 | 检测到目标但数据不一致,通常发生在存在次要目标时 |
65
+ | 255 | 未检测到目标 |
66
+
67
+ ## 传感器规格
68
+
69
+ | 参数 | 数值 |
70
+ | --- | --- |
71
+ | 600 lux 下量程 | 1.5 cm 到 4 m |
72
+ | 60K lux 下量程 | 1.5 cm 到 2 m |
73
+ | 100K lux 下量程 | 1.5 cm 到 1.2 m |
74
+ | 距离分辨率 | 1 mm |
75
+ | 典型测距精度 | +/- 1.5 cm |
76
+ | 典型标准差 | 室内 / 600 lux / 4 m 条件下 < 1 cm |
77
+ | 视场角 | 水平 45 deg,垂直 45 deg,对角 65 deg |
78
+ | 支持像素模式 | 8x8 和 4x4 |
79
+ | 刷新率 | 8x8 为 15 Hz,4x4 为 60 Hz |
80
+ | 激光波长 | 940 nm |
81
+ | 激光等级 | Class 1 |
82
+ | 典型功耗 | 670 mW |
83
+ | UART 供电电压 | 3.7 V 到 5.2 V |
84
+ | CAN 供电电压 | 4.2 V 到 5.2 V |
85
+
86
+ 当前数据集版本没有固定的 ToF-to-base 外参。明确的标定状态见 `calibration/robot_v1_template/tof_to_base.yaml`。
scripts/foxglove_visual.py ADDED
@@ -0,0 +1,851 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Build a compact Foxglove-friendly rosbag from the raw dataset bags.
3
+
4
+ The raw bags are the source of truth. This script is only for visualization.
5
+ It keeps a small set of original topics, adds throttled compressed ToF heatmaps,
6
+ and can inject dynamic TF from odometry for Foxglove 3D view.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import glob
13
+ import math
14
+ import os
15
+ import struct
16
+ from pathlib import Path
17
+
18
+ cv2 = None
19
+ np = None
20
+
21
+
22
+ TOF_CASCADE_TOPIC = "/nlink_tofsensem_cascade"
23
+ TOF_FRAME0_TOPIC = "/nlink_tofsensem_frame0"
24
+ LIVOX_LIDAR_TOPIC = "/livox/lidar"
25
+ LIVOX_POINTCLOUD_TOPIC = "/foxglove/livox/points"
26
+
27
+ ODOM_CANDIDATE_TOPICS = (
28
+ "/fusion_odometry/current_point_odom",
29
+ "/fusion_odometry/lazy_point_odom",
30
+ "/ekf_quat/ekf_odom",
31
+ "/ekf/ekf_odom",
32
+ "/Odometry",
33
+ "/vrpn_client_node/crazy/pose",
34
+ )
35
+
36
+ COMPACT_COPY_TOPICS = (
37
+ "/tf_static",
38
+ "/fusion_odometry/current_point_odom",
39
+ "/fusion_odometry/lazy_point_odom",
40
+ "/ekf_quat/ekf_odom",
41
+ "/mavros/imu/data",
42
+ "/mavros/imu/data_raw",
43
+ "/livox/imu",
44
+ TOF_CASCADE_TOPIC,
45
+ TOF_FRAME0_TOPIC,
46
+ )
47
+
48
+
49
+ def import_ros_deps():
50
+ try:
51
+ import genpy
52
+ import rosbag
53
+ from geometry_msgs.msg import PoseStamped, TransformStamped
54
+ from nav_msgs.msg import Path as RosPath
55
+ from sensor_msgs.msg import CompressedImage, Image, PointCloud2, PointField
56
+ from tf2_msgs.msg import TFMessage
57
+ except ImportError as exc:
58
+ raise RuntimeError(
59
+ "ROS1 Python dependencies are not available. Run this script inside a ROS1 environment "
60
+ "that can import rosbag, geometry_msgs, sensor_msgs, and tf2_msgs."
61
+ ) from exc
62
+ return genpy, rosbag, PoseStamped, TransformStamped, RosPath, CompressedImage, Image, PointCloud2, PointField, TFMessage
63
+
64
+
65
+ def import_visual_deps():
66
+ global cv2, np
67
+ try:
68
+ import cv2 as cv2_module
69
+ import numpy as np_module
70
+ except ImportError as exc:
71
+ raise RuntimeError(
72
+ "Visualization dependencies are not available. Install python3-opencv and numpy "
73
+ "inside the ROS1 environment used to run this script."
74
+ ) from exc
75
+ cv2 = cv2_module
76
+ np = np_module
77
+
78
+
79
+ def is_valid_stamp(stamp) -> bool:
80
+ return stamp is not None and hasattr(stamp, "to_sec") and stamp.to_sec() > 0.0
81
+
82
+
83
+ def select_time(stamp, fallback_time):
84
+ return stamp if is_valid_stamp(stamp) else fallback_time
85
+
86
+
87
+ def parse_topic_csv(text: str) -> list[str]:
88
+ if not text:
89
+ return []
90
+ return [item.strip() for item in text.split(",") if item.strip()]
91
+
92
+
93
+ def bag_stem(path: str) -> str:
94
+ name = Path(path).name
95
+ return name[:-4] if name.endswith(".bag") else name
96
+
97
+
98
+ class RateLimiter:
99
+ def __init__(self, hz: float):
100
+ self.period = 0.0 if hz <= 0.0 else 1.0 / float(hz)
101
+ self.next_time = None
102
+
103
+ def allow(self, stamp) -> bool:
104
+ if self.period <= 0.0:
105
+ return True
106
+ if not is_valid_stamp(stamp):
107
+ return True
108
+ now = stamp.to_sec()
109
+ if self.next_time is None or now >= self.next_time:
110
+ self.next_time = now + self.period
111
+ return True
112
+ return False
113
+
114
+
115
+ class TofHeatmapRenderer:
116
+ def __init__(
117
+ self,
118
+ compressed_image_cls,
119
+ raw_image_cls,
120
+ max_nodes: int,
121
+ grid_size: int,
122
+ cell_px: int,
123
+ min_distance_mm: float,
124
+ max_distance_mm: float,
125
+ valid_status: int,
126
+ colormap_name: str,
127
+ output_format: str,
128
+ jpeg_quality: int,
129
+ draw_distance_text: bool,
130
+ show_tables: bool,
131
+ include_overview_image: bool,
132
+ include_node_images: bool,
133
+ overview_topic: str,
134
+ node_topic_prefix: str,
135
+ ):
136
+ self.CompressedImage = compressed_image_cls
137
+ self.Image = raw_image_cls
138
+ self.max_nodes = max(1, int(max_nodes))
139
+ self.grid_size = int(grid_size)
140
+ self.cell_px = int(cell_px)
141
+ self.min_distance_mm = float(min_distance_mm)
142
+ self.max_distance_mm = float(max_distance_mm)
143
+ self.valid_status = int(valid_status)
144
+ self.colormap = getattr(cv2, colormap_name, cv2.COLORMAP_TURBO)
145
+ self.output_format = output_format
146
+ self.jpeg_quality = int(jpeg_quality)
147
+ self.draw_distance_text = bool(draw_distance_text)
148
+ self.show_tables = bool(show_tables)
149
+ self.include_overview_image = bool(include_overview_image)
150
+ self.include_node_images = bool(include_node_images)
151
+ self.overview_topic = overview_topic
152
+ self.node_topic_prefix = node_topic_prefix
153
+ self.latest_frame0_panels = {}
154
+
155
+ @staticmethod
156
+ def get_nodes(msg) -> list:
157
+ if hasattr(msg, "nodes"):
158
+ return list(msg.nodes)
159
+ if hasattr(msg, "node"):
160
+ return list(msg.node)
161
+ return []
162
+
163
+ def reshape_or_pad(self, values, fill_value: float = 0.0) -> np.ndarray:
164
+ target = self.grid_size * self.grid_size
165
+ data = list(values[:target])
166
+ if len(data) < target:
167
+ data.extend([fill_value] * (target - len(data)))
168
+ return np.array(data, dtype=np.float32).reshape(self.grid_size, self.grid_size)
169
+
170
+ def render_numeric_table(self, grid, title: str, cell_w: int = 44, cell_h: int = 20) -> np.ndarray:
171
+ rows, cols = grid.shape
172
+ header_h = 24
173
+ width = cols * cell_w
174
+ height = header_h + rows * cell_h
175
+ image = np.full((height, width, 3), 248, dtype=np.uint8)
176
+
177
+ cv2.putText(image, title, (5, 17), cv2.FONT_HERSHEY_SIMPLEX, 0.42, (20, 20, 20), 1, cv2.LINE_AA)
178
+ for row in range(rows + 1):
179
+ y = header_h + row * cell_h
180
+ cv2.line(image, (0, y), (width, y), (180, 180, 180), 1)
181
+ for col in range(cols + 1):
182
+ x = col * cell_w
183
+ cv2.line(image, (x, header_h), (x, height), (180, 180, 180), 1)
184
+
185
+ for row in range(rows):
186
+ for col in range(cols):
187
+ text = str(int(grid[row, col]))
188
+ x = col * cell_w + 3
189
+ y = header_h + row * cell_h + 14
190
+ cv2.putText(image, text, (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.34, (30, 30, 30), 1, cv2.LINE_AA)
191
+ return image
192
+
193
+ def render_node(self, node_id: int, pixels, stamp) -> np.ndarray:
194
+ distances = [float(getattr(pixel, "dis", 0.0)) for pixel in pixels]
195
+ statuses = [int(getattr(pixel, "dis_status", 255)) for pixel in pixels]
196
+ strengths = [int(getattr(pixel, "signal_strength", 0)) for pixel in pixels]
197
+
198
+ dis = self.reshape_or_pad(distances, fill_value=0.0)
199
+ status = self.reshape_or_pad(statuses, fill_value=255).astype(np.int32)
200
+ strength = self.reshape_or_pad(strengths, fill_value=0).astype(np.int32)
201
+ valid = np.logical_and(status == self.valid_status, dis > 0.0)
202
+
203
+ clipped = np.clip(dis, self.min_distance_mm, self.max_distance_mm)
204
+ scale = max(1e-6, self.max_distance_mm - self.min_distance_mm)
205
+ normalized = ((clipped - self.min_distance_mm) / scale * 255.0).astype(np.uint8)
206
+ heat = cv2.applyColorMap(normalized, self.colormap)
207
+ heat = cv2.cvtColor(heat, cv2.COLOR_BGR2RGB)
208
+ heat[~valid] = np.array([88, 88, 88], dtype=np.uint8)
209
+
210
+ tile_size = self.grid_size * self.cell_px
211
+ tile = cv2.resize(heat, (tile_size, tile_size), interpolation=cv2.INTER_NEAREST)
212
+ for idx in range(self.grid_size + 1):
213
+ offset = idx * self.cell_px
214
+ cv2.line(tile, (offset, 0), (offset, tile.shape[0]), (255, 255, 255), 1)
215
+ cv2.line(tile, (0, offset), (tile.shape[1], offset), (255, 255, 255), 1)
216
+
217
+ if self.draw_distance_text:
218
+ for row in range(self.grid_size):
219
+ for col in range(self.grid_size):
220
+ text = str(int(dis[row, col]))
221
+ x = col * self.cell_px + 3
222
+ y = row * self.cell_px + int(self.cell_px * 0.65)
223
+ color = (255, 255, 255) if valid[row, col] else (220, 220, 220)
224
+ cv2.putText(tile, text, (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.32, color, 1, cv2.LINE_AA)
225
+
226
+ body = tile
227
+ if self.show_tables:
228
+ status_table = self.render_numeric_table(status, "dis_status")
229
+ strength_table = self.render_numeric_table(strength, "signal_strength")
230
+ table_w = max(status_table.shape[1], strength_table.shape[1])
231
+
232
+ def pad_width(image, width):
233
+ if image.shape[1] == width:
234
+ return image
235
+ pad = np.full((image.shape[0], width - image.shape[1], 3), 248, dtype=np.uint8)
236
+ return np.concatenate([image, pad], axis=1)
237
+
238
+ status_table = pad_width(status_table, table_w)
239
+ strength_table = pad_width(strength_table, table_w)
240
+ table_gap = np.full((8, table_w, 3), 245, dtype=np.uint8)
241
+ tables = np.concatenate([status_table, table_gap, strength_table], axis=0)
242
+
243
+ content_h = max(tile.shape[0], tables.shape[0])
244
+ tile_pad = np.full((content_h, tile.shape[1], 3), 245, dtype=np.uint8)
245
+ table_pad = np.full((content_h, tables.shape[1], 3), 245, dtype=np.uint8)
246
+ tile_pad[:tile.shape[0], :tile.shape[1], :] = tile
247
+ table_pad[:tables.shape[0], :tables.shape[1], :] = tables
248
+ gap = np.full((content_h, 10, 3), 245, dtype=np.uint8)
249
+ body = np.concatenate([tile_pad, gap, table_pad], axis=1)
250
+
251
+ header_h = 32
252
+ panel = np.full((header_h + body.shape[0], body.shape[1], 3), 245, dtype=np.uint8)
253
+ valid_ratio = float(np.count_nonzero(valid)) / float(valid.size) if valid.size else 0.0
254
+ title = "node {} dis(mm) heatmap valid {:.0f}%".format(node_id, valid_ratio * 100.0)
255
+ if is_valid_stamp(stamp):
256
+ title += " t={:.2f}".format(stamp.to_sec())
257
+ cv2.putText(panel, title, (6, 22), cv2.FONT_HERSHEY_SIMPLEX, 0.55, (20, 20, 20), 1, cv2.LINE_AA)
258
+ panel[header_h:, :, :] = body
259
+ return panel
260
+
261
+ @staticmethod
262
+ def render_overview(node_panels):
263
+ if not node_panels:
264
+ return np.full((260, 420, 3), 245, dtype=np.uint8)
265
+
266
+ cols = min(3, len(node_panels))
267
+ rows = int(math.ceil(len(node_panels) / float(cols)))
268
+ gap = 12
269
+ top = 38
270
+ tile_h = max(panel.shape[0] for panel in node_panels)
271
+ tile_w = max(panel.shape[1] for panel in node_panels)
272
+ canvas_h = top + rows * tile_h + max(0, rows - 1) * gap + 12
273
+ canvas_w = cols * tile_w + max(0, cols - 1) * gap + 12
274
+ canvas = np.full((canvas_h, canvas_w, 3), 245, dtype=np.uint8)
275
+ cv2.putText(
276
+ canvas,
277
+ "TOFSense-M cascade heatmap",
278
+ (6, 25),
279
+ cv2.FONT_HERSHEY_SIMPLEX,
280
+ 0.72,
281
+ (20, 20, 20),
282
+ 2,
283
+ cv2.LINE_AA,
284
+ )
285
+ for idx, panel in enumerate(node_panels):
286
+ row = idx // cols
287
+ col = idx % cols
288
+ y = top + row * (tile_h + gap)
289
+ x = 6 + col * (tile_w + gap)
290
+ canvas[y:y + panel.shape[0], x:x + panel.shape[1], :] = panel
291
+ return canvas
292
+
293
+ def to_ros_image(self, image_rgb: np.ndarray, stamp):
294
+ if self.output_format == "raw":
295
+ msg = self.Image()
296
+ if is_valid_stamp(stamp):
297
+ msg.header.stamp = stamp
298
+ msg.height = image_rgb.shape[0]
299
+ msg.width = image_rgb.shape[1]
300
+ msg.encoding = "rgb8"
301
+ msg.is_bigendian = 0
302
+ msg.step = msg.width * 3
303
+ msg.data = np.ascontiguousarray(image_rgb).tobytes()
304
+ return msg
305
+
306
+ msg = self.CompressedImage()
307
+ if is_valid_stamp(stamp):
308
+ msg.header.stamp = stamp
309
+ image_bgr = cv2.cvtColor(image_rgb, cv2.COLOR_RGB2BGR)
310
+ if self.output_format == "png":
311
+ ok, encoded = cv2.imencode(".png", image_bgr, [cv2.IMWRITE_PNG_COMPRESSION, 3])
312
+ msg.format = "png"
313
+ else:
314
+ ok, encoded = cv2.imencode(".jpg", image_bgr, [cv2.IMWRITE_JPEG_QUALITY, self.jpeg_quality])
315
+ msg.format = "jpeg"
316
+ if not ok:
317
+ raise RuntimeError("failed to encode ToF heatmap")
318
+ msg.data = encoded.tobytes()
319
+ return msg
320
+
321
+ def consume_cascade(self, msg, fallback_time) -> list[tuple[str, object, object]]:
322
+ stamp = fallback_time
323
+ if hasattr(msg, "header") and hasattr(msg.header, "stamp"):
324
+ stamp = select_time(msg.header.stamp, fallback_time)
325
+
326
+ node_panels = []
327
+ node_outputs = []
328
+ for idx, node in enumerate(self.get_nodes(msg)[:self.max_nodes]):
329
+ node_id = int(getattr(node, "id", idx))
330
+ panel = self.render_node(node_id, list(getattr(node, "pixels", [])), stamp)
331
+ node_panels.append(panel)
332
+ if self.include_node_images:
333
+ node_outputs.append((
334
+ self.node_topic_prefix + str(node_id),
335
+ self.to_ros_image(panel, stamp),
336
+ select_time(stamp, fallback_time),
337
+ ))
338
+
339
+ outputs = []
340
+ if self.include_overview_image:
341
+ overview = self.render_overview(node_panels)
342
+ outputs.append((self.overview_topic, self.to_ros_image(overview, stamp), select_time(stamp, fallback_time)))
343
+ outputs.extend(node_outputs)
344
+ return outputs
345
+
346
+ def consume_frame0(self, msg, fallback_time) -> list[tuple[str, object, object]]:
347
+ stamp = fallback_time
348
+ if hasattr(msg, "header") and hasattr(msg.header, "stamp"):
349
+ stamp = select_time(msg.header.stamp, fallback_time)
350
+
351
+ node_id = int(getattr(msg, "id", 0))
352
+ panel = self.render_node(node_id, list(getattr(msg, "pixels", [])), stamp)
353
+ self.latest_frame0_panels[node_id] = panel
354
+
355
+ ordered_ids = sorted(self.latest_frame0_panels.keys())[:self.max_nodes]
356
+ outputs = []
357
+ if self.include_overview_image:
358
+ overview = self.render_overview([self.latest_frame0_panels[item] for item in ordered_ids])
359
+ outputs.append((self.overview_topic, self.to_ros_image(overview, stamp), select_time(stamp, fallback_time)))
360
+ if self.include_node_images:
361
+ outputs.append((self.node_topic_prefix + str(node_id), self.to_ros_image(panel, stamp), select_time(stamp, fallback_time)))
362
+ return outputs
363
+
364
+
365
+ class Converter:
366
+ def __init__(self, args):
367
+ self.args = args
368
+ import_visual_deps()
369
+ (
370
+ self.genpy,
371
+ self.rosbag,
372
+ self.PoseStamped,
373
+ self.TransformStamped,
374
+ self.RosPath,
375
+ self.CompressedImage,
376
+ self.Image,
377
+ self.PointCloud2,
378
+ self.PointField,
379
+ self.TFMessage,
380
+ ) = import_ros_deps()
381
+ self.input_bag = Path(args.input_bag).resolve()
382
+ self.output_bag = self.resolve_output_bag()
383
+ self.tof_limiter = RateLimiter(args.tof_rate_hz)
384
+ self.tf_limiter = RateLimiter(args.tf_rate_hz)
385
+ self.path_limiter = RateLimiter(args.path_rate_hz)
386
+ self.odom_path = None
387
+ self.copy_topics = self.resolve_copy_topics()
388
+ self.renderer = TofHeatmapRenderer(
389
+ compressed_image_cls=self.CompressedImage,
390
+ raw_image_cls=self.Image,
391
+ max_nodes=args.tof_max_nodes,
392
+ grid_size=args.tof_grid_size,
393
+ cell_px=args.tof_cell_px,
394
+ min_distance_mm=args.tof_min_dis,
395
+ max_distance_mm=args.tof_max_dis,
396
+ valid_status=args.tof_valid_status,
397
+ colormap_name=args.tof_colormap,
398
+ output_format=args.tof_output_format,
399
+ jpeg_quality=args.tof_jpeg_quality,
400
+ draw_distance_text=args.tof_draw_distance_text,
401
+ show_tables=args.tof_show_tables,
402
+ include_overview_image=args.tof_image_mode in ("overview", "both"),
403
+ include_node_images=args.tof_image_mode in ("nodes", "both"),
404
+ overview_topic=args.tof_overview_topic,
405
+ node_topic_prefix=args.tof_node_topic_prefix,
406
+ )
407
+
408
+ def resolve_output_bag(self) -> Path:
409
+ if self.args.output_bag:
410
+ output = Path(self.args.output_bag).resolve()
411
+ else:
412
+ output_dir = Path(self.args.output_dir).resolve() if self.args.output_dir else self.input_bag.parent / "foxglove"
413
+ output = output_dir / (bag_stem(str(self.input_bag)) + "_foxglove_compact.bag")
414
+ if output == self.input_bag:
415
+ raise RuntimeError("output bag path must be different from input bag path")
416
+ output.parent.mkdir(parents=True, exist_ok=True)
417
+ if output.exists():
418
+ if self.args.force:
419
+ output.unlink()
420
+ else:
421
+ raise RuntimeError("output bag already exists: {} (use --force)".format(output))
422
+ return output
423
+
424
+ def resolve_copy_topics(self) -> set[str]:
425
+ mode = self.args.copy_mode
426
+ if mode == "none":
427
+ topics = set()
428
+ elif mode == "compact":
429
+ topics = set(COMPACT_COPY_TOPICS)
430
+ elif mode == "custom":
431
+ topics = set()
432
+ else:
433
+ topics = None
434
+
435
+ if topics is not None:
436
+ topics.update(parse_topic_csv(self.args.copy_topics))
437
+ topics.update(parse_topic_csv(self.args.keep_topics))
438
+ return topics
439
+
440
+ def choose_topic(self, topic_info, requested, candidates, label):
441
+ if requested and requested != "auto":
442
+ if requested not in topic_info:
443
+ raise RuntimeError("{} topic not found in bag: {}".format(label, requested))
444
+ return requested
445
+ for topic in candidates:
446
+ if topic in topic_info:
447
+ return topic
448
+ return None
449
+
450
+ def build_tf_from_pose(self, msg, bag_time):
451
+ if hasattr(msg, "pose") and hasattr(msg.pose, "pose"):
452
+ pose = msg.pose.pose
453
+ stamp = select_time(msg.header.stamp, bag_time)
454
+ parent = self.args.tf_parent_frame or getattr(msg.header, "frame_id", "") or "map"
455
+ elif hasattr(msg, "pose"):
456
+ pose = msg.pose
457
+ stamp = select_time(msg.header.stamp, bag_time)
458
+ parent = self.args.tf_parent_frame or getattr(msg.header, "frame_id", "") or "map"
459
+ else:
460
+ return None, None
461
+
462
+ transform = self.TransformStamped()
463
+ transform.header.stamp = stamp
464
+ transform.header.frame_id = parent
465
+ transform.child_frame_id = self.args.tf_child_frame
466
+ transform.transform.translation.x = pose.position.x
467
+ transform.transform.translation.y = pose.position.y
468
+ transform.transform.translation.z = pose.position.z
469
+ transform.transform.rotation.x = pose.orientation.x
470
+ transform.transform.rotation.y = pose.orientation.y
471
+ transform.transform.rotation.z = pose.orientation.z
472
+ transform.transform.rotation.w = pose.orientation.w
473
+ return self.TFMessage(transforms=[transform]), stamp
474
+
475
+ def build_path_from_odometry(self, msg, bag_time):
476
+ if hasattr(msg, "pose") and hasattr(msg.pose, "pose"):
477
+ pose = msg.pose.pose
478
+ stamp = select_time(msg.header.stamp, bag_time)
479
+ elif hasattr(msg, "pose"):
480
+ pose = msg.pose
481
+ stamp = select_time(msg.header.stamp, bag_time)
482
+ else:
483
+ return None, None
484
+
485
+ frame_id = self.args.path_frame
486
+ if frame_id == "auto":
487
+ frame_id = self.args.tf_parent_frame or getattr(msg.header, "frame_id", "") or "odom"
488
+
489
+ if self.odom_path is None:
490
+ self.odom_path = self.RosPath()
491
+ self.odom_path.header.frame_id = frame_id
492
+
493
+ pose_msg = self.PoseStamped()
494
+ pose_msg.header.stamp = stamp
495
+ pose_msg.header.frame_id = frame_id
496
+ pose_msg.pose = pose
497
+ self.odom_path.poses.append(pose_msg)
498
+
499
+ if self.args.path_max_poses > 0 and len(self.odom_path.poses) > self.args.path_max_poses:
500
+ self.odom_path.poses = self.odom_path.poses[-self.args.path_max_poses:]
501
+
502
+ self.odom_path.header.stamp = stamp
503
+ self.odom_path.header.frame_id = frame_id
504
+ return self.odom_path, stamp
505
+
506
+ def build_pointcloud2_from_livox(self, msg, bag_time):
507
+ stamp = bag_time
508
+ frame_id = "livox_frame"
509
+ if hasattr(msg, "header"):
510
+ stamp = select_time(getattr(msg.header, "stamp", None), bag_time)
511
+ frame_id = getattr(msg.header, "frame_id", "") or frame_id
512
+
513
+ points = []
514
+ for point in getattr(msg, "points", []):
515
+ x = float(getattr(point, "x", 0.0))
516
+ y = float(getattr(point, "y", 0.0))
517
+ z = float(getattr(point, "z", 0.0))
518
+ if not self.args.livox_keep_zero_points and x == 0.0 and y == 0.0 and z == 0.0:
519
+ continue
520
+ points.append((
521
+ x,
522
+ y,
523
+ z,
524
+ float(getattr(point, "reflectivity", 0)),
525
+ int(getattr(point, "line", 0)) & 0xFF,
526
+ int(getattr(point, "tag", 0)) & 0xFF,
527
+ int(getattr(point, "offset_time", 0)) & 0xFFFFFFFF,
528
+ ))
529
+
530
+ cloud = self.PointCloud2()
531
+ cloud.header.stamp = stamp
532
+ cloud.header.frame_id = frame_id
533
+ cloud.height = 1
534
+ cloud.width = len(points)
535
+ cloud.fields = [
536
+ self.PointField(name="x", offset=0, datatype=self.PointField.FLOAT32, count=1),
537
+ self.PointField(name="y", offset=4, datatype=self.PointField.FLOAT32, count=1),
538
+ self.PointField(name="z", offset=8, datatype=self.PointField.FLOAT32, count=1),
539
+ self.PointField(name="intensity", offset=12, datatype=self.PointField.FLOAT32, count=1),
540
+ self.PointField(name="line", offset=16, datatype=self.PointField.UINT8, count=1),
541
+ self.PointField(name="tag", offset=17, datatype=self.PointField.UINT8, count=1),
542
+ self.PointField(name="offset_time", offset=20, datatype=self.PointField.UINT32, count=1),
543
+ ]
544
+ cloud.is_bigendian = False
545
+ cloud.point_step = 24
546
+ cloud.row_step = cloud.point_step * cloud.width
547
+ cloud.is_dense = False
548
+
549
+ packer = struct.Struct("<ffffBBxxI")
550
+ data = bytearray(cloud.row_step)
551
+ for idx, point in enumerate(points):
552
+ packer.pack_into(data, idx * cloud.point_step, *point)
553
+ cloud.data = bytes(data)
554
+ return cloud, stamp
555
+
556
+ def output_compression(self):
557
+ if self.args.bag_compression == "none":
558
+ return "none"
559
+ return self.args.bag_compression
560
+
561
+ def resolve_time_window(self, in_bag):
562
+ if self.args.start_offset_sec is None and self.args.duration_sec is None:
563
+ return None, None
564
+
565
+ bag_start = float(in_bag.get_start_time())
566
+ bag_end = float(in_bag.get_end_time())
567
+ start_offset = float(self.args.start_offset_sec or 0.0)
568
+ start_sec = bag_start + max(0.0, start_offset)
569
+ if self.args.duration_sec is None:
570
+ end_sec = bag_end
571
+ else:
572
+ end_sec = min(bag_end, start_sec + max(0.0, float(self.args.duration_sec)))
573
+ if start_sec >= end_sec:
574
+ raise RuntimeError("empty time window: start={} end={}".format(start_sec, end_sec))
575
+ return self.genpy.Time.from_sec(start_sec), self.genpy.Time.from_sec(end_sec)
576
+
577
+ def write_static_tf_for_window(self, in_bag, out_bag, window_start):
578
+ if window_start is None:
579
+ return 0
580
+ if self.copy_topics is not None and "/tf_static" not in self.copy_topics:
581
+ return 0
582
+ written = 0
583
+ for _, msg, _ in in_bag.read_messages(topics=["/tf_static"]):
584
+ out_bag.write("/tf_static", msg, t=window_start)
585
+ written += 1
586
+ return written
587
+
588
+ def resolve_livox_calibration_path(self):
589
+ if not self.args.inject_livox_static_tf:
590
+ return None
591
+ calib_path = Path(self.args.livox_calibration)
592
+ if not calib_path.is_absolute():
593
+ calib_path = Path(__file__).resolve().parents[1] / calib_path
594
+ if not calib_path.is_file():
595
+ raise RuntimeError("Livox calibration file not found: {}".format(calib_path))
596
+ return calib_path
597
+
598
+ def load_livox_static_transform(self, stamp):
599
+ calib_path = self.resolve_livox_calibration_path()
600
+ if calib_path is None:
601
+ return None
602
+ try:
603
+ import yaml
604
+ except ImportError as exc:
605
+ raise RuntimeError("PyYAML is required to read Livox calibration: {}".format(calib_path)) from exc
606
+
607
+ with calib_path.open("r", encoding="utf-8") as stream:
608
+ calib = yaml.safe_load(stream) or {}
609
+
610
+ parent = calib.get("parent_frame")
611
+ child = calib.get("child_frame")
612
+ translation = calib.get("translation_xyz_m")
613
+ rotation = calib.get("rotation_xyzw")
614
+ if not parent or not child or translation is None or rotation is None:
615
+ raise RuntimeError(
616
+ "Livox calibration must define parent_frame, child_frame, translation_xyz_m, and rotation_xyzw: {}".format(
617
+ calib_path
618
+ )
619
+ )
620
+ if len(translation) != 3 or len(rotation) != 4:
621
+ raise RuntimeError("invalid Livox calibration vector length: {}".format(calib_path))
622
+
623
+ transform = self.TransformStamped()
624
+ transform.header.stamp = stamp or self.genpy.Time(0)
625
+ transform.header.frame_id = str(parent)
626
+ transform.child_frame_id = str(child)
627
+ transform.transform.translation.x = float(translation[0])
628
+ transform.transform.translation.y = float(translation[1])
629
+ transform.transform.translation.z = float(translation[2])
630
+ transform.transform.rotation.x = float(rotation[0])
631
+ transform.transform.rotation.y = float(rotation[1])
632
+ transform.transform.rotation.z = float(rotation[2])
633
+ transform.transform.rotation.w = float(rotation[3])
634
+ return self.TFMessage(transforms=[transform])
635
+
636
+ def write_livox_static_tf(self, out_bag, window_start):
637
+ if self.copy_topics is not None and "/tf_static" not in self.copy_topics:
638
+ return 0
639
+ tf_msg = self.load_livox_static_transform(window_start)
640
+ if tf_msg is None:
641
+ return 0
642
+ out_bag.write("/tf_static", tf_msg, t=window_start or self.genpy.Time(0))
643
+ return 1
644
+
645
+ def convert(self):
646
+ if not self.input_bag.is_file():
647
+ raise RuntimeError("input bag does not exist: {}".format(self.input_bag))
648
+
649
+ processed = 0
650
+ copied = 0
651
+ tof_images = 0
652
+ tf_inserted = 0
653
+ livox_converted = 0
654
+ path_inserted = 0
655
+
656
+ with self.rosbag.Bag(str(self.input_bag), "r") as in_bag:
657
+ window_start, window_end = self.resolve_time_window(in_bag)
658
+ topic_info = in_bag.get_type_and_topic_info().topics
659
+ tof_topic = self.choose_topic(
660
+ topic_info,
661
+ self.args.tof_input_topic,
662
+ (TOF_CASCADE_TOPIC, TOF_FRAME0_TOPIC),
663
+ "ToF",
664
+ )
665
+ odom_topic = self.choose_topic(topic_info, self.args.odom_input_topic, ODOM_CANDIDATE_TOPICS, "odometry")
666
+ livox_topic = self.choose_topic(
667
+ topic_info,
668
+ self.args.livox_input_topic,
669
+ (LIVOX_LIDAR_TOPIC,),
670
+ "Livox lidar",
671
+ ) if self.args.convert_livox_pointcloud2 else None
672
+
673
+ read_topics = None
674
+ if self.copy_topics is not None:
675
+ read_topics = set(topic for topic in self.copy_topics if topic in topic_info)
676
+ if tof_topic:
677
+ read_topics.add(tof_topic)
678
+ if self.args.inject_dynamic_tf and odom_topic:
679
+ read_topics.add(odom_topic)
680
+ if livox_topic:
681
+ read_topics.add(livox_topic)
682
+ read_topics = sorted(read_topics)
683
+
684
+ print("[INFO] input bag: {}".format(self.input_bag))
685
+ print("[INFO] output bag: {}".format(self.output_bag))
686
+ print("[INFO] copy mode: {}".format(self.args.copy_mode))
687
+ print("[INFO] ToF topic: {}".format(tof_topic or "not found"))
688
+ print("[INFO] ToF image mode: {} format={} rate={}Hz".format(
689
+ self.args.tof_image_mode, self.args.tof_output_format, self.args.tof_rate_hz
690
+ ))
691
+ print("[INFO] odometry topic for TF: {}".format(odom_topic or "not found"))
692
+ print("[INFO] odometry Path: {}".format(
693
+ "{} -> {}".format(odom_topic, self.args.odom_path_topic) if odom_topic and self.args.write_odom_path else "disabled/not found"
694
+ ))
695
+ print("[INFO] Livox PointCloud2: {}".format(
696
+ "{} -> {}".format(livox_topic, self.args.livox_pointcloud_topic) if livox_topic else "disabled/not found"
697
+ ))
698
+ print("[INFO] Livox static TF calibration: {}".format(
699
+ self.resolve_livox_calibration_path() if self.args.inject_livox_static_tf else "disabled"
700
+ ))
701
+ if window_start is not None:
702
+ print("[INFO] time window: {:.3f} -> {:.3f} ({:.3f}s)".format(
703
+ window_start.to_sec(), window_end.to_sec(), window_end.to_sec() - window_start.to_sec()
704
+ ))
705
+
706
+ with self.rosbag.Bag(str(self.output_bag), "w", compression=self.output_compression()) as out_bag:
707
+ copied += self.write_static_tf_for_window(in_bag, out_bag, window_start)
708
+ copied += self.write_livox_static_tf(out_bag, window_start)
709
+
710
+ for topic, msg, bag_time in in_bag.read_messages(
711
+ topics=read_topics,
712
+ start_time=window_start,
713
+ end_time=window_end,
714
+ ):
715
+ processed += 1
716
+
717
+ if self.copy_topics is None or topic in self.copy_topics:
718
+ out_bag.write(topic, msg, t=bag_time)
719
+ copied += 1
720
+
721
+ if self.args.inject_dynamic_tf and odom_topic and topic == odom_topic and self.tf_limiter.allow(bag_time):
722
+ tf_msg, tf_time = self.build_tf_from_pose(msg, bag_time)
723
+ if tf_msg is not None:
724
+ out_bag.write(self.args.tf_topic, tf_msg, t=tf_time)
725
+ tf_inserted += 1
726
+
727
+ if self.args.write_odom_path and odom_topic and topic == odom_topic:
728
+ path_msg, path_time = self.build_path_from_odometry(msg, bag_time)
729
+ if path_msg is not None and self.path_limiter.allow(path_time):
730
+ out_bag.write(self.args.odom_path_topic, path_msg, t=path_time)
731
+ path_inserted += 1
732
+
733
+ if livox_topic and topic == livox_topic:
734
+ cloud, cloud_time = self.build_pointcloud2_from_livox(msg, bag_time)
735
+ out_bag.write(self.args.livox_pointcloud_topic, cloud, t=cloud_time)
736
+ livox_converted += 1
737
+
738
+ if tof_topic and topic == tof_topic and self.args.tof_image_mode != "none" and self.tof_limiter.allow(bag_time):
739
+ if topic == TOF_CASCADE_TOPIC or hasattr(msg, "nodes") or hasattr(msg, "node"):
740
+ outputs = self.renderer.consume_cascade(msg, bag_time)
741
+ else:
742
+ outputs = self.renderer.consume_frame0(msg, bag_time)
743
+ for out_topic, out_msg, out_time in outputs:
744
+ out_bag.write(out_topic, out_msg, t=out_time)
745
+ tof_images += 1
746
+
747
+ if processed % 10000 == 0:
748
+ print("[RUNNING] processed={} copied={} tof_images={} tf={} path={} livox_pc2={}".format(
749
+ processed, copied, tof_images, tf_inserted, path_inserted, livox_converted
750
+ ))
751
+
752
+ input_size = self.input_bag.stat().st_size
753
+ output_size = self.output_bag.stat().st_size
754
+ ratio = float(output_size) / float(input_size) if input_size else 0.0
755
+ print("[DONE] processed={} copied={} tof_images={} tf={} path={} livox_pc2={}".format(
756
+ processed, copied, tof_images, tf_inserted, path_inserted, livox_converted
757
+ ))
758
+ print("[DONE] input_size={:.2f} GB output_size={:.2f} GB ratio={:.3f}".format(
759
+ input_size / 1e9, output_size / 1e9, ratio
760
+ ))
761
+
762
+
763
+ def parse_args():
764
+ parser = argparse.ArgumentParser(description="Create a compact Foxglove visualization rosbag.")
765
+ parser.add_argument("--input-bag", required=True, help="Input ROS1 bag")
766
+ parser.add_argument("--output-bag", default=None, help="Output ROS1 bag")
767
+ parser.add_argument("--output-dir", default=None, help="Output directory when --output-bag is omitted")
768
+ parser.add_argument("--force", action="store_true", help="Overwrite output bag")
769
+ parser.add_argument("--start-offset-sec", type=float, default=None, help="Start offset from input bag start")
770
+ parser.add_argument("--duration-sec", type=float, default=None, help="Maximum duration to convert")
771
+
772
+ parser.add_argument(
773
+ "--copy-mode",
774
+ choices=("compact", "all", "none", "custom"),
775
+ default="compact",
776
+ help="Original topic copy policy. compact avoids camera/lidar by default.",
777
+ )
778
+ parser.add_argument("--copy-topics", default="", help="Comma-separated extra original topics to copy")
779
+ parser.add_argument(
780
+ "--keep-topics",
781
+ default="",
782
+ help="Alias for --copy-topics. Use with --copy-mode custom to keep exactly the listed original topics.",
783
+ )
784
+ parser.add_argument("--bag-compression", choices=("none", "bz2", "lz4"), default="bz2")
785
+
786
+ parser.add_argument("--tof-input-topic", default="auto")
787
+ parser.add_argument("--tof-image-mode", choices=("overview", "nodes", "both", "none"), default="overview")
788
+ parser.add_argument("--tof-output-format", choices=("jpeg", "png", "raw"), default="jpeg")
789
+ parser.add_argument(
790
+ "--tof-rate-hz",
791
+ type=float,
792
+ default=15.0,
793
+ help="Visualization image rate. 15 matches TOFSense-M 8x8 nominal rate; 0 disables throttling.",
794
+ )
795
+ parser.add_argument("--tof-overview-topic", default="/foxglove/tof/overview/compressed")
796
+ parser.add_argument("--tof-node-topic-prefix", default="/foxglove/tof/node_")
797
+ parser.add_argument("--tof-max-nodes", type=int, default=6)
798
+ parser.add_argument("--tof-grid-size", type=int, default=8)
799
+ parser.add_argument("--tof-cell-px", type=int, default=28)
800
+ parser.add_argument("--tof-min-dis", type=float, default=0.0)
801
+ parser.add_argument("--tof-max-dis", type=float, default=5000.0)
802
+ parser.add_argument("--tof-valid-status", type=int, default=0)
803
+ parser.add_argument("--tof-colormap", default="COLORMAP_TURBO")
804
+ parser.add_argument("--tof-jpeg-quality", type=int, default=82)
805
+ parser.add_argument("--tof-draw-distance-text", dest="tof_draw_distance_text", action="store_true")
806
+ parser.add_argument("--tof-hide-distance-text", dest="tof_draw_distance_text", action="store_false")
807
+ parser.set_defaults(tof_draw_distance_text=True)
808
+ parser.add_argument("--tof-show-tables", dest="tof_show_tables", action="store_true")
809
+ parser.add_argument("--tof-hide-tables", dest="tof_show_tables", action="store_false")
810
+ parser.set_defaults(tof_show_tables=True)
811
+
812
+ parser.add_argument("--convert-livox-pointcloud2", dest="convert_livox_pointcloud2", action="store_true")
813
+ parser.add_argument("--no-convert-livox-pointcloud2", dest="convert_livox_pointcloud2", action="store_false")
814
+ parser.set_defaults(convert_livox_pointcloud2=True)
815
+ parser.add_argument("--livox-input-topic", default="auto")
816
+ parser.add_argument("--livox-pointcloud-topic", default=LIVOX_POINTCLOUD_TOPIC)
817
+ parser.add_argument("--livox-keep-zero-points", action="store_true")
818
+ parser.add_argument("--inject-livox-static-tf", dest="inject_livox_static_tf", action="store_true")
819
+ parser.add_argument("--no-inject-livox-static-tf", dest="inject_livox_static_tf", action="store_false")
820
+ parser.set_defaults(inject_livox_static_tf=True)
821
+ parser.add_argument(
822
+ "--livox-calibration",
823
+ default="calibration/robot_v1_template/livox_to_base.yaml",
824
+ help="YAML file with parent_frame, child_frame, translation_xyz_m, and rotation_xyzw.",
825
+ )
826
+
827
+ parser.add_argument("--inject-dynamic-tf", dest="inject_dynamic_tf", action="store_true")
828
+ parser.add_argument("--no-inject-dynamic-tf", dest="inject_dynamic_tf", action="store_false")
829
+ parser.set_defaults(inject_dynamic_tf=True)
830
+ parser.add_argument("--odom-input-topic", default="auto")
831
+ parser.add_argument("--tf-rate-hz", type=float, default=10.0, help="0 disables TF throttling")
832
+ parser.add_argument("--tf-topic", default="/tf")
833
+ parser.add_argument("--tf-parent-frame", default="map")
834
+ parser.add_argument("--tf-child-frame", default="base_link")
835
+ parser.add_argument("--write-odom-path", dest="write_odom_path", action="store_true")
836
+ parser.add_argument("--no-write-odom-path", dest="write_odom_path", action="store_false")
837
+ parser.set_defaults(write_odom_path=True)
838
+ parser.add_argument("--odom-path-topic", default="/foxglove/odom/path")
839
+ parser.add_argument("--path-rate-hz", type=float, default=10.0, help="0 writes path at every odometry message")
840
+ parser.add_argument("--path-frame", default="auto", help="Path frame. auto uses --tf-parent-frame, then odometry frame.")
841
+ parser.add_argument("--path-max-poses", type=int, default=0, help="0 keeps the full path")
842
+ return parser.parse_args()
843
+
844
+
845
+ def main():
846
+ args = parse_args()
847
+ Converter(args).convert()
848
+
849
+
850
+ if __name__ == "__main__":
851
+ main()