Skip to content

Commit dd74b59

Browse files
committed
Merge branch 'master' into ros2
2 parents fafa1c4 + bad8e13 commit dd74b59

File tree

13 files changed

+83
-43
lines changed

13 files changed

+83
-43
lines changed

capabilities/src/execute_task_solution_capability.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void ExecuteTaskSolutionCapability::execCallback(
111111
}
112112

113113
plan_execution::ExecutableMotionPlan plan;
114-
if (!constructMotionPlan(goal->solution, plan))
114+
if (!constructMotionPlan(goal->solution, plan, goal_handle))
115115
result->error_code.val = moveit_msgs::msg::MoveItErrorCodes::INVALID_MOTION_PLAN;
116116
else {
117117
RCLCPP_INFO(LOGGER, "Executing TaskSolution");
@@ -133,8 +133,9 @@ rclcpp_action::CancelResponse ExecuteTaskSolutionCapability::preemptCallback(
133133
return rclcpp_action::CancelResponse::ACCEPT;
134134
}
135135

136-
bool ExecuteTaskSolutionCapability::constructMotionPlan(const moveit_task_constructor_msgs::msg::Solution& solution,
137-
plan_execution::ExecutableMotionPlan& plan) {
136+
bool ExecuteTaskSolutionCapability::constructMotionPlan(
137+
const moveit_task_constructor_msgs::msg::Solution& solution, plan_execution::ExecutableMotionPlan& plan,
138+
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle) {
138139
moveit::core::RobotModelConstPtr model = context_->planning_scene_monitor_->getRobotModel();
139140

140141
moveit::core::RobotState state(model);
@@ -182,20 +183,26 @@ bool ExecuteTaskSolutionCapability::constructMotionPlan(const moveit_task_constr
182183
exec_traj.controller_name = sub_traj.execution_info.controller_names;
183184

184185
/* TODO add action feedback and markers */
185-
exec_traj.effect_on_success = [this,
186-
&scene_diff = const_cast<::moveit_msgs::msg::PlanningScene&>(sub_traj.scene_diff),
187-
description](const plan_execution::ExecutableMotionPlan* /*plan*/) {
188-
// Never modify joint state directly (only via robot trajectories)
189-
scene_diff.robot_state.joint_state = sensor_msgs::msg::JointState();
190-
scene_diff.robot_state.multi_dof_joint_state = sensor_msgs::msg::MultiDOFJointState();
191-
scene_diff.robot_state.is_diff = true; // silent empty JointState msg error
192-
193-
if (!moveit::core::isEmpty(scene_diff)) {
194-
RCLCPP_DEBUG_STREAM(LOGGER, "apply effect of " << description);
195-
return context_->planning_scene_monitor_->newPlanningSceneMessage(scene_diff);
196-
}
197-
return true;
198-
};
186+
exec_traj.effect_on_success =
187+
[this, &scene_diff = const_cast<::moveit_msgs::msg::PlanningScene&>(sub_traj.scene_diff), description,
188+
goal_handle, i, no = solution.sub_trajectory.size()](const plan_execution::ExecutableMotionPlan* /*plan*/) {
189+
// publish feedback
190+
auto feedback = std::make_shared<moveit_task_constructor_msgs::action::ExecuteTaskSolution::Feedback>();
191+
feedback->sub_id = i;
192+
feedback->sub_no = no;
193+
goal_handle->publish_feedback(feedback);
194+
195+
// Never modify joint state directly (only via robot trajectories)
196+
scene_diff.robot_state.joint_state = sensor_msgs::msg::JointState();
197+
scene_diff.robot_state.multi_dof_joint_state = sensor_msgs::msg::MultiDOFJointState();
198+
scene_diff.robot_state.is_diff = true; // silent empty JointState msg error
199+
200+
if (!moveit::core::isEmpty(scene_diff)) {
201+
RCLCPP_DEBUG_STREAM(LOGGER, "apply effect of " << description);
202+
return context_->planning_scene_monitor_->newPlanningSceneMessage(scene_diff);
203+
}
204+
return true;
205+
};
199206

200207
if (!moveit::core::isEmpty(sub_traj.scene_diff.robot_state) &&
201208
!moveit::core::robotStateMsgToRobotState(sub_traj.scene_diff.robot_state, state, true)) {

capabilities/src/execute_task_solution_capability.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ class ExecuteTaskSolutionCapability : public MoveGroupCapability
6060
private:
6161
using ExecuteTaskSolutionAction = moveit_task_constructor_msgs::action::ExecuteTaskSolution;
6262
using ActionServerType = rclcpp_action::Server<ExecuteTaskSolutionAction>;
63-
bool constructMotionPlan(const moveit_task_constructor_msgs::msg::Solution& solution,
64-
plan_execution::ExecutableMotionPlan& plan);
63+
bool
64+
constructMotionPlan(const moveit_task_constructor_msgs::msg::Solution& solution,
65+
plan_execution::ExecutableMotionPlan& plan,
66+
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle);
6567

6668
void execCallback(const std::shared_ptr<rclcpp_action::ServerGoalHandle<ExecuteTaskSolutionAction>>& goal_handle);
6769

core/include/moveit/task_constructor/container.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ContainerBase : public Stage
8080

8181
virtual bool canCompute() const = 0;
8282
virtual void compute() = 0;
83-
void explainFailure(std::ostream& os) const override;
83+
bool explainFailure(std::ostream& os) const override;
8484

8585
/// called by a (direct) child when a new solution becomes available
8686
virtual void onNewSolution(const SolutionBase& s) = 0;

core/include/moveit/task_constructor/stage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class Stage
242242
/// Should we generate failure solutions? Note: Always report a failure!
243243
bool storeFailures() const;
244244

245-
virtual void explainFailure(std::ostream& os) const;
245+
virtual bool explainFailure(std::ostream& /*os*/) const { return false; };
246246

247247
/// Get the stage's property map
248248
PropertyMap& properties();

core/include/moveit/task_constructor/task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Task : protected WrapperBase
139139
void printState(std::ostream& os = std::cout) const;
140140

141141
/// print an explanation for a planning failure to os
142-
void explainFailure(std::ostream& os = std::cout) const override;
142+
bool explainFailure(std::ostream& os = std::cout) const override;
143143

144144
size_t numSolutions() const { return solutions().size(); }
145145
const ordered<SolutionBaseConstPtr>& solutions() const { return stages()->solutions(); }

core/src/container.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,18 +453,21 @@ void ContainerBase::init(const moveit::core::RobotModelConstPtr& robot_model) {
453453
throw errors;
454454
}
455455

456-
void ContainerBase::explainFailure(std::ostream& os) const {
456+
bool ContainerBase::explainFailure(std::ostream& os) const {
457457
for (const auto& stage : pimpl()->children()) {
458458
if (!stage->solutions().empty())
459459
continue; // skip deeper traversal, this stage produced solutions
460460
if (stage->numFailures()) {
461461
os << stage->name() << " (0/" << stage->numFailures() << ")";
462-
stage->explainFailure(os);
462+
if (!stage->failures().empty())
463+
os << ": " << stage->failures().front()->comment();
463464
os << '\n';
464-
break;
465+
return true;
465466
}
466-
stage->explainFailure(os); // recursively process children
467+
if (stage->explainFailure(os)) // recursively process children
468+
return true;
467469
}
470+
return false;
468471
}
469472

470473
std::ostream& operator<<(std::ostream& os, const ContainerBase& container) {

core/src/stage.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,6 @@ bool Stage::storeFailures() const {
437437
return pimpl()->storeFailures();
438438
}
439439

440-
void Stage::explainFailure(std::ostream& os) const {
441-
if (!failures().empty())
442-
os << ": " << failures().front()->comment();
443-
}
444-
445440
PropertyMap& Stage::properties() {
446441
return pimpl()->properties_;
447442
}

core/src/stages/compute_ik.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,23 @@ void ComputeIK::compute() {
258258
const moveit::core::JointModelGroup* jmg = nullptr;
259259
std::string msg;
260260

261+
auto report_failure = [&s, this](const std::string& msg) {
262+
planning_scene::PlanningScenePtr scene = s.start()->scene()->diff();
263+
SubTrajectory solution;
264+
solution.markAsFailure(msg);
265+
spawn(InterfaceState(scene), std::move(solution));
266+
};
267+
261268
if (!validateEEF(props, robot_model, eef_jmg, &msg)) {
262-
RCLCPP_WARN_STREAM(LOGGER, msg);
269+
report_failure(msg);
263270
return;
264271
}
265272
if (!validateGroup(props, robot_model, eef_jmg, jmg, &msg)) {
266-
RCLCPP_WARN_STREAM(LOGGER, msg);
273+
report_failure(msg);
267274
return;
268275
}
269276
if (!eef_jmg && !jmg) {
270-
RCLCPP_WARN_STREAM(LOGGER, "Neither eef nor group are well defined");
277+
report_failure("Neither eef nor group are well defined");
271278
return;
272279
}
273280
properties().property("timeout").setDefaultValue(jmg->getDefaultIKTimeout());
@@ -281,7 +288,7 @@ void ComputeIK::compute() {
281288
tf2::fromMsg(target_pose_msg.pose, target_pose);
282289
if (target_pose_msg.header.frame_id != scene->getPlanningFrame()) {
283290
if (!scene->knowsFrameTransform(target_pose_msg.header.frame_id)) {
284-
RCLCPP_WARN_STREAM(LOGGER, "Unknown reference frame for target pose: " << target_pose_msg.header.frame_id);
291+
report_failure(fmt::format("Unknown reference frame for target pose: '{}'", target_pose_msg.header.frame_id));
285292
return;
286293
}
287294
// transform target_pose w.r.t. planning frame
@@ -296,7 +303,7 @@ void ComputeIK::compute() {
296303
// determine IK link from eef/group
297304
if (!(link = eef_jmg ? robot_model->getLinkModel(eef_jmg->getEndEffectorParentGroup().second) :
298305
jmg->getOnlyOneEndEffectorTip())) {
299-
RCLCPP_WARN_STREAM(LOGGER, "Failed to derive IK target link");
306+
report_failure("Failed to derive IK target link");
300307
return;
301308
}
302309
ik_pose_msg.header.frame_id = link->getName();
@@ -307,7 +314,7 @@ void ComputeIK::compute() {
307314
tf2::fromMsg(ik_pose_msg.pose, ik_pose);
308315

309316
if (!scene->getCurrentState().knowsFrameTransform(ik_pose_msg.header.frame_id)) {
310-
RCLCPP_WARN_STREAM(LOGGER, fmt::format("ik frame unknown in robot: '{}'", ik_pose_msg.header.frame_id));
317+
report_failure(fmt::format("ik frame unknown in robot: '{}'", ik_pose_msg.header.frame_id));
311318
return;
312319
}
313320
ik_pose = scene->getCurrentState().getFrameTransform(ik_pose_msg.header.frame_id) * ik_pose;

core/src/stages/current_state.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
/* Authors: Michael Goerner, Luca Lach, Robert Haschke */
3737

3838
#include <chrono>
39+
#include <fmt/format.h>
3940

4041
#include <moveit/task_constructor/stages/current_state.h>
4142
#include <moveit/task_constructor/storage.h>
@@ -101,7 +102,13 @@ void CurrentState::compute() {
101102
return;
102103
}
103104
}
104-
RCLCPP_WARN(LOGGER, "failed to acquire current PlanningScene");
105+
if (storeFailures()) {
106+
SubTrajectory solution;
107+
solution.markAsFailure(
108+
fmt::format("Failed to acquire current PlanningScene within timeout of {}s", timeout.count()));
109+
spawn(InterfaceState(scene_), std::move(solution));
110+
} else
111+
RCLCPP_WARN(LOGGER, "failed to acquire current PlanningScene");
105112
}
106113
} // namespace stages
107114
} // namespace task_constructor

core/src/stages/fixed_cartesian_poses.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
/* Authors: Robert Haschke */
3636

37+
#include <fmt/format.h>
38+
3739
#include <moveit/task_constructor/stages/fixed_cartesian_poses.h>
3840
#include <moveit/task_constructor/storage.h>
3941
#include <moveit/task_constructor/cost_terms.h>
@@ -88,7 +90,12 @@ void FixedCartesianPoses::compute() {
8890
if (pose.header.frame_id.empty())
8991
pose.header.frame_id = scene->getPlanningFrame();
9092
else if (!scene->knowsFrameTransform(pose.header.frame_id)) {
91-
RCLCPP_WARN(LOGGER, "Unknown frame: '%s'", pose.header.frame_id.c_str());
93+
if (storeFailures()) {
94+
SubTrajectory trajectory;
95+
trajectory.markAsFailure(fmt::format("Unknown frame: '{}'", pose.header.frame_id));
96+
spawn(InterfaceState(scene), std::move(trajectory));
97+
} else
98+
RCLCPP_WARN(LOGGER, "Unknown frame: '%s'", pose.header.frame_id.c_str());
9299
continue;
93100
}
94101

0 commit comments

Comments
 (0)