Skip to content
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

[draft] switch wpical backend to gtsam #7606

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

mcm001
Copy link
Contributor

@mcm001 mcm001 commented Dec 29, 2024

Draft MR switching the wpical backend from ceres to GTSAM via the photonvision thirdparty repo.

Blocked on #7796

@github-actions github-actions bot added the component: wpimath Math library label Dec 29, 2024
@mcm001 mcm001 force-pushed the mmorley/wpical-gtsam branch 3 times, most recently from 6f2a99d to d34b60f Compare December 29, 2024 17:35
Comment on lines +181 to +183
it.cppCompiler.args.add("-Wno-deprecated-copy")
it.cppCompiler.args.add("-Wno-redundant-move")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should probably fix these upstream instead

Comment on lines 154 to 97
inline cameracalibration::CameraModel load_camera_model(wpi::json json_data) {
inline CameraModel load_camera_model(wpi::json json_data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function feels like it doesn't belong in fieldcalibration code?

struct Pose3WithVariance {
frc::Pose3d pose;
// in order rx ry rz tx ty tz. Units are SI units
std::array<double, 6> covariance;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

member is named covariance but holds variance? swap to cov


struct TagDetection {
int32_t id;
std::vector<TargetCorner> corners;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

always 4 corners - consider an array

return worldTtags;
}

static std::vector<Point3> MakeTagModel(double width) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

consider templating this

Comment on lines +28 to +31
// cv::Mat R;
// cv::Rodrigues(rvec, R); // R is 3x3
// R = R.t(); // rotation of inverse
// cv::Mat tvecI = -R * tvec; // translation of inverse
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dead code

Copy link
Contributor

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

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

Since we're not in a rush for this, and I know you want some of calibration things in here, considering splitting wpical into app and lib directories like Glass, so you can have a libwpical you can pull in.

@mcm001
Copy link
Contributor Author

mcm001 commented Dec 29, 2024

I was trying to keep the diff small, but now that wpical is in main im less scared about merge conflicts unless @ElliotScher is planning a similar refactor already?

@ElliotScher
Copy link
Contributor

ElliotScher commented Dec 30, 2024

I wasn't planning on it yet, but I can if it would help.

@mcm001
Copy link
Contributor Author

mcm001 commented Dec 30, 2024

I don't think it would - I think it makes more sense here to swap out the bones and fight the build system, then we can think about other plans? The wpical docs PR going in and getting some user feedback post kickoff seem like plenty of work to me

@spacey-sooty

This comment was marked as outdated.

@spacey-sooty spacey-sooty force-pushed the mmorley/wpical-gtsam branch 2 times, most recently from cb0027d to 41dc097 Compare December 30, 2024 11:49
Copy link
Contributor

@Gold856 Gold856 left a comment

Choose a reason for hiding this comment

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

wpical needs _ENABLE_EXTENDED_ALIGNED_STORAGE to be defined. Confirmed this is defined in gtsam's CMake build.

@mcm001
Copy link
Contributor Author

mcm001 commented Jan 15, 2025

Why does it need it?

@mcm001 mcm001 force-pushed the mmorley/wpical-gtsam branch from 41dc097 to 7626e6e Compare March 18, 2025 03:19
@mcm001 mcm001 force-pushed the mmorley/wpical-gtsam branch from 7626e6e to 230efdf Compare March 18, 2025 03:20
crueter and others added 6 commits March 17, 2025 20:31
The problem was ill-conditioned if either semiaxis had zero length.
…e#7850)

Throughout the code the state sqrt covariance S and innovation covariance Sy are maintained as upper triangular cholesky factors of those covariance matrices. The original paper defines P=S*S', so S should be lower triangular. The functions in the paper reflect this. In the code implementation, the sqrt covariance matrices are upper triangular, but the algorithm expects them to be lower triangular.

This bug was likely missed because the incorrect version of the filter is able to converge for some systems where all the states are observed, and the test case is set up such that all states are observed.

To fix the bug, a couple things needed to be changed:
all instances of rankUpdate() needed to be changed to use the lower triangular cholesky factor,
In the unscented transform, when S is found via QR decomposition, we need to take the transpose because R is upper triangular,
P() and SetP() functions need to be modified to be P=S*S' instead of P=S'*S, and P.llt().matrixL() instead of P.llt().matrixU() respectively.

Each part of the algorithm has also had the comments changed to clarify exactly which equation from the paper it implements.

Co-authored-by: Tyler Veness <[email protected]>
@mcm001 mcm001 force-pushed the mmorley/wpical-gtsam branch from 230efdf to 66216a6 Compare March 18, 2025 03:32
@github-actions github-actions bot added the component: wpiutil WPI utility library label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants