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

Test body_P_sensor in SmartFactor #379

Merged
merged 7 commits into from
Jul 10, 2020

Conversation

varunagrawal
Copy link
Collaborator

@varunagrawal varunagrawal commented Jul 7, 2020

Addresses #20.


This change is Reviewable

@varunagrawal varunagrawal added the bugfix Fixes an issue or bug label Jul 7, 2020
@varunagrawal varunagrawal requested review from ProfFan and dellaert July 7, 2020 23:26
@varunagrawal varunagrawal self-assigned this Jul 7, 2020
Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

So, the only thing that really changed was adding a test? just checking

@@ -206,11 +206,12 @@ class SmartFactorBase: public NonlinearFactor {
boost::optional<Matrix&> E = boost::none) const {
Vector ue = cameras.reprojectionError(point, measured_, Fs, E);
if (body_P_sensor_ && Fs) {
const Pose3 sensor_P_body = body_P_sensor_->inverse();
const Pose3 sensor_T_body = body_P_sensor_->inverse();
Copy link
Member

Choose a reason for hiding this comment

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

Please keep P, as the field uses that convention

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gotcha. I was trying to follow the convention as per Samarth's post. Reverted.

@varunagrawal
Copy link
Collaborator Author

@dellaert pretty much. The original issue asked for a test so decided it was easy enough to do so (aka unit tests are my friends).

@varunagrawal varunagrawal requested a review from dellaert July 10, 2020 09:49
@varunagrawal
Copy link
Collaborator Author

So unit testing won this round. Discovered a bug in the handling of the jacobian for cases such as PinholeCamera<Cal3Bundler> where the number of parameters is 9 instead of the usual 6.

Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Wow, good find! Some style comments, and you should always uses stack-allocated static Matrices when possible (big performance impact).

@@ -207,10 +207,17 @@ class SmartFactorBase: public NonlinearFactor {
Vector ue = cameras.reprojectionError(point, measured_, Fs, E);
if (body_P_sensor_ && Fs) {
const Pose3 sensor_P_body = body_P_sensor_->inverse();
size_t camera_dim = size_t(traits<CAMERA>::dimension);
Copy link
Member

Choose a reason for hiding this comment

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

Use constexpr int, no casting

Matrix J(6, 6);
const Pose3 world_P_body = w_Pose_body.compose(*body_P_sensor_, J);
const Pose3 world_P_body = cameras[i].pose() * sensor_P_body;
Matrix J = Matrix::Zero(camera_dim, camera_dim);
Copy link
Member

Choose a reason for hiding this comment

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

Why switch to dynamic? Make static, use setZero(), save a malloc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gotcha. It was already dynamic for some reason so was trying not to inadvertently introduce any bugs.

Matrix H(pose_dim, pose_dim);
world_P_body.compose(*body_P_sensor_, H);
// Assign extrinsics
J.block(0, 0, pose_dim, pose_dim) = H;
Copy link
Member

Choose a reason for hiding this comment

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

You can just pass the block into the optionalJacobian slot. Amazing, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried doing that but it was complaining about something (which I don't remember right now). I am guessing it will fix itself with static matrices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So as per this link, casting an Eigen::Block expression to a non-const Matrix is not possible.

Quoting the specific line:

When trying to execute the following code

MatrixXf C = MatrixXf::Zero(3,6);
cov(x,y, C.block(0,0,3,3));

the compiler will fail, because it is not possible to convert the expression returned by MatrixXf::block() into a non-const MatrixXf&. This is the case because the compiler wants to protect you from writing your result to a temporary object.

Copy link
Member

Choose a reason for hiding this comment

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

Is the same true for fixed matrices, though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like it. I am having compile time issues otherwise, specifically signature mismatch. This is the best explanation since we're trying to convert a block expression to a non-const matrix as a requirement.

eigen_error

@varunagrawal varunagrawal merged commit 5dd1c8e into develop Jul 10, 2020
@varunagrawal varunagrawal deleted the fix/smartfactor_body_P_sensor branch July 10, 2020 23:39
@ProfFan ProfFan mentioned this pull request Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes an issue or bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants