-
Notifications
You must be signed in to change notification settings - Fork 158
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
End-state deviates from goal state #532
Merged
rhaschke
merged 8 commits into
moveit:master
from
captain-yoshi:conect-stage-validation
Feb 25, 2024
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c931acf
Validate connect stage deviation: end trajectory with goal
captain-yoshi 7c317b9
[fix] compute shortest angular distance only on revolute joints
captain-yoshi b42c0b1
[refac] move validation into it's own method
captain-yoshi 26e8519
[fix] compute joint difference
captain-yoshi 0d50ec9
[impl] expose deviation threshold to stage property
captain-yoshi fc6eacc
simplify
rhaschke 7edc2f9
Add corresponding unit test
rhaschke 8f8f08b
fixup! simplify
rhaschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,6 +43,8 @@ | |||||
#include <moveit/planning_scene/planning_scene.h> | ||||||
#include <moveit/trajectory_processing/time_optimal_trajectory_generation.h> | ||||||
|
||||||
#include <angles/angles.h> | ||||||
|
||||||
using namespace trajectory_processing; | ||||||
|
||||||
namespace moveit { | ||||||
|
@@ -132,6 +134,51 @@ | |||||
return true; | ||||||
} | ||||||
|
||||||
bool Connect::validateEndTrajectoryDeviation(const moveit::core::JointModelGroup* jmg, | ||||||
const robot_trajectory::RobotTrajectoryPtr trajectory, | ||||||
const moveit::core::RobotState& goal_state, std::string& comment) { | ||||||
const std::size_t waypoint_count = trajectory->getWayPointCount(); | ||||||
|
||||||
if (!waypoint_count) { | ||||||
comment = "Cannot validate end trajectory deviation with an empty trajectory"; | ||||||
return false; | ||||||
} | ||||||
|
||||||
for (const moveit::core::JointModel* jm : jmg->getJointModels()) { | ||||||
const unsigned int num = jm->getVariableCount(); | ||||||
|
||||||
if (!num) | ||||||
continue; | ||||||
|
||||||
Eigen::Map<const Eigen::VectorXd> positions_goal(goal_state.getJointPositions(jm), num); | ||||||
Eigen::Map<const Eigen::VectorXd> positions_last_waypoint( | ||||||
trajectory->getWayPoint(waypoint_count - 1).getJointPositions(jm), num); | ||||||
|
||||||
double min_distance; | ||||||
for (std::size_t i = 0; i < num; ++i) { | ||||||
if (jm->getType() == robot_state::JointModel::REVOLUTE) | ||||||
min_distance = angles::shortest_angular_distance(positions_last_waypoint[i], positions_goal[i]); | ||||||
else | ||||||
min_distance = positions_last_waypoint[i], positions_goal[i]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you want to compute the joint difference:
Suggested change
|
||||||
|
||||||
ROS_DEBUG_STREAM_NAMED("Connect", | ||||||
"angular deviation: " << min_distance << " between trajectory last waypoint and goal."); | ||||||
|
||||||
if (std::abs(min_distance) > 1e-4) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The magic number 1e-4 should be configurable, e.g. via a stage property. |
||||||
std::stringstream ss; | ||||||
ss << "Deviation in joint " << jm->getName() << ": [" << positions_last_waypoint.transpose() << "] != [" | ||||||
<< positions_goal.transpose() << "]"; | ||||||
comment = ss.str(); | ||||||
ROS_ERROR_STREAM_NAMED("Connect", comment); | ||||||
|
||||||
return false; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return true; | ||||||
} | ||||||
|
||||||
void Connect::compute(const InterfaceState& from, const InterfaceState& to) { | ||||||
const auto& props = properties(); | ||||||
double timeout = this->timeout(); | ||||||
|
@@ -146,6 +193,7 @@ | |||||
intermediate_scenes.push_back(start); | ||||||
|
||||||
bool success = false; | ||||||
std::string deviation_comment; | ||||||
std::vector<double> positions; | ||||||
for (const GroupPlannerVector::value_type& pair : planner_) { | ||||||
// set intermediate goal state | ||||||
|
@@ -161,6 +209,12 @@ | |||||
success = pair.second->plan(start, end, jmg, timeout, trajectory, path_constraints); | ||||||
sub_trajectories.push_back(trajectory); // include failed trajectory | ||||||
|
||||||
if (!success) | ||||||
break; | ||||||
|
||||||
// validate position deviation: trajectory last waypoint to goal | ||||||
success = validateEndTrajectoryDeviation(jmg, trajectory, goal_state, deviation_comment); | ||||||
|
||||||
if (!success) | ||||||
break; | ||||||
|
||||||
|
@@ -175,6 +229,8 @@ | |||||
solution = makeSequential(sub_trajectories, intermediate_scenes, from, to); | ||||||
if (!success) // error during sequential planning | ||||||
solution->markAsFailure(); | ||||||
if (!deviation_comment.empty()) // deviation error | ||||||
solution->setComment(deviation_comment); | ||||||
connect(from, to, solution); | ||||||
} | ||||||
|
||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You must not use
angles::shortest_angular_distance
here, as we need to reach the exact goal state - subsequent stages rely on this fact!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.
Hum... I'm pretty sure it removed valid solutions... Will investigate more and report back soon.
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.
We cannot accept equality up to multiples to 360°. The goal state needs to be reached exactly. Otherwise subsequent stages will run into trouble because they relied on a different start state.