-
Notifications
You must be signed in to change notification settings - Fork 0
fix(bag): use ROS1 alignment rules for headerless BAG message decoding #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The previous fix (d198484) changed from decode_ros1 to decode_headerless to avoid skipping 16 bytes of message data. However, decode_headerless sets is_ros1=false, which causes the decoder to use ROS2-style alignment for primitive arrays. This caused decoding failures for ROS1 BAG files with messages containing primitive arrays (e.g., kuavo_msgs/sensorsData), resulting in errors like: "Array length 756369941 exceeds maximum allowed 10000000" The fix adds a new decode_headerless_ros1 function that: - Starts from byte 0 (no header skip) - Uses ROS1 alignment rules (is_ros1=true) This ensures primitive arrays are decoded correctly for ROS1 BAG messages. Fixes #26
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile OverviewGreptile SummaryThis PR correctly fixes ROS1 BAG message decoding by introducing a new Key Changes:
Technical Context: The Fix: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant BAG as BagDecodedMessageStream
participant DEC as CdrDecoder
participant CUR as CdrCursor
Note over BAG,CUR: ROS1 BAG Message Decoding Flow
BAG->>BAG: next() - get raw message
Note over BAG: BAG parser extracts CDR data<br/>(no headers, just message bytes)
BAG->>DEC: decode_headerless_ros1(schema, data, type)
Note over DEC: Use ROS1 alignment rules
DEC->>CUR: new_headerless_ros1(data, little_endian=true)
Note over CUR: Create cursor with:<br/>- offset=0, origin=0<br/>- is_ros1=true
CUR-->>DEC: cursor
DEC->>DEC: execute_plan(plan, cursor, schema)
loop For each primitive array
DEC->>DEC: read_array(cursor, element_type, count)
alt is_ros1 == true
Note over DEC,CUR: ROS1: Skip alignment<br/>(contiguous storage)
DEC->>CUR: read elements without alignment
else is_ros1 == false
Note over DEC,CUR: ROS2: Apply alignment<br/>(aligned to element size)
DEC->>CUR: align(elem_size)
DEC->>CUR: read elements with alignment
end
end
DEC-->>BAG: DecodedMessage
Note over BAG,CUR: Key Fix: is_ros1=true prevents<br/>incorrect ROS2 alignment in<br/>ROS1 primitive arrays
|
…vior - Rename \`convert\` command to \`rewrite\` to clarify it doesn't change formats - Simplify CLI interface: \`rewrite <input> <output>\` (no subcommands) - Keep cross-format protection with helpful error message The \`convert to-mcap\` and \`convert to-bag\` commands were misleading as they suggested format conversion capability that doesn't exist. The new \`rewrite\` command accurately describes what it does: rewrites a file in the same format. Fixes #33
Since cursor.align() already handles the ROS1 check internally, the wrapper checks in execute_plan(), read_time(), and read_duration() were redundant. Removed them for cleaner, more maintainable code.
- Remove unused parse_schema and FormatReader imports - Use for loop instead of while let on iterator
Problem
The previous fix (d198484) changed from
decode_ros1todecode_headerlessto avoid skipping 16 bytes of message data. However,decode_headerlesssetsis_ros1=false, which causes the decoder to use ROS2-style alignment for primitive arrays.This caused decoding failures for ROS1 BAG files with messages containing primitive arrays (e.g.,
kuavo_msgs/sensorsData), resulting in errors like:Root Cause
The
is_ros1flag controls alignment behavior for primitive arrays:When
is_ros1=false, the decoder applies ROS2-style alignment, which causes it to read garbage values as array lengths when processing ROS1 BAG data.Solution
Added a new
decode_headerless_ros1function that:is_ros1=true)This ensures primitive arrays are decoded correctly for ROS1 BAG messages.
Changes
CdrCursor::new_headerless_ros1()- creates cursor withis_ros1=trueCdrDecoder::decode_headerless_ros1()- uses ROS1 alignment for decodingBagDecodedMessageStreamto usedecode_headerless_ros1()Testing
Tested with Leju robot BAG file (
Rubbish_sorting_P4-278_20250830101814.bag) which contains ~487K messages with complex nested types including primitive arrays.Fixes #26