Skip to content

Commit c931acf

Browse files
committed
Validate connect stage deviation: end trajectory with goal
If not within the threshold, mark solution as a failure and set comment.
1 parent 7638e5f commit c931acf

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

core/src/stages/connect.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include <moveit/planning_scene/planning_scene.h>
4444
#include <moveit/trajectory_processing/time_optimal_trajectory_generation.h>
4545

46+
#include <angles/angles.h>
47+
4648
using namespace trajectory_processing;
4749

4850
namespace moveit {
@@ -146,6 +148,8 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
146148
intermediate_scenes.push_back(start);
147149

148150
bool success = false;
151+
bool deviation = false;
152+
std::stringstream deviation_comment;
149153
std::vector<double> positions;
150154
for (const GroupPlannerVector::value_type& pair : planner_) {
151155
// set intermediate goal state
@@ -164,6 +168,45 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
164168
if (!success)
165169
break;
166170

171+
// validate position deviation from trajectory last waypoint to goal
172+
const std::size_t waypoint_count = trajectory->getWayPointCount();
173+
174+
if (waypoint_count) {
175+
for (const moveit::core::JointModel* jm : jmg->getJointModels()) {
176+
const unsigned int num = jm->getVariableCount();
177+
178+
if (!num)
179+
continue;
180+
181+
Eigen::Map<const Eigen::VectorXd> positions_goal(goal_state.getJointPositions(jm), num);
182+
Eigen::Map<const Eigen::VectorXd> positions_last_waypoint(
183+
trajectory->getWayPoint(waypoint_count - 1).getJointPositions(jm), num);
184+
185+
for (std::size_t i = 0; i < num; ++i) {
186+
double min_distance = angles::shortest_angular_distance(positions_last_waypoint[i], positions_goal[i]);
187+
ROS_DEBUG_STREAM_NAMED(
188+
"Connect", "angular deviation: " << min_distance << " between trajectory last waypoint and goal.");
189+
190+
if (std::abs(min_distance) > 1e-4) {
191+
deviation_comment << "Deviation in joint " << jm->getName() << ": ["
192+
<< positions_last_waypoint.transpose() << "] != [" << positions_goal.transpose()
193+
<< "]";
194+
ROS_ERROR_STREAM_NAMED("Connect", deviation_comment.str());
195+
196+
deviation = true;
197+
success = false;
198+
break;
199+
}
200+
}
201+
202+
if (deviation)
203+
break;
204+
}
205+
}
206+
207+
if (deviation)
208+
break;
209+
167210
// continue from reached state
168211
start = end;
169212
}
@@ -175,6 +218,8 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
175218
solution = makeSequential(sub_trajectories, intermediate_scenes, from, to);
176219
if (!success) // error during sequential planning
177220
solution->markAsFailure();
221+
if (deviation) // deviation error
222+
solution->setComment(deviation_comment.str());
178223
connect(from, to, solution);
179224
}
180225

0 commit comments

Comments
 (0)