Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the relative frame task #80

Merged
merged 12 commits into from
Mar 28, 2024
Merged

Conversation

stephane-caron
Copy link
Owner

This PR adds a task similar to the existing FrameTask, but a bit more general.

It is, on purpose, not a parent/child class of FrameTask. We can merge them if applicable in a later PR.

Thanks @ymontmarin for helping with the derivation of this task! 馃憤

@coveralls
Copy link

coveralls commented Mar 26, 2024

Pull Request Test Coverage Report for Build 8458281785

Details

  • 90 of 96 (93.75%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 99.45%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pink/tasks/relative_frame_task.py 53 59 89.83%
Totals Coverage Status
Change from base Build 8422815704: -0.2%
Covered Lines: 1265
Relevant Lines: 1272

馃挍 - Coveralls

@stephane-caron stephane-caron merged commit c62ad60 into main Mar 28, 2024
12 checks passed
@stephane-caron stephane-caron deleted the feature/relative_frame_task branch March 28, 2024 13:13
Copy link
Collaborator

@ymontmarin ymontmarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am wrong but line 207 of relative_frame_task.py look weird to me.

Other than that looks good and I proposed a (tiny) simplification

)
transform_target_to_frame = self.transform_target_to_root.act(
transform_root_to_frame
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should'nt it be transform_root_to_frame.act(self.transform_target_to_root) ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, at least the variable name (if not more 馃檲) is definitely wrong. I will fix that.

task target frame to the root frame.
"""
self.transform_target_to_root = transform_target_to_root.copy()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store the inverse ${}^tT_r$ instead:
self.transform_root_to_target = transform_target_to_root.inverse().copy()

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would make sense in internal calculations, but from an API standpoint I think it's better in this direction for consistency with the FrameTask:

  • Frame task has "transform from target to world" (because common practice is to work with $T_{0b}$ rather than $T_{b0}$)
  • Relative frame task has "transform from target to root"

pink/tasks/relative_frame_task.py Show resolved Hide resolved
self.transform_target_to_root
)
error_in_frame: np.ndarray = pin.log(transform_target_to_frame).vector
return error_in_frame
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It becomes:

transform_frame_to_root = configuration.get_transform(
    self.frame, self.root
)  # rTf
transform_frame_to_target = self.transform_root_to_target.act(
    transform_frame_to_root
)  # tTf = tTr rTf
error_in_frame: np.ndarray = - pin.log(transform_frame_to_target).vector
# log(fTt) = -log(tTf)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it is one line of code, you can use the "Add suggestion" button (or <Ctrl+g>) on GitHub.

If it is more than one line of code, either the PR author does it, or you can commit directly to the PR (you are welcome to 馃槂). Or, in this instance since it was already merged, open a new PR 馃憣

action_root_to_target @ jacobian_root_in_root
- action_frame_to_target @ jacobian_frame_in_frame
)
return J
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anycase with the new formulation we can calculate:
$J_e = - Jlog({}^tT_f) J$
with $J$ left jacobian of ${}^tT_f = {}^tT_r {}^wT_r^{-1} {}^wT_f$

Recall that $[J v ]^{up} = {}^tT_f^{-1}\frac{d}{dt} ({}^tT_f)$ and we calculate:
${}^tT_f^{-1} d/dt ({}^tT_f) = {}^wT_f^{-1} {}^wT_r {}^tT_r^{-1}({}^tT_r(-{}^wT_r^{-1}{}^w\dot{T}_r{}^wT_r^{-1} {}^wT_f + {}^wT_r^{-1}{}^w\dot{T}_f))$
And it simplifies to:
$-{}^fT_r({}^wT_r^{-1}{}^w\dot{T}_r){}^fT_r^{-1} + {}^wT_f^{-1}{}^w\dot{T}_f = [{}^fX_r J_r v + J_f v]^{up}$

And finaly $J = -{}^fX_r J_r + J_f$.
And $J_e = Jlog({}^tT_f) ({}^fX_r J_r - J_f)$

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform_frame_to_root = configuration.get_transform(
    self.frame, self.root
)  # rTf
transform_frame_to_target = self.transform_root_to_target.act(
    transform_frame_to_root
)  # tTf = tTr rTf

action_root_to_frame = transform_frame_to_root.actionInverse

jacobian_frame_in_frame = configuration.get_frame_jacobian(self.frame)  # J_f
jacobian_root_in_root = configuration.get_frame_jacobian(self.root)  # J_r

J = pin.Jlog6(transform_frame_to_target) @ (
    action_root_to_frame @ jacobian_root_in_root
    - jacobian_frame_in_frame
)  # Je = Jlog (- fXr Jr + J_f)
return J

@stephane-caron
Copy link
Owner Author

stephane-caron commented Mar 29, 2024

Thank you @ymontmarin! (And apologies for merging early after our chat, I thought this one was good to go.) I will take care of the fix in #81.

Can you open a PR for your alternative calculation proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants