Skip to content

Commit 397fc07

Browse files
committed
Fix SolutionBase::fillMessage(): also write start_scene
This method was only doing half of the job, namely adding subsolutions to the message fields. However, the start_scene was not yet written. This was handled manually in some but not all callers. To avoid this inconsistency, the new method toMsg() takes care of both actions now, while the old fillMessage() method was renamed to appendTo().
1 parent bd400de commit 397fc07

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

core/include/moveit/task_constructor/storage.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,11 @@ class SolutionBase
311311
auto& markers() { return markers_; }
312312
const auto& markers() const { return markers_; }
313313

314+
/// convert solution to message
315+
void toMsg(moveit_task_constructor_msgs::Solution& solution, Introspection* introspection = nullptr) const;
314316
/// append this solution to Solution msg
315-
virtual void fillMessage(moveit_task_constructor_msgs::Solution& solution,
316-
Introspection* introspection = nullptr) const = 0;
317+
virtual void appendTo(moveit_task_constructor_msgs::Solution& solution,
318+
Introspection* introspection = nullptr) const = 0;
317319
void fillInfo(moveit_task_constructor_msgs::SolutionInfo& info, Introspection* introspection = nullptr) const;
318320

319321
/// required to dispatch to type-specific CostTerm methods via vtable
@@ -354,7 +356,7 @@ class SubTrajectory : public SolutionBase
354356
robot_trajectory::RobotTrajectoryConstPtr trajectory() const { return trajectory_; }
355357
void setTrajectory(const robot_trajectory::RobotTrajectoryPtr& t) { trajectory_ = t; }
356358

357-
void fillMessage(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection = nullptr) const override;
359+
void appendTo(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection = nullptr) const override;
358360

359361
double computeCost(const CostTerm& cost, std::string& comment) const override;
360362

@@ -387,7 +389,7 @@ class SolutionSequence : public SolutionBase
387389
void push_back(const SolutionBase& solution);
388390

389391
/// append all subsolutions to solution
390-
void fillMessage(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const override;
392+
void appendTo(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const override;
391393

392394
double computeCost(const CostTerm& cost, std::string& comment) const override;
393395

@@ -418,8 +420,8 @@ class WrappedSolution : public SolutionBase
418420
: SolutionBase(creator, cost), wrapped_(wrapped) {}
419421
explicit WrappedSolution(Stage* creator, const SolutionBase* wrapped)
420422
: WrappedSolution(creator, wrapped, wrapped->cost()) {}
421-
void fillMessage(moveit_task_constructor_msgs::Solution& solution,
422-
Introspection* introspection = nullptr) const override;
423+
void appendTo(moveit_task_constructor_msgs::Solution& solution,
424+
Introspection* introspection = nullptr) const override;
423425

424426
double computeCost(const CostTerm& cost, std::string& comment) const override;
425427

core/python/bindings/src/core.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ void export_core(pybind11::module& m) {
124124
":visualization_msgs:`Marker`: Markers to visualize important aspects of the trajectory (read-only)")
125125
.def(
126126
"toMsg",
127-
[](const SolutionBasePtr& s) {
127+
[](const SolutionBase& self) {
128128
moveit_task_constructor_msgs::Solution msg;
129-
s->fillMessage(msg);
129+
self.toMsg(msg);
130130
return msg;
131131
},
132132
"Convert to the ROS message ``Solution``");
@@ -495,7 +495,7 @@ void export_core(pybind11::module& m) {
495495

496496
MoveGroupInterface::Plan plan;
497497
moveit_task_constructor_msgs::Solution serialized;
498-
solution->fillMessage(serialized);
498+
solution->toMsg(serialized);
499499

500500
for (const moveit_task_constructor_msgs::SubTrajectory& traj : serialized.sub_trajectory) {
501501
if (!traj.trajectory.joint_trajectory.points.empty()) {

core/src/introspection.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ void Introspection::registerSolution(const SolutionBase& s) {
146146
}
147147

148148
void Introspection::fillSolution(moveit_task_constructor_msgs::Solution& msg, const SolutionBase& s) {
149-
s.fillMessage(msg, this);
150-
s.start()->scene()->getPlanningSceneMsg(msg.start_scene);
151-
149+
s.toMsg(msg, this);
152150
msg.task_id = impl->task_id_;
153151
}
154152

core/src/storage.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ void SolutionBase::markAsFailure(const std::string& msg) {
204204
}
205205
}
206206

207+
void SolutionBase::toMsg(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const {
208+
appendTo(msg, introspection);
209+
start()->scene()->getPlanningSceneMsg(msg.start_scene);
210+
}
211+
207212
void SolutionBase::fillInfo(moveit_task_constructor_msgs::SolutionInfo& info, Introspection* introspection) const {
208213
info.id = introspection ? introspection->solutionId(*this) : 0;
209214
info.cost = this->cost();
@@ -216,7 +221,7 @@ void SolutionBase::fillInfo(moveit_task_constructor_msgs::SolutionInfo& info, In
216221
std::copy(markers.begin(), markers.end(), info.markers.begin());
217222
}
218223

219-
void SubTrajectory::fillMessage(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const {
224+
void SubTrajectory::appendTo(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const {
220225
msg.sub_trajectory.emplace_back();
221226
moveit_task_constructor_msgs::SubTrajectory& t = msg.sub_trajectory.back();
222227
SolutionBase::fillInfo(t.info, introspection);
@@ -235,7 +240,7 @@ void SolutionSequence::push_back(const SolutionBase& solution) {
235240
subsolutions_.push_back(&solution);
236241
}
237242

238-
void SolutionSequence::fillMessage(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const {
243+
void SolutionSequence::appendTo(moveit_task_constructor_msgs::Solution& msg, Introspection* introspection) const {
239244
moveit_task_constructor_msgs::SubSolution sub_msg;
240245
SolutionBase::fillInfo(sub_msg.info, introspection);
241246

@@ -257,7 +262,7 @@ void SolutionSequence::fillMessage(moveit_task_constructor_msgs::Solution& msg,
257262
msg.sub_trajectory.reserve(msg.sub_trajectory.size() + subsolutions_.size());
258263
for (const SolutionBase* s : subsolutions_) {
259264
size_t current = msg.sub_trajectory.size();
260-
s->fillMessage(msg, introspection);
265+
s->appendTo(msg, introspection);
261266

262267
// zero IDs of sub solutions with same creator as this
263268
if (s->creator() == this->creator()) {
@@ -274,9 +279,8 @@ double SolutionSequence::computeCost(const CostTerm& f, std::string& comment) co
274279
return f(*this, comment);
275280
}
276281

277-
void WrappedSolution::fillMessage(moveit_task_constructor_msgs::Solution& solution,
278-
Introspection* introspection) const {
279-
wrapped_->fillMessage(solution, introspection);
282+
void WrappedSolution::appendTo(moveit_task_constructor_msgs::Solution& solution, Introspection* introspection) const {
283+
wrapped_->appendTo(solution, introspection);
280284

281285
// prepend this solutions info as a SubSolution msg
282286
moveit_task_constructor_msgs::SubSolution sub_msg;

core/src/task.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ moveit::core::MoveItErrorCode Task::execute(const SolutionBase& s) {
270270
ac.waitForServer();
271271

272272
moveit_task_constructor_msgs::ExecuteTaskSolutionGoal goal;
273-
s.fillMessage(goal.solution, pimpl()->introspection_.get());
274-
s.start()->scene()->getPlanningSceneMsg(goal.solution.start_scene);
273+
s.toMsg(goal.solution, pimpl()->introspection_.get());
275274

276275
ac.sendGoal(goal);
277276
ac.waitForResult();

demo/src/pick_place_task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ bool PickPlaceTask::execute() {
502502
// actionlib::SimpleActionClient<moveit_task_constructor_msgs::ExecuteTaskSolutionAction>
503503
// execute("execute_task_solution", true); execute.waitForServer();
504504
// moveit_task_constructor_msgs::ExecuteTaskSolutionGoal execute_goal;
505-
// task_->solutions().front()->fillMessage(execute_goal.solution);
505+
// task_->solutions().front()->toMsg(execute_goal.solution);
506506
// execute.sendGoalAndWait(execute_goal);
507507
// execute_result = execute.getResult()->error_code;
508508

0 commit comments

Comments
 (0)