-
Notifications
You must be signed in to change notification settings - Fork 300
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 AddLinkForce Function to Apply Forces in Link Frame #2816
base: main
Are you sure you want to change the base?
Conversation
The CI picked up some lint issues - can you remove trailing whitespace and limit lines to 80 char? I also made some minor comments on removing empty lines. |
include/gz/sim/Link.hh
Outdated
/// and applied at the center of mass of the link. | ||
/// \param[in] _ecm Mutable Entity-component manager. | ||
/// \param[in] _force Force to be applied expressed in link's center of mass coordinates | ||
public: void AddLinkForce(EntityComponentManager &_ecm, |
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.
Maybe just AddForce
, which is more consistent with gazebo-classic's API. Do you have any preference on the API name, @scpeters?.
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.
friendly ping @scpeters
given that the other functions in this class do not have the Link
string in the name, e.g. SetLinearVelocity
(instead of SetLinkLinearVelocity
), I think we should rename this to AddForce
to be consistent.
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 was thinking to use the following naming convention
- The function which applies force directly at the COM, can be named either AddForce or AddRelativeForce
- The function which applies force at an offset from the COM, can be named AddLinkForce.
This naming convention is consistent with gazebo-classic's API.
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.
apologies for the delayed response; this is complicated and I wrote an overly long response, which I will post as a separate comment to this PR
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.
/// \param[in] _force Force to be applied expressed in link's
/// center of mass coordinates
by center of mass coordinates, do you mean the coordinates of the inertial frame defined by the SDFormat //link/inertial/pose
offset from the link frame?
If so, you could name this method AddInertialForce
or AddForceInInertialFrame
or AddForceRelativeToInertialFrame
0cbdd0f
to
4e44110
Compare
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
… to 80 characters Signed-off-by: Vedant87 <[email protected]>
… to 80 characters Signed-off-by: Vedant87 <[email protected]>
4e44110
to
9660d0c
Compare
Once you decide on the naming, it'll also be good to update the python API. |
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
Sorry for the delay; this is complicated and it took me a while to collect my thoughts.
Some references for naming these quantities:
The gz::sim::Link class already has two overloads of the
I suppose the "World" in the "AddWorldForce" method name refers to the "expressed-in-coordinates-of" frame for the force vector, but it seems inconsistent to me that the position parameter is "expressed-in-coordinates-of" the link frame. It also seems inconsistent that for one overload, the force is applied "relative-to" the link center-of-mass, but in the other overload it is applied "relative-to" an offset from the link-fixed frame. In gazebo-classic, the gazebo::physics::Link class has the following APIs with varying levels of documented behavior in the header file:
Having said all that, here are some guidelines:
I'll follow up with concrete suggestions inline |
include/gz/sim/Link.hh
Outdated
/// and applied at the center of mass of the link. | ||
/// \param[in] _ecm Mutable Entity-component manager. | ||
/// \param[in] _force Force to be applied expressed in link's center of mass coordinates | ||
public: void AddLinkForce(EntityComponentManager &_ecm, |
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.
/// \param[in] _force Force to be applied expressed in link's
/// center of mass coordinates
by center of mass coordinates, do you mean the coordinates of the inertial frame defined by the SDFormat //link/inertial/pose
offset from the link frame?
If so, you could name this method AddInertialForce
or AddForceInInertialFrame
or AddForceRelativeToInertialFrame
include/gz/sim/Link.hh
Outdated
/// \param[in] _force Force to be applied expressed in link's center | ||
/// of mass coordinates | ||
/// \param[in] _position The point of application of the force expressed | ||
/// in the link-fixed frame. |
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.
consider defining _position
in the same coordinates as _force
for consistency
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.
consider defining
_position
in the same coordinates as_force
for consistency
The documentation is conflicting:
- According to Link.hh:330-331 ,
_position
is defined in link-fixed coordinates. - According to Link.cc:457-459 ,
_position
is defined in Link's center of mass coordinates.
In the current implementation I am assuming _position
is defined in Link's center of mass coordinates, which are the same coordinates as _force
.
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.
well if the inconsistent use of frames is a documentation error, then let's fix the documentation. We should confirm the actual behavior with the test though
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.
well if the inconsistent use of frames is a documentation error, then let's fix the documentation. We should confirm the actual behavior with the test though
-
_position
, is expressed in terms of link fixed frame. In Link.cc:460-461 ,_position
is directly added toinertial
, if_position
is expressed in terms of Link's center of mass there should be a calculation to convert_position
from in terms of Link's center of mass to_position
in terms of link-fixed coordinates. -
There is a major issue in my code that I overlooked, the calculations in my code consider the force is expressed in coordinates of the link frame, so coincidently
_force
and_position
are both expressed in link-fixed coordinates. -
I'll work on fixing all these issues in the next commit.
include/gz/sim/Link.hh
Outdated
/// \param[in] _force Force to be applied expressed in link's center | ||
/// of mass coordinates | ||
/// \param[in] _position The point of application of the force expressed | ||
/// in the link-fixed frame. |
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.
well if the inconsistent use of frames is a documentation error, then let's fix the documentation. We should confirm the actual behavior with the test though
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
I've made the required changes to the code, I am not sure why the commit is failing the following 2 tests: |
this had an unrelated flaky test failure (see #2609) this was an infra problem, fixed by gazebo-tooling/release-tools#1281, I retriggered it |
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
Signed-off-by: Vedant87 <[email protected]>
🎉 New feature
Closes #2713
Summary
Function added: to apply force relative to the center of mass of the link frame, the function converts the force to a force with respect to the world coordinates. It uses the AddWorldForce method to apply force either at the center of mass of the link or at an offset from the center of mass, based on user input.
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.