43
43
#include < moveit/planning_scene/planning_scene.h>
44
44
#include < moveit/trajectory_processing/time_optimal_trajectory_generation.h>
45
45
46
+ #include < angles/angles.h>
47
+
46
48
using namespace trajectory_processing ;
47
49
48
50
namespace moveit {
@@ -146,6 +148,8 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
146
148
intermediate_scenes.push_back (start);
147
149
148
150
bool success = false ;
151
+ bool deviation = false ;
152
+ std::stringstream deviation_comment;
149
153
std::vector<double > positions;
150
154
for (const GroupPlannerVector::value_type& pair : planner_) {
151
155
// set intermediate goal state
@@ -164,6 +168,45 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
164
168
if (!success)
165
169
break ;
166
170
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
+
167
210
// continue from reached state
168
211
start = end;
169
212
}
@@ -175,6 +218,8 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
175
218
solution = makeSequential (sub_trajectories, intermediate_scenes, from, to);
176
219
if (!success) // error during sequential planning
177
220
solution->markAsFailure ();
221
+ if (deviation) // deviation error
222
+ solution->setComment (deviation_comment.str ());
178
223
connect (from, to, solution);
179
224
}
180
225
0 commit comments