Skip to content

feat: public fields for the ego position covariance and a route's start pose - #25

Merged
xtk8532704 merged 5 commits into
mainfrom
feat/position-covariance-route-start
Dec 2, 2026
Merged

xtk8532704 merged 5 commits into
mainfrom
feat/position-covariance-route-start

Conversation

@Max-Bin

@Max-Bin Max-Bin commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #24.

A Scene can now carry two observations that Autoware publishes and that had no public place:

Field Shape Meaning
EgoSequence.position_covariances_3d float64 [T,3,3] Covariance of the ego position in Scene axes, m²
T4Scene.start_poses_3d float64 [T,4,4] Start-to-Scene transform of the route each row follows

Both are optional and use new Protobuf field numbers (EgoSequence 15, T4Scene 15), so existing Scenes read unchanged.

Design choices

Two questions from #24 that I had to settle to write this. Both are easy to change if you prefer the other answer.

  • The route start is a per-row column, not a field of RouteData. It mirrors goal_poses_3d, so validation, slicing, frame access and reanchoring reuse the existing pose-column code in both languages, including masks and tensors. As a field of RouteData it would make the route table depend on the Scene frame, which it does not today.
  • Position block only. The orientation block of a 6×6 pose covariance has its own frame conventions and no consumer yet.

Semantics

Position covariance

  • Symmetric positive semidefinite. A row is fully known or fully masked. Both SDKs check this in validate() and in the checked codecs.
  • Under a change of Scene axes by a rotation R it becomes R C Rᵀ. reanchor() does this in Python (NumPy, masked arrays, tensors) and in C++, so the eigenvalues do not depend on the anchor.
  • EgoStatus.position_covariance_3d is the row of one frame.

Route start pose

  • Same conventions as a goal pose: a rigid transform, whole rows may be masked.
  • T4Scene.start_pose_3d and T4Frame.start_pose_3d read the current row and one frame.
  • start is a new consumer requirement name, beside goal.

ROS2 generator

Source Rule
nav_msgs/Odometry.pose.covariance The upper-left 3×3 block, which is expressed in the Scene frame. A row interpolated between two messages takes the same weighted mean of their covariances as of their positions; a convex combination of covariances is a covariance.
A covariance that is all zero, not finite, not symmetric or not positive semidefinite Unknown for that message. The pose is still used.
A source that never reports a covariance The column is left out.
LaneletRoute.start_pose Read like the goal. A start pose whose orientation is not a unit quaternion is unknown; the route and its goal are still used.

No profile setting is added: both follow the existing odometry and route inputs.

Tests

Suite Result
Python (t4scene/python/tests) 321 passed, 8 skipped; two new files, 18 tests
C++ core (t4scene/cpp/tests) 4 of 4; two new scenarios in records_test.cpp, and both fields in the Protobuf round trip
Python/C++ exchange (t4scene/tests) 35 passed; both fields in the round trip, the slice and the reanchor comparison, and four new invalid cases that both decoders reject
ROS2 generator, C++ 1 of 1; a new scenario for sampled, interpolated and unknown covariances and for known and unknown start poses
ROS2 generator, Python 35 passed; the all-inputs bag test asserts both fields and that a replay from the bag is identical

I built and ran these in a conda environment with ROS Humble packages, not in the CI images, so CI is the reference.

Documentation

The component READMEs for the wire format, the Python and C++ SDKs and the generator inputs describe both fields, and the changelog has an entry under Unreleased.

🤖 Generated with Claude Code

Max-Bin and others added 2 commits December 2, 2026 16:07
…rt pose

A Scene could say that an ego pose is missing but not how well it was localised, and it
held a route's goal and lanes but not where the route starts. Producers that needed
either had to carry it in model_data.

EgoSequence.position_covariances_3d is [T,3,3] in Scene axes and m^2: symmetric positive
semidefinite, a row fully known or fully masked, and R C R^T under a change of Scene
axes. T4Scene.route_start_poses_3d is [T,4,4] start-to-Scene transforms, with the
conventions of goal_poses_3d. Both are optional and use new Protobuf field numbers.

Python and C++ records, validation, slicing, frame access and reanchoring handle both,
and route_start is a consumer requirement name. The ROS2 generator fills them from
nav_msgs/Odometry.pose.covariance and LaneletRoute.start_pose.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…es_3d

The column, its frame and Scene accessors and the consumer requirement take the names of
their goal counterparts: start_poses_3d, start_pose_3d and "start".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@xtk8532704
xtk8532704 self-requested a review December 2, 2026 09:06

@xtk8532704 xtk8532704 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the three issues below before merging. I reproduced them on this revision with the checked Python/C++ codecs, the ROS2 range generator, and the public SDK constructors.

for (unsigned j = i + 1; j < 3; ++j)
require(std::abs(c[3 * i + j] - c[3 * j + i]) <= tolerance,
"position covariance must be symmetric");
const double xy = c[0] * c[4] - c[1] * c[1], xz = c[0] * c[8] - c[2] * c[2],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Use the same covariance validation rule in the producer and both SDKs. The tolerances on principal minors and the determinant here give different results from the eigenvalue checks in Python and ROS2. A matrix with unit diagonal and every off-diagonal entry set to -0.5000000004 passes Python validation and ROS2 ingestion, then fails C++ decoding and the default build_range() export. The reverse also occurs. A matrix with Czz = 1, Cxy = Cyx = 1e-5, and all other entries zero passes the checked C++ round trip, then fails checked Python decoding. Please use one symmetry and positive-semidefiniteness rule with a shared tolerance, and cover both cases in the exchange tests. The generator should preserve the odometry pose when it marks an unusable covariance as missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ef85c7c. Both of your cases reproduced, and both SDKs now give the same answer for them.

There is one rule now, written out in t4scene/proto/README.md. With τ = 1e-9 · (1 + |trace C|):

  • Symmetric: the differences of the three pairs of mirrored entries have a Euclidean norm of at most τ.
  • Positive semidefinite: the symmetric part plus τ I has a Cholesky factor, so every eigenvalue is above -τ.

Python (covariance_faults) and C++ (scene_detail::covariance_fault) run the same arithmetic, and the generator calls the C++ function instead of its own eigenvalue check.

The first version of this fix kept a per-entry symmetry tolerance, and the new exchange test caught that a matrix could pass and then fail after reanchor(). The tolerance is therefore built from the trace and the norm of the antisymmetric part, which do not change under a rotation, and the trace is linear, so a weighted mean of two valid covariances is valid. That is what lets the generator promise that a covariance it keeps can be exported.

Tests:

  • test_both_sdks_apply_one_covariance_rule runs six matrices around the tolerance through both decoders, including your two, and reanchors the accepted ones.
  • generator_test ingests your first matrix, blends it with another message and validates the default build_range() export.
  • For your second matrix, the generator test checks that the covariance is dropped and the pose is kept.

Comment thread t4scene/python/t4scene/data/ego.py Outdated

def _validate_covariances(value):
values = np.ma.asarray(value)
masks = np.ma.getmaskarray(values).reshape(len(values), -1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Handle a window with no available ego observations. A Scene built with EgoSequence.from_statuses([None, EgoStatus(position_covariance_3d=np.eye(3))]) validates as a whole. When its first row is the anchor, both slice_time(0, 1).validate() and checked from_proto(..., rows=(0, 1)) raise ValueError because filtering on available leaves zero rows and NumPy cannot infer the second dimension in reshape(0, -1). Reshape to a fixed width of 9 or reduce over the last two axes so the window remains readable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ef85c7c: the mask is reshaped to a fixed width of 9, so a selection of zero rows validates. test_a_window_without_an_ego_observation_stays_readable covers your example with both slice_time(0, 1).validate() and checked from_proto(..., rows=(0, 1)).

Comment thread t4scene/python/t4scene/data/ego.py Outdated
ego_velocity_3d: Array | None = None # [3], Scene vx/vy/vz, m/s.
ego_acceleration_3d: Array | None = None # [3], Scene ax/ay/az, m/s².
angular_velocity_3d: Array | None = None # [3], Scene angular velocity, rad/s.
position_covariance_3d: Array | None = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve existing positional constructors and aggregate initialization. On the base revision, EgoStatus(None, None, None, None, 0.25) sets tire_steering_angle. This revision puts that value into position_covariance_3d and validation fails. The equivalent C++ aggregate initializer fails to compile. Inserting fields also shifts existing arguments in Python EgoSequence and T4Scene and existing aggregate members in C++ T4Scene and T4Frame. Please append the new optional fields after the existing fields in those public records.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ef85c7c. The new optional fields are now the last members of their records:

  • Python: EgoStatus, EgoSequence, T4Scene (T4Frame.start_pose_3d was already last).
  • C++: EgoStatus, T4Scene, T4Frame (EgoSequence.position_covariances_3d was already last).

EgoStatus(None, None, None, None, 0.25) sets tire_steering_angle again, and the C++ aggregate initializer compiles; both are in the tests.

…ome last

- The position covariance is checked by one rule in Python, C++ and the ROS2
  generator: finite; the mirrored differences have a norm of at most tau; the
  symmetric part plus tau*I has a Cholesky factor, tau = 1e-9 * (1 + |trace|).
  The answer does not depend on the Scene axes and holds for a weighted mean,
  so every covariance the generator keeps can be exported and reanchored.
- A window with no available ego observation validates.
- The new optional fields are the last members of EgoStatus, EgoSequence,
  T4Scene and T4Frame, so positional construction keeps its meaning.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Max-Bin
Max-Bin requested a review from xtk8532704 December 2, 2026 09:50

@xtk8532704 xtk8532704 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified the original covariance cases, the empty ego window, and the restored positional argument order on this revision. Please address the two remaining issues reproduced below.

"""``R C R^T`` for [..., 3, 3] covariances: rotate the columns, then the rows."""
if values is None:
return None
values, rotation = self.local_pair(values, self.to_old[:3, :3].T)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep valid float32 covariances serializable after reanchoring. A Scene with a torch.float32 covariance of diag(1, 0, 1) passes a checked Protobuf round trip. After scene.reanchor((0, 0, 0.6)), float32 roundoff makes its smallest eigenvalue about -2.25e-8, and to_proto() rejects it as indefinite. A full-rank example with unit diagonal and Cxy = 0.2, Cxz = 0.1, Cyz = 0.3 and their mirrored entries also fails the symmetry check after a yaw of 0.1. Please account for both types of roundoff in the covariance transform and add a float32 regression that exercises reanchoring through checked serialization while preserving tensor device and gradient behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 06893dc. Both of your float32 cases reproduced with a torch.float32 tensor (a NumPy float32 array is promoted to float64 by reanchor() and was not affected).

Two changes, one for each kind of roundoff:

  • Symmetry: reanchor() now returns the symmetric part of R C Rᵀ, so mirrored entries are equal exactly, in any dtype.
  • Smallest eigenvalue: the rule's tolerance is now 1e-6 · (1 + |trace C|), the tolerance the pose checks already use, in both SDKs and the generator. The earlier 1e-9 was below float32 resolution, so no transform could keep a rank-deficient float32 covariance inside it.

test_float32_covariances_stay_serializable_under_new_anchors runs both of your matrices through 20 chained reanchors with a checked Protobuf round trip after each, and asserts that the result is still a float32 tensor on the same device with its gradient. As a margin check, over 20 chains of 200 random float32 reanchors of diag(1, 0, 1) the smallest eigenvalue used at most 21% of the tolerance.

The exchange test's boundary cases moved with the tolerance. Your two cases from the first review keep their answers in both SDKs: the -0.5000000004 matrix is accepted and the Cxy = 1e-5 matrix is rejected.

steering_wheel_timestamp_ns, turn_indicator_timestamp_ns;
std::optional<EgoShape> ego_shape;
// float64 [3,3], covariance of the ego position in Scene axes, m^2.
std::optional<Array<double>> position_covariance_3d;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Default-initialize the appended aggregate members. An existing positional initializer that supplies every original member of EgoStatus or T4Frame compiles on the base revision with GCC and -Werror=missing-field-initializers. On this revision, the same code fails because the appended position_covariance_3d and start_pose_3d members lack default member initializers. I verified that adding {} to both declarations makes the original code compile under the same flag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 06893dc: EgoStatus::position_covariance_3d and T4Frame::start_pose_3d have {} default member initializers. I reproduced the error with GCC and -Werror=missing-field-initializers on the previous revision (positional initializers naming every base-revision member of both records) and the same code compiles on this one. records_test.cpp now contains those two initializers.

…nded members

- reanchor() returns the symmetric part of R C R^T, and the covariance rule's
  tolerance is that of the pose checks, 1e-6 * (1 + |trace|), in both SDKs and
  the generator: a float32 covariance stays serializable through chained
  reanchors, with its tensor dtype, device and gradient.
- The appended members of the C++ EgoStatus and T4Frame have default
  initializers, so a positional initializer of the earlier members is complete.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Max-Bin
Max-Bin requested a review from xtk8532704 December 2, 2026 10:06

@xtk8532704 xtk8532704 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both float32 reanchor reproductions now pass checked serialization, and the original C++ aggregate initializers compile with the strict warning flag. Please address the two remaining covariance issues below.

for (unsigned i = 0; i < 9; ++i)
if (!std::isfinite(c[i]))
return "position covariance must be finite";
const double tau = 1e-6 * (1 + std::abs(c[0] + c[4] + c[8]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep negative variances out of checked Scenes. The new trace-scaled tolerance is about 1 m² for diag(-0.5, 0.04, 1e6). I reproduced the default ROS2 build_range() export retaining the X variance of -0.5 m² as known. The checked Python and C++ codecs also round-trip it, and a consumer taking the square root of the X variance gets NaN. The large Z variance allows a materially negative value on an independent axis. Please handle float32 transform roundoff on the reanchor path and have shared validation and ROS2 ingestion reject this covariance while retaining the odometry pose.

@Max-Bin Max-Bin Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing 21fc754. It restores the 1e-9 · (1 + |trace C|) tolerance and handles the float32 rounding in the rotation, so diag(-0.5, 0.04, 1e6) is rejected and the float32 reanchor cases still serialize. I had prepared a fix for the same two points locally and have dropped it in favour of yours; the branch head is your commit, and CI is green on it.

(An earlier version of this reply named a local commit of mine that was never pushed. Please disregard it.)


// R C R^T for [T,3,3] covariances: rotate each row's x/y pair, then each
// column's. Masks follow the same dependencies as a rotated vector.
void covariances(std::optional<Array<double>> &field) const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Apply the same covariance reanchor rule in both SDKs. I passed the same checked Protobuf input to both SDKs with unit diagonal, Cxy = 2e-6, Cyx = 0, and all other off-diagonal entries zero. After reanchor((0, 0, 0)), Python produces (Cxy, Cyx) = (1e-6, 1e-6), while C++ returns (2e-6, 0). The wire guide specifies the symmetric part of the rotated covariance. Please apply the same rule in C++ and Python and add a within-tolerance asymmetric input to the reanchor exchange test.

@Max-Bin Max-Bin Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, 21fc754 covers this: both SDKs now keep the symmetric part of R C Rᵀ, and the exchange test has the asymmetric input. I dropped my local change for the same point in favour of yours.

(An earlier version of this reply named a local commit of mine that was never pushed. Please disregard it.)

Restore the shared position covariance tolerance and handle float32 rounding in the rotation that introduces it. Return symmetric reanchored covariances in both SDKs and cover the negative-variance ROS2 export and asymmetric input exchange cases.
@Max-Bin
Max-Bin requested a review from xtk8532704 December 2, 2026 11:15
@xtk8532704
xtk8532704 merged commit 79d64c3 into main Dec 2, 2026
7 checks passed
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.

Public fields for the ego position covariance and a route's start pose

2 participants