Add Capsule class with inertia calculation method#163
Add Capsule class with inertia calculation method#163scpeters merged 18 commits intogazebosim:ign-math6from
Conversation
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
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 <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
There was a problem hiding this comment.
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.
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 <scpeters@openrobotics.org>
This is more elegant than the MassMatrix3::SetFromCapsuleZ helper functions. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
I thought about it, and we can use the I've removed the |
chapulina
left a comment
There was a problem hiding this comment.
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.
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.
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.
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 <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
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 <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
This package has classes for several shapes (
Box,Cylinder,Sphere) as well as methods inMassMatrix3for computing inertial properties of these shapes assuming uniform density. This pull request adds a newCapsuleshape class that is like aCylinderwith hemispheres capping each end. Methods for computing the inertial properties of aCapsuleare added toMassMatrix3and validated in unit tests by comparing to the formulae used by Open Dynamics Engine.Update: I've removed the
MassMatrix3methods and removed theQuaternionparameter from theCapsuleclass.