Robowflex  v0.1
Making MoveIt Easy
fetch_plan.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <chrono>
4 #include <thread>
5 
7 
8 #include <robowflex_dart/gui.h>
9 #include <robowflex_dart/io.h>
11 #include <robowflex_dart/robot.h>
12 #include <robowflex_dart/space.h>
13 #include <robowflex_dart/world.h>
14 
15 #include <ompl/geometric/SimpleSetup.h>
16 #include <ompl/geometric/planners/rrt/RRTConnect.h>
17 
18 using namespace robowflex;
19 
20 int main(int argc, char **argv)
21 {
22  auto world = std::make_shared<darts::World>();
23 
24  auto fetch1 = darts::loadMoveItRobot("fetch1", //
25  "package://fetch_description/robots/fetch.urdf", //
26  "package://fetch_moveit_config/config/fetch.srdf");
27 
28  world->addRobot(fetch1);
29 
30  int nfetch = 1;
31  if (argc > 1)
32  nfetch = atoi(argv[1]);
33 
34  if (nfetch > 1)
35  {
36  auto fetch2 = fetch1->cloneRobot("fetch2");
37  fetch2->setDof(2, -1.57);
38  fetch2->setDof(3, 0.525);
39  fetch2->setDof(4, 0.525);
40  world->addRobot(fetch2);
41  }
42 
43  if (nfetch > 2)
44  {
45  auto fetch3 = fetch1->cloneRobot("fetch3");
46  fetch3->setDof(2, 1.57);
47  fetch3->setDof(3, 0.525);
48  fetch3->setDof(4, -0.525);
49  world->addRobot(fetch3);
50  }
51 
52  if (nfetch > 3)
53  {
54  auto fetch4 = fetch1->cloneRobot("fetch4");
55  fetch4->setDof(2, 3.14);
56  fetch4->setDof(3, 1.05);
57  world->addRobot(fetch4);
58  }
59 
60  darts::Window window(world);
61  window.run([&] {
62  darts::PlanBuilder builder(world);
63  builder.addGroup("fetch1", "arm_with_torso");
64  if (nfetch > 1)
65  builder.addGroup("fetch2", "arm_with_torso");
66  if (nfetch > 2)
67  builder.addGroup("fetch3", "arm_with_torso");
68  if (nfetch > 3)
69  builder.addGroup("fetch4", "arm_with_torso");
70 
71  builder.setStartConfiguration({
72  0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
73  0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
74  0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
75  0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0,
76  });
77 
78  builder.initialize();
79 
80  auto goal = builder.getGoalConfiguration({
81  0.0, 0.501, 1.281, -2.272, 2.243, -2.774, 0.976, -2.007,
82  0.13, 0.501, 1.281, -2.272, 2.243, -2.774, 0.976, -2.007, //
83  0.38, 0.501, 1.281, -2.272, 2.243, -2.774, 0.976, -2.007, //
84  0.26, 0.501, 1.281, -2.272, 2.243, -2.774, 0.976, -2.007, //
85  });
86  builder.setGoal(goal);
87 
88  auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
89  rrt->setRange(1.);
90  builder.ss->setPlanner(rrt);
91 
92  builder.setup();
93  builder.ss->print();
94 
95  ompl::base::PlannerStatus solved = builder.ss->solve(30.0);
96 
97  if (solved)
98  {
99  RBX_INFO("Found solution!");
100  window.animatePath(builder, builder.getSolutionPath());
101  }
102  else
103  RBX_WARN("No solution found");
104  });
105 
106  return 0;
107 }
A helper class to setup common OMPL structures for planning.
void setGoal(const ompl::base::GoalPtr &goal)
Set the goal for the problem.
void setup()
Calls setup routines on OMPL structures. Call after all setup is done and builder is initialized.
void setStartConfiguration(const Eigen::Ref< const Eigen::VectorXd > &q)
Set the start configuration from a configuration.
void initialize()
Initialize OMPL structures. Only call this once all constraints, groups, and other parameters have be...
ompl::base::SpaceInformationPtr info
Actual Space Information.
ompl::geometric::PathGeometric getSolutionPath(bool simplify=true, bool interpolate=true) const
Get the solution path from a successful plan.
ompl::geometric::SimpleSetupPtr ss
Simple Setup.
void addGroup(const std::string &robot, const std::string &name, std::size_t cyclic=0)
Add a robot's planning group to the controlled DoF in the state space.
std::shared_ptr< ompl::base::GoalStates > getGoalConfiguration(const Eigen::Ref< const Eigen::VectorXd > &q)
Set the goal configuration from a configuration.
Open Scene Graph GUI for DART visualization.
Definition: gui.h:67
void run(std::function< void()> thread={})
Run the GUI. Blocks.
Definition: gui.cpp:231
void animatePath(const StateSpacePtr &space, const ompl::geometric::PathGeometric &path, std::size_t times=1, double fps=60, bool block=true)
Animate a motion plan using the world.
Definition: gui.cpp:160
int main(int argc, char **argv)
Definition: fetch_plan.cpp:20
#define RBX_WARN(fmt,...)
Output a warning logging message.
Definition: log.h:110
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
RobotPtr loadMoveItRobot(const std::string &name, const std::string &urdf, const std::string &srdf)
Load a robot from a URDF and SRDF (i.e., a MoveIt enabled robot).
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25