-
Notifications
You must be signed in to change notification settings - Fork 67
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
Subtraction operator for Inertial class #432
Conversation
Signed-off-by: deepanshu <[email protected]>
Signed-off-by: deepanshu <[email protected]>
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 <[email protected]>
Signed-off-by: deepanshu <[email protected]>
Signed-off-by: deepanshu <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is correct. This MassMatrix object contains invalid inertias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can also have a separate implementation for -=operator
if this creates confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Signed-off-by: deepanshu <[email protected]>
Signed-off-by: deepanshu <[email protected]>
Signed-off-by: deepanshu <[email protected]>
src/Inertial_TEST.cc
Outdated
EXPECT_EQ(left, tmp); | ||
} | ||
{ | ||
math::Inertiald tmp = right; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tmp = cube;
here I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. Let me check real quick. Sorry about that.
Signed-off-by: deepanshu <[email protected]>
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 <[email protected]>
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
// Only continue if remaining mass is positive | ||
if (m1 <= 0) | ||
{ | ||
return *this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it!
Signed-off-by: deepanshu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
codecheck
passed (See contributing)