Skip to content

Commit 1e05859

Browse files
sjahrrhaschke
authored andcommitted
Add planner_id to SubTrajectory info (moveit#490)
1 parent ed70497 commit 1e05859

File tree

14 files changed

+64
-16
lines changed

14 files changed

+64
-16
lines changed

core/include/moveit/task_constructor/solvers/cartesian_path.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class CartesianPath : public PlannerInterface
7171
const Eigen::Isometry3d& offset, const Eigen::Isometry3d& target, const moveit::core::JointModelGroup* jmg,
7272
double timeout, robot_trajectory::RobotTrajectoryPtr& result,
7373
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override;
74+
75+
std::string getPlannerId() const override { return "CartesianPath"; }
7476
};
7577
} // namespace solvers
7678
} // namespace task_constructor

core/include/moveit/task_constructor/solvers/joint_interpolation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class JointInterpolationPlanner : public PlannerInterface
6666
const Eigen::Isometry3d& offset, const Eigen::Isometry3d& target, const moveit::core::JointModelGroup* jmg,
6767
double timeout, robot_trajectory::RobotTrajectoryPtr& result,
6868
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override;
69+
70+
std::string getPlannerId() const override { return "JointInterpolationPlanner"; }
6971
};
7072
} // namespace solvers
7173
} // namespace task_constructor

core/include/moveit/task_constructor/solvers/pipeline_planner.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class PipelinePlanner : public PlannerInterface
137137
robot_trajectory::RobotTrajectoryPtr& result,
138138
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) override;
139139

140+
std::string getPlannerId() const override { return last_successful_planner_; }
141+
140142
protected:
141143
/** \brief Actual plan() implementation, targeting the given goal_constraints.
142144
* \param [in] planning_scene Scene for which the planning should be solved
@@ -155,6 +157,8 @@ class PipelinePlanner : public PlannerInterface
155157

156158
rclcpp::Node::SharedPtr node_;
157159

160+
std::string last_successful_planner_;
161+
158162
/** \brief Map of instantiated (and named) planning pipelines. */
159163
std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr> planning_pipelines_;
160164

core/include/moveit/task_constructor/solvers/planner_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class PlannerInterface
9999
const moveit::core::JointModelGroup* jmg, double timeout,
100100
robot_trajectory::RobotTrajectoryPtr& result,
101101
const moveit_msgs::msg::Constraints& path_constraints = moveit_msgs::msg::Constraints()) = 0;
102+
103+
// get name of the planner
104+
virtual std::string getPlannerId() const = 0;
102105
};
103106
} // namespace solvers
104107
} // namespace task_constructor

core/include/moveit/task_constructor/stages/connect.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ class Connect : public Connecting
7373
WAYPOINTS = 1
7474
};
7575

76-
using GroupPlannerVector = std::vector<std::pair<std::string, solvers::PlannerInterfacePtr> >;
76+
struct PlannerIdTrajectoryPair
77+
{
78+
std::string planner_id;
79+
robot_trajectory::RobotTrajectoryConstPtr trajectory;
80+
};
81+
82+
using GroupPlannerVector = std::vector<std::pair<std::string, solvers::PlannerInterfacePtr>>;
7783
Connect(const std::string& name = "connect", const GroupPlannerVector& planners = {});
7884

