symforce-org / symforce

Fast symbolic computation, code generation, and nonlinear optimization for robotics
https://symforce.org
Apache License 2.0
1.41k stars 145 forks source link

How to intialize sf.Rot3 with a quaternion?? #314

Closed VineetTambe closed 1 year ago

VineetTambe commented 1 year ago

How do I initialise sf.Rot3 with a quaternion?? The tutorial on rotations talks about getting a sf.R3 from all other representation and even specifies that the underlying structure is a quaternion. But how do I initialise a sf.Rot3 structure if I already have quaternion - this is not specified in the tutorials page (Maybe a good idea to add it there?? Or did I just miss it - if that's the case I apologies and can you direct me to that page)

I also dug around a little and found one way to do it for a quaternion: q = s + vx i_hat + vy j_hat + vz k_hat sf.Rot3(sf.Quaternion(xyz= np.array([vx,vy,vz]), w = s)) Is the above correct??

sudo-robot-destroy commented 1 year ago

That is correct, Rot3's initialization method accepts a quaternion, if one isn't provided it uses an identity quaternion (https://symforce.org/api/symforce.geo.rot3.html)

It can seem a little confusing why there is a need to distinguish between the two, but the Rot3 is a Lie Group and the Quaternion is just a Group.

VineetTambe commented 1 year ago

Thanks for the reply! The latter part - of having them distinguished is pretty clear and makes sense.

Suggestion: Can we have Rot3 initialisation from a quaternion visible more readily and on the tutorials page? From the perspective of a first time users of symforce - having that with the tutorials where initialisation from other representations is present would have had been really helpful!

Thanks!

aaron-skydio commented 1 year ago

Yeah I think having an example there is a good idea

VineetTambe commented 1 year ago

Should I add one?? Assuming this comment is correct.

aaron-skydio commented 1 year ago

Sure! Really the example should use sf.V3 instead of np.array, but otherwise that's right

VineetTambe commented 1 year ago

Cool! I'll add a quaternion cell to symforce-org/symforce/notebooks/tutorials/geometry_tutorial.ipynb and raise a pull request!

VineetTambe commented 1 year ago

Do I need some access rights to push to a branch so that I can raise a pull request? If so, then can I be permitted to push a branch to raise a PR for review? If not, then what is the procedure that is followed to raise a PR?

aaron-skydio commented 1 year ago

You should make a fork of the symforce repo and make your changes there, and then make a PR to this repo from your fork: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

VineetTambe commented 1 year ago

Done!