-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix(state_representation): remove error in orientation scaling #147
Conversation
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 believe the division by two probably was mistakenly carried over from mapping equations involving the half-angle. For example, when converting from axis-angle to quaternion, the angle is divided by two before being used in a similar exponential function.
Using Eigen's slerp is definitely simpler. Just to be sure, does the resulting quaternion respect the original hemisphere (i.e. does the real part remain positive / negative in all cases)? Would be good to have a small test case for that too.
Yeah, could you give me a hand with that? I don't think I would know what to test for exactly... |
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.
From what I see, the log
function was in charge of putting the quaternion in the correct hemisphere:
if (q_tmp.w() < 0) {
q_tmp = Eigen::Quaterniond(-q_tmp.coeffs());
}
Question is to know if slerp
is handling that or if you need to check for that. I see this question on slack overflow that is vey relevant https://stackoverflow.com/questions/62943083/interpolate-between-two-quaternions-the-long-way.
You need to check what is already handled by Eigen
as we don't want to duplicate.
source/state_representation/include/state_representation/MathTools.hpp
Outdated
Show resolved
Hide resolved
Coming back to that I am trying to find how it is implemented in
This means that our |
I think I am getting my head around that. I am so rusty... It makes sense that So, if the function does not behave correctly with slerp(lambda % 1, q) If I recall a negative number modulo would end up positive. If not find the correct function one of them have that behavior in C++. Gosh I miss that. |
I can't understand why we wouldn't be able to 'double' the rotation though. Imagine just a small roational displacement from identity, and then I would like to double that. Why would I not be able to do that? It wouldn't change the hemisphere or anything, except if I really have a bad understanding of quaternions.. |
You can. We should not restrict that because for position it makes sense. But doubling the orientation means that you end up where you are. So either |
Baptiste of course makes an excellent point about slerp (spherical linear interpolation). For context, in my original use case I wanted to interpolate between two poses according to an interpolation time factor t, which was explicitly bound between 0 and 1. That's why I chose slerp as the workaround in my application. When Dominic applied it here, I didn't consider the cases outside of my original use case of interpolation. But, "clamping" the lambda of this scaling operation between 0 and 1 using the modulus is not correct either, since that defeats the purpose of arbitrarily scaling a rotation. I suspect just removing the suspicious half operation from the exponentiation function would be enough to solve the original problem and preserve the intended scaling effect. The exp function essentially acts as an integrator for cumulatively applied rotations, and is similar to how angular velocity can be converted into a rotation. The main point is that the half-angle is normally used when converting between quaternion and axis-angle, and it slipped into this equation even though it shouldn't. Concretely, I would suggest the following test cases:
Same for negative case, where the expected orientation is the conjugate of the above expectations |
Just to also clarify this, doubling an orientation represented by some quaternion |
Very good explanation as always @eeberhard. I am definitely too rusty for this. I think we are getting around this. As discussed with @domire8 proper test cases are needed and it seems the one you propose are good. |
Makes sense, I've tried it. However, I'm not sure how I can control on which hemisphere the quaternions should end up now. The axis angle representation of the resulting scaled quaternions are the same between |
It would better to check angular distance against the Eigen methods (expect near zero), rather than the coefficients. Regarding the duality of quaternions, I would test that Could you also test the inverse case to make sure negative scaling works as intended? (i.e., same tests but take the conjugate of the slerp-calculated result) |
This reverts commit 88bfed3.
Thanks for helping me work this out. I think this is good to go now with all requested test cases. |
Description
Bug detected by @eeberhard, scaling a pose didn't give the correct orientation. The fix I propose is to use slerp instead of the exponential calculation from before. As a side note, this solution is equivalent to keeping the
exp
but removing the division by 2 that already seemed suspicious.Review guidelines
Estimated Time of Review: 5 minutes
Checklist before merging: