22 int main(
int argc,
char** argv) {
30 t.setName(
"fallback strategies in MoveTo");
32 const moveit::core::RobotModelConstPtr robot{
t.getRobotModel() };
34 assert(robot->getName() ==
"panda");
37 auto cartesian = std::make_shared<solvers::CartesianPath>();
39 auto ptp = std::make_shared<solvers::PipelinePlanner>(
"pilz_industrial_motion_planner");
40 ptp->setPlannerId(
"PTP");
42 auto rrtconnect = std::make_shared<solvers::PipelinePlanner>(
"ompl");
43 rrtconnect->setPlannerId(
"RRTConnect");
46 std::map<std::string, double> target_state;
47 robot->getJointModelGroup(
"panda_arm")->getVariableDefaultPositions(
"ready", target_state);
48 target_state[
"panda_joint1"] = +
TAU / 8;
51 auto initial_scene{ std::make_shared<planning_scene::PlanningScene>(robot) };
52 initial_scene->getCurrentStateNonConst().setToDefaultValues(robot->getJointModelGroup(
"panda_arm"),
"ready");
54 auto initial_alternatives = std::make_unique<Alternatives>(
"initial states");
58 auto fixed{ std::make_unique<stages::FixedState>(
"close to target state in workspace") };
59 auto scene{ initial_scene->diff() };
60 scene->getCurrentStateNonConst().setVariablePositions({ {
"panda_joint1", -
TAU / 8 } });
61 fixed->setState(scene);
62 initial_alternatives->add(
std::move(fixed));
66 auto fixed{ std::make_unique<stages::FixedState>(
"directly reachable without collision") };
67 auto scene{ initial_scene->diff() };
68 scene->getCurrentStateNonConst().setVariablePositions({
69 {
"panda_joint1", +
TAU / 8 },
70 {
"panda_joint4", 0 },
72 fixed->setState(scene);
73 initial_alternatives->add(
std::move(fixed));
77 auto fixed{ std::make_unique<stages::FixedState>(
"getting to target requires collision avoidance") };
78 auto scene{ initial_scene->diff() };
79 scene->getCurrentStateNonConst().setVariablePositions({ {
"panda_joint1", -
TAU / 8 } });
80 scene->processCollisionObjectMsg([]() {
81 moveit_msgs::CollisionObject
co;
83 co.header.frame_id =
"panda_link0";
84 co.operation =
co.ADD;
87 geometry_msgs::Pose
p;
90 p.position.z = 0.64 / 2;
91 p.orientation.w = 1.0;
94 co.primitives.push_back([]() {
95 shape_msgs::SolidPrimitive sp;
97 sp.dimensions = { 0.2, 0.05, 0.64 };
102 fixed->setState(scene);
103 initial_alternatives->add(
std::move(fixed));
109 auto fallbacks = std::make_unique<Fallbacks>(
"move to other side");
111 auto add_to_fallbacks{ [&](
auto& solver,
auto&
name) {
112 auto move_to = std::make_unique<stages::MoveTo>(
name, solver);
113 move_to->setGroup(
"panda_arm");
114 move_to->setGoal(target_state);
117 add_to_fallbacks(
cartesian,
"Cartesian path");
118 add_to_fallbacks(ptp,
"PTP path");
119 add_to_fallbacks(rrtconnect,
"RRT path");
126 std::cout << e <<
'\n';