Subtraction operator for Inertial class #432
Conversation
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
|
please add tests to Inertial_TEST.cc |
|
Based on the initial testing of After implementation it seems like we might be able to piggy bank on the |
Also, one small thing though that since Inertial objects will be passed as const in |
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
include/gz/math/Inertial.hh
Outdated
| public: Inertial<T> &operator-=(const Inertial<T> &_inertial) | ||
| { | ||
| MassMatrix3<T> _mass_matrix_copy(-_inertial.MassMatrix().Mass(), | ||
| -_inertial.MassMatrix().DiagonalMoments(), -_inertial.MassMatrix().OffDiagonalMoments()); |
There was a problem hiding this comment.
I'm not sure this is correct. This MassMatrix object contains invalid inertias
There was a problem hiding this comment.
I guess the MassMatrix object is invalid on it's own but the reason for doing this was to make it work with +operator.
Inside +operator this is what happens:
auto moi = this->Moi() + _inertial.Moi();
What we want for -operator is this:
auto moi = this->Moi() - _inertial.Moi();
So we make the _inertial.Moi() negative before sending it to +operator
There was a problem hiding this comment.
I can also have a separate implementation for -=operator if this creates confusion.
There was a problem hiding this comment.
I think it would be better to have a separate -=operator implementation
src/Inertial_TEST.cc
Outdated
| const math::Vector3d size(1, 1, 1); | ||
| math::MassMatrix3d cubeMM3; | ||
| EXPECT_TRUE(cubeMM3.SetFromBox(mass, size)); | ||
| const math::Inertiald cube(cubeMM3, math::Pose3d::Zero); |
There was a problem hiding this comment.
I think you could add expectations for the - operator in the Addition test instead of duplicating everything here. The test could be renamed as AdditionSubtraction
There was a problem hiding this comment.
yeah, makes sense. I was also thinking to add some more unit tests for subtraction operator different from addition operator. Should I add them as well inside AdditionSubtraction
There was a problem hiding this comment.
I think the tests can be shared in most cases. Anywhere that you would test a + b == c, you can also test c - a == b and c - b == a and it would prevent a lot of duplicated code
…usion Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
src/Inertial_TEST.cc
Outdated
| EXPECT_EQ(left, tmp); | ||
| } | ||
| { | ||
| math::Inertiald tmp = right; |
There was a problem hiding this comment.
yeah. Let me check real quick. Sorry about that.
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
|
are you up for adding this to the python bindings as well? |
yes, I can do that as well. |
I am currently in the middle of another issue, so I will start on this by tomorrow. |
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
@scpeters I have added the python binding and unit test as well. Thanks! |
| math::MassMatrix3d trueCubeMM3; | ||
| EXPECT_TRUE(trueCubeMM3.SetFromBox(8*mass, 2*size)); | ||
| EXPECT_EQ(addedCube, math::Inertiald(trueCubeMM3, math::Pose3d::Zero)); | ||
| EXPECT_EQ(lastCube, addedCube - sevenCubes); |
There was a problem hiding this comment.
nit: let's add EXPECT_EQ(sevenCubes, addedCube - lastCube); as well
| math::MassMatrix3d trueCubeMM3; | ||
| EXPECT_TRUE(trueCubeMM3.SetFromBox(8*mass, 2*size)); | ||
| EXPECT_EQ(addedCube, math::Inertiald(trueCubeMM3, math::Pose3d::Zero)); | ||
| EXPECT_EQ(lastCube, addedCube - sevenCubes); |
There was a problem hiding this comment.
add EXPECT_EQ(sevenCubes, addedCube - lastCube); as well
src/Inertial_TEST.cc
Outdated
| EXPECT_EQ( | ||
| math::Pose3d(-0.5, -0.5, -0.5, 0, 0, 0), | ||
| (diagonalCubes - cube2).Pose()); | ||
| EXPECT_EQ( | ||
| math::Pose3d(0.5, 0.5, 0.5, 0, 0, 0), | ||
| (diagonalCubes - cube1).Pose()); |
There was a problem hiding this comment.
| EXPECT_EQ( | |
| math::Pose3d(-0.5, -0.5, -0.5, 0, 0, 0), | |
| (diagonalCubes - cube2).Pose()); | |
| EXPECT_EQ( | |
| math::Pose3d(0.5, 0.5, 0.5, 0, 0, 0), | |
| (diagonalCubes - cube1).Pose()); | |
| EXPECT_EQ(cube1.Pose(), (diagonalCubes - cube2).Pose()); | |
| EXPECT_EQ(cube2.Pose(), (diagonalCubes - cube1).Pose()); |
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
| // Only continue if remaining mass is positive | ||
| if (m1 <= 0) | ||
| { | ||
| return *this; |
There was a problem hiding this comment.
we should also add a test case that exercises this line of code. It can be in a separate test case than AdditionSubtraction, like InvalidSubtraction or something like that
Signed-off-by: deepanshu <deepanshubansal01@gmail.com>
scpeters
left a comment
There was a problem hiding this comment.
looks great! thanks for all the changes and improvements.
when merging, please edit the commit message as suggested in our contributing guide
Default to “squash and merge”
Review the pull request title and reword if necessary since this will be part of the commit message.
Make sure the commit message concisely captures the core ideas of the pull request and contains all authors' signatures.
Summary
This PR adds a feature for minus operator in inertial class, full description here #423
Checklist
codecheckpassed (See contributing)