7985
void setPathConstraints(moveit_msgs::msg::Constraints path_constraints) {
@@ -85,10 +91,10 @@ class Connect : public Connecting
8591
void compute(const InterfaceState& from, const InterfaceState& to) override;
8692

8793
protected:
88-
SolutionSequencePtr makeSequential(const std::vector<robot_trajectory::RobotTrajectoryConstPtr>& sub_trajectories,
94+
SolutionSequencePtr makeSequential(const std::vector<PlannerIdTrajectoryPair>& sub_trajectories,
8995
const std::vector<planning_scene::PlanningSceneConstPtr>& intermediate_scenes,
9096
const InterfaceState& from, const InterfaceState& to);
91-
SubTrajectoryPtr merge(const std::vector<robot_trajectory::RobotTrajectoryConstPtr>& sub_trajectories,
97+
SubTrajectoryPtr merge(const std::vector<PlannerIdTrajectoryPair>& sub_trajectories,
9298
const std::vector<planning_scene::PlanningSceneConstPtr>& intermediate_scenes,
9399
const moveit::core::RobotState& state);
94100

core/include/moveit/task_constructor/storage.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ class SolutionBase
309309
const std::string& comment() const { return comment_; }
310310
void setComment(const std::string& comment) { comment_ = comment; }
311311

312+
const std::string& plannerId() const { return planner_id_; }
313+
void setPlannerId(const std::string& planner_id) { planner_id_ = planner_id; }
314+
312315
auto& markers() { return markers_; }
313316
const auto& markers() const { return markers_; }
314317

@@ -326,8 +329,8 @@ class SolutionBase
326329
bool operator<(const SolutionBase& other) const { return this->cost_ < other.cost_; }
327330

328331
protected:
329-
SolutionBase(Stage* creator = nullptr, double cost = 0.0, std::string comment = "")
330-
: creator_(creator), cost_(cost), comment_(std::move(comment)) {}
332+
SolutionBase(Stage* creator = nullptr, double cost = 0.0, std::string comment = "", std::string planner_id = "")
333+
: creator_(creator), cost_(cost), comment_(std::move(comment)), planner_id_(std::move(planner_id)) {}
331334

332335
private:
333336
// back-pointer to creating stage, allows to access sub-solutions
@@ -336,6 +339,8 @@ class SolutionBase
336339
double cost_;
337340
// comment for this solution, e.g. explanation of failure
338341
std::string comment_;
342+
// name of the planner used to create this solution
343+
std::string planner_id_;
339344
// markers for this solution, e.g. target frame or collision indicators
340345
std::deque<visualization_msgs::msg::Marker> markers_;
341346

@@ -351,8 +356,8 @@ class SubTrajectory : public SolutionBase
351356
public:
352357
SubTrajectory(
353358
const robot_trajectory::RobotTrajectoryConstPtr& trajectory = robot_trajectory::RobotTrajectoryConstPtr(),
354-
double cost = 0.0, std::string comment = "")
355-
: SolutionBase(nullptr, cost, std::move(comment)), trajectory_(trajectory) {}
359+
double cost = 0.0, std::string comment = "", std::string planner_id = "")
360+
: SolutionBase(nullptr, cost, std::move(comment), std::move(planner_id)), trajectory_(trajectory) {}
356361

357362
robot_trajectory::RobotTrajectoryConstPtr trajectory() const { return trajectory_; }
358363
void setTrajectory(const robot_trajectory::RobotTrajectoryPtr& t) { trajectory_ = t; }

core/src/solvers/pipeline_planner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ bool PipelinePlanner::plan(const planning_scene::PlanningSceneConstPtr& planning
165165
robot_trajectory::RobotTrajectoryPtr& result,
166166
const moveit_msgs::msg::Constraints& path_constraints) {
167167
const auto& map = properties().get<PipelineMap>("pipeline_id_planner_id_map");
168+
last_successful_planner_ = "Unknown";
168169

169170
// Create a request for every planning pipeline that should run in parallel
170171
std::vector<moveit_msgs::msg::MotionPlanRequest> requests;
@@ -205,6 +206,7 @@ bool PipelinePlanner::plan(const planning_scene::PlanningSceneConstPtr& planning
205206
if (solution) {
206207
// Choose the first solution trajectory as response
207208
result = solution.trajectory;
209+
last_successful_planner_ = solution.planner_id;
208210
return bool(result);
209211
}
210212
}

core/src/stages/connect.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
141141
const auto& path_constraints = props.get<moveit_msgs::msg::Constraints>("path_constraints");
142142

143143
const moveit::core::RobotState& final_goal_state = to.scene()->getCurrentState();
144-
std::vector<robot_trajectory::RobotTrajectoryConstPtr> sub_trajectories;
144+
std::vector<PlannerIdTrajectoryPair> sub_trajectories;
145145

146146
std::vector<planning_scene::PlanningSceneConstPtr> intermediate_scenes;
147147
planning_scene::PlanningSceneConstPtr start = from.scene();
@@ -161,7 +161,7 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
161161

162162
robot_trajectory::RobotTrajectoryPtr trajectory;
163163
success = pair.second->plan(start, end, jmg, timeout, trajectory, path_constraints);
164-
sub_trajectories.push_back(trajectory); // include failed trajectory
164+
sub_trajectories.push_back({ pair.second->getPlannerId(), trajectory });
165165

166166
if (!success)
167167
break;
@@ -181,7 +181,7 @@ void Connect::compute(const InterfaceState& from, const InterfaceState& to) {
181181
}
182182

183183
SolutionSequencePtr
184-
Connect::makeSequential(const std::vector<robot_trajectory::RobotTrajectoryConstPtr>& sub_trajectories,
184+
Connect::makeSequential(const std::vector<PlannerIdTrajectoryPair>& sub_trajectories,
185185
const std::vector<planning_scene::PlanningSceneConstPtr>& intermediate_scenes,
186186
const InterfaceState& from, const InterfaceState& to) {
187187
assert(!sub_trajectories.empty());
@@ -195,9 +195,10 @@ Connect::makeSequential(const std::vector<robot_trajectory::RobotTrajectoryConst
195195
SolutionSequence::container_type sub_solutions;
196196
for (const auto& sub : sub_trajectories) {
197197
// persistently store sub solution
198-
auto inserted = subsolutions_.insert(subsolutions_.end(), SubTrajectory(sub));
198+
auto inserted = subsolutions_.insert(subsolutions_.end(),
199+
SubTrajectory(sub.trajectory, 0.0, std::string(""), sub.planner_id));
199200
inserted->setCreator(this);
200-
if (!sub) // a null RobotTrajectoryPtr indicates a failure
201+
if (!sub.trajectory) // a null RobotTrajectoryPtr indicates a failure
201202
inserted->markAsFailure();
202203
// push back solution pointer
203204
sub_solutions.push_back(&*inserted);
@@ -217,17 +218,29 @@ Connect::makeSequential(const std::vector<robot_trajectory::RobotTrajectoryConst
217218
return std::make_shared<SolutionSequence>(std::move(sub_solutions));
218219
}
219220

220-
SubTrajectoryPtr Connect::merge(const std::vector<robot_trajectory::RobotTrajectoryConstPtr>& sub_trajectories,
221+
SubTrajectoryPtr Connect::merge(const std::vector<PlannerIdTrajectoryPair>& sub_trajectories,
221222
const std::vector<planning_scene::PlanningSceneConstPtr>& intermediate_scenes,
222223
const moveit::core::RobotState& state) {
223224
// no need to merge if there is only a single sub trajectory
224225
if (sub_trajectories.size() == 1)
225-
return std::make_shared<SubTrajectory>(sub_trajectories[0]);
226+
return std::make_shared<SubTrajectory>(sub_trajectories.at(0).trajectory, 0.0, std::string(""),
227+
sub_trajectories.at(0).planner_id);
228+
229+
// split sub_trajectories into trajectories and joined planner_ids
230+
std::string planner_ids;
231+
std::vector<robot_trajectory::RobotTrajectoryConstPtr> subs;
232+
subs.reserve(sub_trajectories.size());
233+
for (auto it = sub_trajectories.begin(); it != sub_trajectories.end(); ++it) {
234+
subs.push_back(it->trajectory);
235+
if (it != sub_trajectories.begin())
236+
planner_ids += ", ";
237+
planner_ids += it->planner_id;
238+
}
226239

227240
auto jmg = merged_jmg_.get();
228241
assert(jmg);
229242
auto timing = properties().get<TimeParameterizationPtr>("merge_time_parameterization");
230-
robot_trajectory::RobotTrajectoryPtr trajectory = task_constructor::merge(sub_trajectories, state, jmg, *timing);
243+
robot_trajectory::RobotTrajectoryPtr trajectory = task_constructor::merge(subs, state, jmg, *timing);
231244
if (!trajectory)
232245
return SubTrajectoryPtr();
233246

@@ -237,6 +250,7 @@ SubTrajectoryPtr Connect::merge(const std::vector<robot_trajectory::RobotTraject
237250
return SubTrajectoryPtr();
238251

239252
return std::make_shared<SubTrajectory>(trajectory);
253+
return std::make_shared<SubTrajectory>(trajectory, 0.0, std::string(""), planner_ids);
240254
}
241255
} // namespace stages
242256
} // namespace task_constructor

core/src/stages/move_relative.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ bool MoveRelative::compute(const InterfaceState& state, planning_scene::Planning
199199
if (getJointStateFromOffset(direction, dir, jmg, scene->getCurrentStateNonConst())) {
200200
// plan to joint-space target
201201
success = planner_->plan(state.scene(), scene, jmg, timeout, robot_trajectory, path_constraints);
202+
solution.setPlannerId(planner_->getPlannerId());
202203
} else {
203204
// Cartesian targets require an IK reference frame
204205
const moveit::core::LinkModel* link;
@@ -287,6 +288,7 @@ bool MoveRelative::compute(const InterfaceState& state, planning_scene::Planning
287288

288289
success =
289290
planner_->plan(state.scene(), *link, offset, target_eigen, jmg, timeout, robot_trajectory, path_constraints);
291+
solution.setPlannerId(planner_->getPlannerId());
290292

291293
if (robot_trajectory) { // the following requires a robot_trajectory returned from planning
292294
moveit::core::RobotStatePtr& reached_state = robot_trajectory->getLastWayPointPtr();

core/src/stages/move_to.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ bool MoveTo::compute(const InterfaceState& state, planning_scene::PlanningSceneP
209209
if (getJointStateGoal(goal, jmg, scene->getCurrentStateNonConst())) {
210210
// plan to joint-space target
211211
success = planner_->plan(state.scene(), scene, jmg, timeout, robot_trajectory, path_constraints);
212+
solution.setPlannerId(planner_->getPlannerId());
212213
} else { // Cartesian goal
213214
// Where to go?
214215
Eigen::Isometry3d target;
@@ -241,6 +242,7 @@ bool MoveTo::compute(const InterfaceState& state, planning_scene::PlanningSceneP
241242

242243
// plan to Cartesian target
243244
success = planner_->plan(state.scene(), *link, offset, target, jmg, timeout, robot_trajectory, path_constraints);
245+
solution.setPlannerId(planner_->getPlannerId());
244246
}
245247

246248
// store result

0 commit comments

Comments
 (0)