Skip to content

Commit 7e08974

Browse files
committed
handle colinear points errors
1 parent c6a0389 commit 7e08974

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

moveit_planners/pilz_industrial_motion_planner/include/pilz_industrial_motion_planner/path_free_generator.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,32 @@ class PathFreeGenerator
6868
*/
6969

7070
static double computeBlendRadius(const std::vector<KDL::Frame>& waypoints_, double smoothness);
71+
static void checkConsecutiveColinearWaypoints(const KDL::Frame& p1, const KDL::Frame& p2, const KDL::Frame& p3);
7172

7273
private:
7374
PathFreeGenerator(){}; // no instantiation of this helper class!
7475

7576
static constexpr double MAX_SEGMENT_LENGTH{ 0.2e-3 };
7677
static constexpr double MIN_SMOOTHNESS{ 0.01 };
7778
static constexpr double MAX_SMOOTHNESS{ 0.99 };
79+
static constexpr double MAX_COLINEAR_NORM{ 1e-9 };
80+
};
81+
82+
class ErrorMotionPlanningColinearConsicutiveWaypoints : public KDL::Error_MotionPlanning
83+
{
84+
public:
85+
const char* Description() const override
86+
{
87+
return "Three collinear consecutive waypoints."
88+
" A Free Path cannot be created.";
89+
}
90+
int GetType() const override
91+
{
92+
return ERROR_CODE_COLINEAR_CONSECUTIVE_WAYPOINTS;
93+
} // LCOV_EXCL_LINE
94+
95+
private:
96+
static constexpr int ERROR_CODE_COLINEAR_CONSECUTIVE_WAYPOINTS{ 3104 };
7897
};
7998

8099
} // namespace pilz_industrial_motion_planner

moveit_planners/pilz_industrial_motion_planner/include/pilz_industrial_motion_planner/trajectory_generator_free.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ CREATE_MOVEIT_ERROR_CODE_EXCEPTION(LinTrajectoryConversionFailure, moveit_msgs::
5151
CREATE_MOVEIT_ERROR_CODE_EXCEPTION(JointNumberMismatch, moveit_msgs::msg::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS);
5252
CREATE_MOVEIT_ERROR_CODE_EXCEPTION(LinInverseForGoalIncalculable, moveit_msgs::msg::MoveItErrorCodes::NO_IK_SOLUTION);
5353
CREATE_MOVEIT_ERROR_CODE_EXCEPTION(NoWaypointsSpecified, moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
54+
CREATE_MOVEIT_ERROR_CODE_EXCEPTION(ConsicutiveColinearWaypoints,
55+
moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN);
5456

5557
/**
5658
* @brief This class implements a free trajectory generator in Cartesian

moveit_planners/pilz_industrial_motion_planner/src/path_free_generator.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ double PathFreeGenerator::computeBlendRadius(const std::vector<KDL::Frame>& wayp
9494
{
9595
double dist1 = pose_distance(waypoints_[i], waypoints_[i - 1]);
9696
double dist2 = pose_distance(waypoints_[i + 1], waypoints_[i]);
97-
97+
checkConsecutiveColinearWaypoints(waypoints_[i - 1], waypoints_[i], waypoints_[i + 1]);
9898
if (dist1 < MAX_SEGMENT_LENGTH || dist2 < MAX_SEGMENT_LENGTH)
9999
{
100100
continue;
@@ -115,5 +115,17 @@ double PathFreeGenerator::computeBlendRadius(const std::vector<KDL::Frame>& wayp
115115

116116
return max_radius;
117117
}
118+
void PathFreeGenerator::checkConsecutiveColinearWaypoints(const KDL::Frame& p1, const KDL::Frame& p2,
119+
const KDL::Frame& p3)
120+
{
121+
KDL::Vector v1 = p2.p - p1.p;
122+
KDL::Vector v2 = p3.p - p2.p;
123+
124+
KDL::Vector cross_product = v1 * v2;
125+
if (cross_product.Norm() < MAX_COLINEAR_NORM)
126+
{
127+
throw ErrorMotionPlanningColinearConsicutiveWaypoints();
128+
}
129+
}
118130

119131
} // namespace pilz_industrial_motion_planner

moveit_planners/pilz_industrial_motion_planner/src/trajectory_generator_free.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,18 @@ void TrajectoryGeneratorFree::plan(const planning_scene::PlanningSceneConstPtr&
133133
// set pilz cartesian limits for each item
134134
setMaxCartesianSpeed(req);
135135
// create Cartesian FREE path
136-
std::unique_ptr<KDL::Path> path(setPathFree(plan_info.start_pose, plan_info.waypoints, req.smoothness_level));
136+
std::unique_ptr<KDL::Path> path;
137+
try
138+
{
139+
path = setPathFree(plan_info.start_pose, plan_info.waypoints, req.smoothness_level);
140+
}
141+
catch (const KDL::Error_MotionPlanning& e)
142+
{
143+
RCLCPP_ERROR(getLogger(), "Motion planning error: %s", e.Description());
144+
std::ostringstream os;
145+
os << "waypoints specified in path constraints have three consicutive colinear points";
146+
throw ConsicutiveColinearWaypoints(os.str());
147+
}
137148
// create velocity profile
138149
std::unique_ptr<KDL::VelocityProfile> vp(
139150
cartesianTrapVelocityProfile(req.max_velocity_scaling_factor, req.max_acceleration_scaling_factor, path));

0 commit comments

Comments
 (0)