-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add Capsule class with inertia calculation method #163
Conversation
Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Steve Peters <[email protected]>
Copy the Cylinder class and unit test to create Capsule, which is similar to the Cylinder but with hemispheres capping either end of the cylinder. Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Steve Peters <[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 good at a high-level. The API here seems to be highly redundant and coupled (e.g. shapes + offsets, inertia computations, etc.), but understandably it'd be hard to refactor any time soon.
Made some picky comments, but nothing blocking.
Is there also a high-level issue that this is aiming towards?
e.g. gazebosim/sdformat#176 gazebosim/sdformat#376
include/ignition/math/Capsule.hh
Outdated
/// equivalent to a cylinder with capped with hemispheres. Radius and | ||
/// length are in meters. See Material for more on material properties. | ||
/// By default, a capsule's length is aligned with the Z axis. The | ||
/// rotational offset encodes a rotation from the z axis. |
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.
It would be good to also state that the radius defines the circle when the capsule intersects with G's XY-plane.
Also, the shapes defined in Am I missing something there? |
it's in support of gazebosim/sdformat#376, along with gazebosim/sdformat#389 |
It took me a little while to remember, but I remembered a bit of the original intent behind this design. We added the That When the shape functions were added in 5.0.0, they included a Quaternion parameter in the constructor, and in retrospect, I think they might be confusing things more than helping. I'll remove them from the I'll think further on whether we need |
Signed-off-by: Steve Peters <[email protected]>
This is more elegant than the MassMatrix3::SetFromCapsuleZ helper functions. Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Steve Peters <[email protected]>
I thought about it, and we can use the I've removed the |
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 good to me, I just have a question about the hemispheres, but I'm trusting the test that the math checks out.
no I don't think you're missing anything. I think the shape objects have similar API's but it's not enforced |
Aye, sounds good. Minor concern is that the |
{ | ||
/// \brief Default constructor. The default radius and length are both | ||
/// zero. | ||
public: Capsule() = default; |
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.
What do you think about not providing a default constructor? That way the only time we would have invalid Capsule objects would be if the input length and radius values are invalid.
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 like having the default constructor. If you want to create a shape without remembering the order of the arguments in the constructor:
Capsuled capsule;
capsule.SetLength(length);
capsule.SetRadius(radius);
if other people don't like it, we can remove it, but I'm inclined to keep it
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.
If I put on my pedantry hat, the "right" way to do what @scpeters is suggesting would be to have something like a Capsule::Builder
class that lets you fill in the information necessary to build a Capsule
object, and then you could call build()
on it (or something similar) and it constructs a capsule for you, perhaps throwing an exception if the parameters are invalid (e.g. radius <= 0, length <= 0).
Some would (fairly) argue that's overkill for this use case, but the more I've had to deal with writing production-quality code, the more I've been feeling it's worth the effort to make every assumption explicit inside the code itself.
* Remove destructor * Remove duplicate SetLength method * Add tparam doc-string * Fix comment about parameter that has been removed Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Steve Peters <[email protected]>
With the prior API that passes a reference to a MassMatrix3, it is unclear whether the object is mutated when the parameters are invalid. Using std::optional removes the ambiguity and ensures that invalid values are not returned. Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Steve Peters <[email protected]>
This package has classes for several shapes (
Box
,Cylinder
,Sphere
) as well as methods inMassMatrix3
for computing inertial properties of these shapes assuming uniform density. This pull request adds a newCapsule
shape class that is like aCylinder
with hemispheres capping each end. Methods for computing the inertial properties of aCapsule
are added toMassMatrix3
and validated in unit tests by comparing to the formulae used by Open Dynamics Engine.Update: I've removed the
MassMatrix3
methods and removed theQuaternion
parameter from theCapsule
class.