Skip to content

Support new datasources (MCAP, ROS1 Bags, Hesai PCAPs) - #680

Merged
JanuszBedkowski merged 21 commits into
MapsHD:mainfrom
michalpelka:mp/hesai_pcap_to_laz
Dec 4, 2026
Merged

JanuszBedkowski merged 21 commits into
MapsHD:mainfrom
michalpelka:mp/hesai_pcap_to_laz

Conversation

@michalpelka

@michalpelka michalpelka commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Step 1 and the raw data viewer read their input through a RecordingSource interface (recording_sources/)
    instead of a hard-coded lidarNNNN.laz / imuNNNN.csv loader. Each kind of recording registers itself, and the apps
    pick the kind from the paths given or dropped. Mandeye LAZ/CSV sessions load as before.
  • New kinds: ROS1 bags and MCAP files (one or several files, LZ4 / Zstd / bz2 compressed, chunks read lazily through
    the file index, an options window to pick the lidar and IMU topics), and Hesai pcap captures (.pcap, .pcap.zstd,
    .pcap.zst or a lidar_recorder session folder, with correction.dat; the IMU comes from the lidar packets or, when
    they carry none, from imuNNNN.csv / MURATA_IMU). The new tool hesai_pcap_to_laz converts any recording kind to
    a Mandeye session.
  • The clang-format check now covers rosbags/ and recording_sources/. rosbags/ is reformatted in the last commit
    (whitespace and line wrapping only: hide whitespace when reviewing it).

Changes users will notice

  • lidar_odometry_step_1 and mandeye_raw_data_viewer open .bag / .mcap files and Hesai captures (button, drag
    and drop, command line). A folder with bags and no LAZ/LAS files at its top level now opens as a bag recording.
  • lidar_odometry_step_1 --gui [<input>...] opens the GUI with the given inputs. Existing command lines are unchanged.
  • Step 1's loading window shows IMU and point cloud progress. A bz2-compressed bag gets a warning that decompressing it
    (rosbag decompress) makes loading much faster.
  • The raw viewer shows a "Nothing to show" window when a loaded recording has no points, no IMU samples, or no point
    within the IMU time span.
  • Windows: lz4, zstd and bzip2 are built from new submodules, so compressed MCAP files and ROS1 bags can be read there.
  • New submodules: 3rdparty/lz4, 3rdparty/zstd, 3rdparty/bzip2 (built on Windows only),
    3rdparty/HesaiLidar_SDK_2.0 for Hesai Support.
  • New developer script scripts/bag_loading_campaign.sh: a loading test over public recordings in every bag format.

Test plan

  • Linux: full build and ctest (5/5) on the rebased branch
  • scripts/run_check_clang_format.py passes
  • Underground Parking, single thread: step 1 result files byte-identical to main, lazy and eager (checked before
    the rebase onto Step 1: explain setup failures, check output folders, choose cache location #674 / Step 1: warn when data has several LiDARs but no calibration #677)
  • Underground Parking exported to MCAP / ROS1 bag and read directly: trajectory length matches the same MCAP
    converted back with mcap_to_laz
  • JT128 lidar_recorder session: step 1 loads the same 24.6 M points and 13,875 IMU samples from the pcaps as
    from the converted session, and runs through
  • XT32 + Murata session (.pcap.zstd chunks): hesai_pcap_to_laz converts three chunks, IMU from MURATA_IMU
  • CI: LIO golden trajectory unchanged on every platform
  • Windows: build; deploy_mandeye.bat finds hesai_pcap_to_laz.exe; step 1 opens a compressed MCAP and a bz2
    ROS1 bag
  • macOS: build (Hesai SDK with cmake/hesai_macos_compat)
  • GUI: open a bag / MCAP and a Hesai session in step 1 and in the raw viewer (button and drag and drop)
    🤖 Generated with Claude Code

@michalpelka
michalpelka requested a review from mwlasiuk December 2, 2026 18:10
@michalpelka
michalpelka marked this pull request as ready for review December 2, 2026 18:35
@michalpelka michalpelka changed the title Mp/hesai pcap to laz Suppor new datasources (MCAP, ROS1 Bags, Hesai PCAPs) Dec 2, 2026
@michalpelka michalpelka changed the title Suppor new datasources (MCAP, ROS1 Bags, Hesai PCAPs) Support new datasources (MCAP, ROS1 Bags, Hesai PCAPs) Dec 2, 2026
@michalpelka

Copy link
Copy Markdown
Contributor Author

Tested Hesai PCAP, ROS 1 and MCAP on Windows.

@mwlasiuk

mwlasiuk commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

@michalpelka

Will be testing this. Besides building and running applications on default hdmapping mandaye datasets I would also want to test these new source - where can I find datasets for testing?

@michalpelka

michalpelka commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

There is a bag testing campaign. Ping me directly, I can hand you some pcaps from Hesai. @mwlasiuk

@mwlasiuk

mwlasiuk commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Builds : Windows 11, MacOS, Ubuntu 24.04 all work fine.

Regarding tests on datasets - next.

michalpelka and others added 21 commits December 4, 2026 01:12
load_data() hard-coded the lidarNNNN.laz / imuNNNN.csv pairing, and the
lazy raw cloud loader re-read LAZ files by path. Both now go through
RecordingSource, so other recording formats (ROS1 bag, MCAP, Ouster
pcap) can be added as further sources without touching the pipeline.
The sources live in recording_sources/, shared by step 1 and the raw data
viewer.

- recording_sources/recording_source.h: the interface (working directory, time-ordered
  point chunks, change stamp, IMU stream), plus PointFilter and
  ChunkStamp. Imu and InputFileSpan move here from lidar_odometry.h.
- recording_sources/laz_csv_source: the existing folder loader, moved out of load_data
  unchanged (file sorting and pairing, calibration and serial-number
  checks, MURATA_IMU fallback).
- load_data(): the file-list overloads keep their signatures and wrap
  LazCsvSource; a new overload takes any RecordingSource.
- RawCloudLoader (moved to recording_sources/) holds the source instead
  of file paths; lazy_ensure /
  lazy_release become RawCloudLoader::ensure / release.

No behaviour change: single-threaded step 1 runs (taskset -c 0,
useMultithread = false) on the Underground Parking dataset give
byte-identical result files to main, lazy and eager.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158FTTEePKhmGqE9Z1HgwUd
The readers could only stream a whole file. Reading one time window on
its own is what a lazily loaded recording needs.

- McapFileReader::read and Ros1BagFileReader::read take an optional
  LogTimeRange [start_ns, end_ns); the default still reads everything.
  MCAP passes it to mcap's ReadMessageOptions, so the chunk index skips
  the rest. An indexed ROS1 bag decompresses only the chunks whose
  chunk info overlaps the range; an unindexed one is scanned whole.
- logTimeSpan() / Ros1BagReader::recordTimeSpan() report the first and
  last message time from the statistics record or the chunk index.
- The IMU rotation and acceleration-unit conversion of mcap_to_laz move
  to rosbags/ImuTransform.h for reuse; the converter is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158FTTEePKhmGqE9Z1HgwUd
A ROS1 bag or MCAP file no longer has to be converted with bag_to_laz /
mcap_to_laz before step 1 or the raw data viewer can read it.

- BagSource (recording_sources/bag_source.h/.cpp): a RecordingSource for both formats.
  Chunks are windows of message log time (10 s by default) read through
  the file's index, each with its own reader, so lazy and parallel
  loading work. Points keep the lidar frame (lidar id 0); IMU samples
  are rotated into the lidar frame and scaled to g, as the converters
  do. The working directory is the file's folder. Unindexed files are
  refused with a hint to reindex them.
- BagSourceConfigUi (recording_sources/bag_source_ui.h/.cpp): ImGui form that produces
  the BagSourceConfig: lidar and IMU topics from the file's channels
  (the only candidate preselected), PointCloud2 layout, IMU
  acceleration unit and rotation, chunk length.
- lidar_odometry_step_1: "Load & process ROS bag / MCAP" button and drag
  and drop open the form; the command line accepts a .bag/.mcap path
  and uses its only lidar and IMU topics.
- mandeye_raw_data_viewer: "Open ROS bag / MCAP" in the open menu and
  drag and drop.

Underground Parking exported with laz_to_mcap / laz_to_bag and read
directly gives the same trajectory as the same MCAP converted back with
mcap_to_laz (229.96 / 230.25 m against 230.36 m, single thread). The
difference from the original LAZ session (223.55 m) comes from the
export round trip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158FTTEePKhmGqE9Z1HgwUd
On Windows mcap was built with MCAP_COMPRESSION_NO_LZ4/NO_ZSTD and
rosbags/Ros1Bag compiled its chunk decompression out, so LZ4/Zstd MCAP
files and bz2/lz4 ROS1 bags could not be read there.

- 3rdparty/lz4 (v1.10.0), 3rdparty/zstd (v1.5.7), 3rdparty/bzip2
  (bzip2-1.0.8): shallow submodules.
- cmake/dependencies.cmake: on Windows, lz4_static, zstd_static and
  bz2_static are built from them; mcap and ros1bag_compression link them.
  Linux and macOS keep the system packages.
- Ros1Bag.cpp: the MCAP_COMPRESSION_NO_LZ4 guard around bz2/lz4 is gone.
- Test: an MCAP file with LZ4 and with Zstd chunks reads the same as the
  uncompressed one, on every platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158FTTCHMj7SBbPGtmCBJg8
…ader

The apps no longer pick an input type with if/else. Each RecordingSource
kind provides static name/accepts/open (and optionally priority,
configure, fileFilter) and registers itself with
HDMAPPING_REGISTER_RECORDING_SOURCE; RecordingSourceFactory::find(paths)
chooses the kind and the GUIs open whatever it returns.

- BagSource<Reader> is declared in bag_source.h; bag_source.cpp defines
  it and instantiates it for the ROS1 bag and MCAP readers. Its static
  acceptDroppedFile is specialized per reader (.bag / .mcap, files or
  folders searched recursively). is_bag_file is internal now.
- BagSourceConfigUi implements RecordingSourceConfigUi.
- recording_sources.cmake lists the source files shared by the apps.
- raw_cloud_loader moves back to lidar_odometry_step_1: it is step 1's
  chunk cache, not a recording source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dropping several .bag or .mcap files, or folders holding them (searched
recursively), opens them as one recording. The files are ordered by log
time and must be of one format and must not overlap; each file is split
into its own chunk windows. IMU samples come from every file, one span
per file. The topics and options chosen for the first file apply to all.
The working directory is the deepest folder holding every file.

A folder with Mandeye LAZ/LAS files at its top level stays a Mandeye
recording even when a bag sits below it. A folder with bags and no
LAZ/LAS files at its top level now opens as a bag recording (drag and
drop, and lidar_odometry_step_1 <folder>).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compressed bag can take minutes to load, most of it in the IMU pass,
which reads the whole recording on one thread.

- The rosbags readers report each message's log time (onProgress), and
  RecordingSource::loadImu passes the fraction read to a callback.
- load_data logs the IMU progress with time left every 2 s
  (ConsoleProgress), one line per point chunk, and the IMU sample count,
  and publishes the progress to LidarOdometryParams::load_progress.
- Step 1's "Loading data" window shows IMU and point cloud progress bars.
- Opening a bz2-compressed ROS1 bag prints a warning, also shown in the
  bag options window, that decompressing it (rosbag decompress) makes
  loading much faster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripts/bag_loading_campaign.sh downloads public lidar + IMU recordings
from Hugging Face and Zenodo, writes each one as MCAP (none, lz4, zstd),
ROS1 bag (none, bz2, lz4) and as a recording split into three files,
times lidar_odometry_step_1 loading every variant and checks that all
variants of a recording load the same points and IMU samples. Runs in
bash on Linux, macOS and MSYS2 (with the python.org Python on Windows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lidar_odometry_step_1 --gui [<input>...] opens the GUI even when inputs
are given; the inputs open as if dropped on the window (a bag opens its
options window). Without --gui the command line is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Some writers put a wrong "size" in the header of an uncompressed chunk
(the Livox ROS1 bags of Zenodo record 7780490 have size 1). The record
data is the chunk, and rosbag ignores the field too, so the reader no
longer rejects such chunks with "uncompressed chunk size mismatch", and
no longer allocates the claimed size before copying the data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…overy

- New recordings from Zenodo: Ouster OS0-32 and a Livox Mid-360, and with
  --large an Ouster OS0-64 and a Velodyne recorded from a drone (zip).
- Archives may be .tar.gz or .zip and may hold .bag or .mcap files.
- An MCAP file cut short (no footer, so no index, as the Mid-360 upload)
  is recovered into an indexed copy, as `mcap recover` does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… session

Converts Hesai captures (.pcap, or zstd-compressed .pcap.zst as
lidar_recorder writes them) into a mandeye session directory, like
mcap_to_laz and ouster_pcap_to_laz. A lidar_recorder session directory
stands for its lidarNNNN.pcap.zst chunks, and its gnssNNNN.nmea files are
copied next to the result.

- 3rdparty/HesaiLidar_SDK_2.0 (v2.0.11, shallow submodule) decodes the
  packets with the lidar's angle correction. It is built with
  BUILD_WITH_CLI_TOOLS only and without PTCS (no OpenSSL needed). On macOS
  cmake/hesai_macos_compat supplies <endian.h> and the Linux serial
  ioctls the SDK names.
- rosbags/PcapUdpReader: the pcap layer of OusterPcapReader (link types,
  IPv4 fragment reassembly) moved into its own class, which also reads
  zstd-compressed captures. OusterPcapReader uses it; its tests pass
  unchanged.
- rosbags/MandeyeSessionChunker: mcap_to_laz's chunking (absolute time
  bins, IMU samples routed into the chunk open at their time) as a class
  on top of MandeyeSessionWriter.
- Points keep the ring as the LAS "ring" attribute; IMU acceleration is in
  g and angular velocity is converted to rad/s, as mandeye_controller's
  Hesai client does.

Tested on a JT128 lidar_recorder session: the same 24.6 M points and
13,875 IMU samples as the prototype converter, and
lidar_odometry_step_1 runs through on the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new recording kind, "Hesai pcap", reads a lidar_recorder session (its
lidarNNNN.pcap.zst chunks) or a set of .pcap / .pcap.zst files, with the
lidar's angle correction (correction.dat next to them). Each file is one
chunk, decoded on its own, so chunks load in parallel and lazily.

- recording_sources/hesai_decoder: the Hesai SDK driver's packet loop,
  run synchronously on the caller's thread with its own UdpParser (no SDK
  threads). Frames are split at a new rotation, the origin "no return"
  points are dropped and the last partial frame is kept; IMU samples come
  from the point packets, in g and rad/s. The packet that selects the
  parser is decoded too, so a decoder per file loses no packet.
- loadImu reads all files with one decoder, so the sample repeated at a
  file boundary is dropped as within a file.
- hesai_pcap_to_laz uses the same decoder instead of the threaded SDK.
- The Hesai SDK is built for every configuration (it was CLI tools only);
  the macOS compatibility header is a source property of the two files
  that include SDK headers. Step 1 and the raw viewer link
  RECORDING_SOURCE_LIBRARIES.

Tested on a JT128 lidar_recorder session: step 1 loads 24,624,038 points
and 13,875 IMU samples straight from the pcaps (skip_first_file off),
the same as hesai_pcap_to_laz writes, and runs through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The converter no longer decodes Hesai packets or chunks the stream itself:
it opens its inputs with RecordingSourceFactory, as lidar_odometry_step_1
does, and writes each chunk's points (unfiltered) and the IMU samples
through MandeyeSessionWriter. Step 1 and the converter now read through
the same code, and any registered kind converts the same way.

- One output chunk per recording chunk (per .pcap.zst file for Hesai);
  --chunk-seconds, --correction and --udp-port are gone (correction.dat
  next to the files, as the source requires).
- No ring attribute (Point3Di has none) and no gnssNNNN.nmea copy.
- MandeyeSessionChunker, used only here, is removed.

Tested on a JT128 lidar_recorder session: 24,624,038 points and 13,875
IMU samples written, the same step 1 loads from the pcaps directly and
from the converted session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s none

A Mandeye unit with a Hesai lidar that has no IMU (or one the unit does
not use) logs the IMU itself, like a Livox recording: into imu****.csv,
or, with an external Murata IMU, into MURATA_IMU. When the first capture
carries no IMU samples, HesaiPcapSource now loads those files of the
recording folder instead of decoding the rest of the packets.

The loading is LazCsvSource's, moved into load_mandeye_imu() so both
sources share it; LazCsvSource behaves as before.

Tested on a Mandeye recording with a Pandar lidar and a Murata IMU
(10 pcaps, 79.7 M points, 58,058 Murata samples): hesai_pcap_to_laz
converts it and lidar_odometry_step_1 runs through on the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The viewer places points along the IMU trajectory, so a recording without
IMU samples, or whose points lie outside the IMU time span, loaded without
error and showed an empty view. A "Nothing to show" window now says why:
no points, no IMU samples, or no point within the IMU time span (with both
time ranges, as the LiDAR and the IMU may be on different clocks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lidar_recorder names its compressed chunks lidarNNNN.pcap.zstd, but the
Hesai source looked only for .pcap and .pcap.zst. A session folder was
then opened by the Mandeye LAZ/CSV kind, which accepts any folder: it
loaded the MURATA_IMU samples, found no LAZ files, and step 1 failed
with "Odometry failed".

is_hesai_capture() now accepts .pcap, .pcap.zstd and .pcap.zst, and is
used both for single files and by hesai_recorder_chunks(), so the two
cannot disagree. The reader already detects zstd by its magic number.

Tested on a lidar_recorder session with an XT32 and a Murata IMU: three
of its .pcap.zstd chunks convert with hesai_pcap_to_laz (25.9 M points,
the IMU from MURATA_IMU).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The line moved one indentation level up into load_from_source during the
rebase onto main, and clang-format 21 wraps it differently there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_clang_format.py and run_check_clang_format.py (CI) now cover
rosbags/ and recording_sources/; scripts/README.md lists them. rosbags/
is reformatted with clang-format 21, whitespace and line wrapping only,
no include reordered. recording_sources/ was already formatted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The zstd test of PcapUdpReader read the plain capture through an
ifstream that stayed open until the end of the test case, so removing
the file threw on Windows ("being used by another process") and the
test failed there. Linux allows removing an open file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…indows

mcap::FileReader seeks with fseek((long)offset) and sizes the file with
ftell. long is 32 bits on Windows, so past 2 GB it reads from the wrong
offset, takes garbage as a record length and throws std::bad_alloc
(seen in lidar_odometry_step_1 loading a large .mcap). Open the file as
a std::ifstream and use mcap's stream reader, whose offsets are 64-bit.
Opening from std::filesystem::path also handles non-ASCII paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michalpelka

Copy link
Copy Markdown
Contributor Author

@JanuszBedkowski
JanuszBedkowski merged commit 48e4d0e into MapsHD:main Dec 4, 2026
7 checks passed
@michalpelka

Copy link
Copy Markdown
Contributor Author

@JanuszBedkowski code was under review during your merge.

@JanuszBedkowski

Copy link
Copy Markdown
Member

I reviewed it , it is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants