Repository navigation
feat: public fields for the ego position covariance and a route's start pose - #25
Conversation
…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
left a comment
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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
τ Ihas 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_ruleruns six matrices around the tolerance through both decoders, including your two, and reanchors the accepted ones.generator_testingests your first matrix, blends it with another message and validates the defaultbuild_range()export.- For your second matrix, the generator test checks that the covariance is dropped and the pose is kept.
|
|
||
| def _validate_covariances(value): | ||
| values = np.ma.asarray(value) | ||
| masks = np.ma.getmaskarray(values).reshape(len(values), -1) |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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)).
| 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 = ( |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
Fixed in ef85c7c. The new optional fields are now the last members of their records:
- Python:
EgoStatus,EgoSequence,T4Scene(T4Frame.start_pose_3dwas already last). - C++:
EgoStatus,T4Scene,T4Frame(EgoSequence.position_covariances_3dwas 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>
xtk8532704
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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 ofR 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 earlier1e-9was 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; |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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>
xtk8532704
left a comment
There was a problem hiding this comment.
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])); |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
Summary
Closes #24.
A Scene can now carry two observations that Autoware publishes and that had no public place:
EgoSequence.position_covariances_3d[T,3,3]T4Scene.start_poses_3d[T,4,4]Both are optional and use new Protobuf field numbers (
EgoSequence15,T4Scene15), 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.
RouteData. It mirrorsgoal_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 ofRouteDatait would make the route table depend on the Scene frame, which it does not today.Semantics
Position covariance
validate()and in the checked codecs.Rit becomesR 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_3dis the row of one frame.Route start pose
T4Scene.start_pose_3dandT4Frame.start_pose_3dread the current row and one frame.startis a new consumer requirement name, besidegoal.ROS2 generator
nav_msgs/Odometry.pose.covarianceLaneletRoute.start_poseNo profile setting is added: both follow the existing
odometryandrouteinputs.Tests
t4scene/python/tests)t4scene/cpp/tests)records_test.cpp, and both fields in the Protobuf round tript4scene/tests)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