-
Notifications
You must be signed in to change notification settings - Fork 30
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 geodesic for SO(2) #408
Conversation
src/planner/SnapPlanner.cpp
Outdated
@@ -37,8 +37,12 @@ trajectory::InterpolatedPtr planSnap( | |||
} | |||
} | |||
|
|||
// Redefine the goal state |
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.
~This shouldn't be necessary, will be removed.
I don't think this is a good solution to the stated problem.
There is no mapping from SO(2) from R that has this property.
I don't see any similarity here. The whole point of the Aikido Our current implementation of |
I don't agree with Aditya's current proposal, but I can discuss the problem we have with the current SO2 implementation. I also agree with @mkoval that there's nothing wrong with current Here's the problem with our current SO2 implementation. We keep Suppose we do geodesic interpolation from SO2(2*pi) to SO2(0). This should be a no-travel. Consider the halfway point. The tangent vector we get for from->to direction in our current operation is Here are two tests that fail with the current implementation: I am ok with the first one ( Maybe I'm misunderstanding @mkoval 's comment here:
|
I do not think there is anything wrong with the There are two ways to solve this right.
@gilwoolee thanks for the tests! I should have started with that :) |
This is true. The only problem I can see is Essentially the output of The criteria for
For example, the range of Also, I think the current function names of All putting together, here is my proposal:
|
Thanks @jslee02 ! 👍 |
Codecov Report
@@ Coverage Diff @@
## master #408 +/- ##
==========================================
+ Coverage 79.56% 79.68% +0.11%
==========================================
Files 231 231
Lines 5955 5960 +5
==========================================
+ Hits 4738 4749 +11
+ Misses 1217 1211 -6
|
Updated for further discussion. 👍 |
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.
The current implementation looks good to me. I have some nitpicks though.
Also, it'd be great if you could add high-level comments to the tests.
include/aikido/statespace/SO2.hpp
Outdated
@@ -71,78 +34,108 @@ class SO2 : virtual public StateSpace | |||
/// \return new \c ScopedState | |||
ScopedState createState() const; | |||
|
|||
/// Gets state as a rotation angle. | |||
/// Returns state as a rotation angle. |
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.
Nit: Let's describe the return angle is in the range of (-pi, pi]
.
include/aikido/statespace/SO2.hpp
Outdated
/// \param _angle rotation angle | ||
void setAngle(State* _state, double _angle) const; | ||
/// \param[in] angle Rotation angle. | ||
/// \param[out] state State corresponding to angle |
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.
Nit: Let's order the argument docstring as the corresponding arguments are ordered.
include/aikido/statespace/SO2.hpp
Outdated
/// \return rotation angle | ||
double getAngle(const State* _state) const; | ||
/// \param[in] state State. | ||
double toAngle(const State* state) const; | ||
|
||
/// Sets state to a rotation angle. |
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.
Nit: Let's update the description something like "Sets state from a rotation angle.".
include/aikido/statespace/SO2.hpp
Outdated
|
||
/// Gets state as an Eigen transformation. | ||
/// Returns state as an Eigen transformation. |
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.
Nit: Eigen rotation.
?
include/aikido/statespace/SO2.hpp
Outdated
void setRotation(State* _state, const Eigen::Rotation2Dd& _rotation) const; | ||
/// \param[in] rotation Eigen transformation. | ||
/// \param[out] state State corresponding to rotation. | ||
void fromRotation(State* state, const Eigen::Rotation2Dd& rotation) const; |
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.
Let's order the docstring as the argument listed.
include/aikido/statespace/SO2.hpp
Outdated
~State() = default; | ||
|
||
/// Returns state as a rotation angle. | ||
double toAngle() const; |
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.
Nit: Let's inform that the range of the return angle.
include/aikido/statespace/SO2.hpp
Outdated
void fromRotation(const Eigen::Rotation2Dd& rotation); | ||
|
||
private: | ||
double mAngle; |
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.
Nit: Please add docstring.
src/statespace/SO2.cpp
Outdated
if (_state1 == _out || _state2 == _out) | ||
throw std::invalid_argument("Output aliases input."); | ||
#ifndef NDEBUG // Debug mode | ||
assert(state1 != out && state2 != out); |
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 don't know why we wanted to disable this in release mode, but it seems we need this precondition check (using exception) in both modes according to the docstring.
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.
Good catch 👍
src/statespace/SO2.cpp
Outdated
throw std::invalid_argument("Output aliases input."); | ||
#ifndef NDEBUG // Debug mode | ||
assert(out != in); | ||
#endif |
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.
Ditto with SO2::compose()
.
src/statespace/SO2.cpp
Outdated
} | ||
#ifndef NDEBUG // Debug mode | ||
assert(tangent.rows() == 1); | ||
#endif |
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.
Hm, the original warning message seems useful. Let's keep it.
Sure. I addressed the minor comments. I'll add a few more tests for catching invalid arguments and notify by removing the WIP label. Thanks! |
src/statespace/SO2.cpp
Outdated
double boundedAngle = std::fmod(angle, 2.0 * M_PI); | ||
if (boundedAngle > M_PI) | ||
boundedAngle -= 2.0 * M_PI; | ||
if (boundedAngle < -M_PI) |
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.
It looks like this permits boundedAngle
to be -pi
, while the documentation says that it is bounded in (-pi, pi]
.
src/statespace/SO2.cpp
Outdated
if (_out == _in) | ||
throw std::invalid_argument("Output aliases input."); | ||
if (out == in) | ||
throw std::invalid_argument("Output aliases input"); |
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.
Undo deleted period?
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.
Looks good overall. Added some minor comments.
include/aikido/statespace/SO2.hpp
Outdated
/// \param _angle rotation angle | ||
void setAngle(State* _state, double _angle) const; | ||
/// \param[out] state State corresponding to angle | ||
/// \param[in] angle Rotation angle. |
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.
Can we specify the range for angle
here? (If it allows (-inf, inf), mention that)
include/aikido/statespace/SO2.hpp
Outdated
|
||
/// Sets state from a rotation angle. | ||
/// | ||
/// \param[in] angle Rotation angle |
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.
Same as above, specify the range for angle
.
@@ -25,9 +25,9 @@ double SO2Angular::distance( | |||
const aikido::statespace::StateSpace::State* _state2) const | |||
{ | |||
// Difference between angles | |||
double diff = mStateSpace->getAngle( | |||
double diff = mStateSpace->toAngle( |
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.
Nit: Are we correcting the variable names in this PR or not? (_state
)
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 doing it only in the SO2.cpp/hpp
since I was mostly modifying them for this PR. I think I'll leave this for another PR and just have SO2 stuff cleaned up in code style.
@@ -8,38 +8,59 @@ using Eigen::Rotation2Dd; | |||
|
|||
static constexpr double TOLERANCE{1e-6}; | |||
|
|||
TEST(SO2, BoundedAngle) | |||
{ | |||
SO2::State s1(3 * M_PI_2); |
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 would add tests to check the exact bounds -pi
and pi
as well.
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.
Looks good to me.
@aditya-vk Please don't forget to update the changelog for completeness. |
👍 the latest round of changes look good to me. Thanks @aditya-vk for the great work and to @jslee02 for the excellent summary of the situation as it stood before this pull request. |
* restrict so2 between -pi to pi + cleanup * make format * WIP: changes in progress * proposal complete * cascade updates to function names * test the new changes to SO2 space * cascade update of change in function names * make format * corrections in test_SO2 * correct test_SO2Angular * make format * remove unnecessary code block * correct test in test_metaSkeletonStateSpace * address JS's comments * address Gilwoo's comments * add tests for when functions throw * update log * Fix incorrect merging of previous commit
This PR restricts the SO(2) state representation to lie between
+pi
and-pi
.SnapPlanner
, between two angles gives the geodesic.This will possibly require keeping a track of another parameter to know what phase of rotation the joint is in?
Looking for proposals and suggestions on handling this in the cleanest possible way [while keeping in mind the trajectories sent to the robot].
(Did not modify tests yet.)Before creating a pull request
make format
Before merging a pull request
CHANGELOG.md