Robowflex  v0.1
Making MoveIt Easy
fetch_ik.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/tsr.h>
14 #include <robowflex_dart/world.h>
15 
16 #include <ompl/geometric/SimpleSetup.h>
17 #include <ompl/geometric/planners/rrt/RRTConnect.h>
18 
19 using namespace robowflex;
20 
21 int main(int /*argc*/, char ** /*argv*/)
22 {
23  auto world = std::make_shared<darts::World>();
24 
25  auto fetch1 = darts::loadMoveItRobot("fetch1", //
26  "package://fetch_description/robots/fetch.urdf", //
27  "package://fetch_moveit_config/config/fetch.srdf");
28  auto fetch2 = fetch1->cloneRobot("fetch2");
29  fetch2->setDof(4, 1);
30 
31  world->addRobot(fetch1);
32  world->addRobot(fetch2);
33 
34  darts::Window window(world);
35 
36  darts::PlanBuilder builder(world);
37  builder.addGroup("fetch1", "arm_with_torso");
38  builder.addGroup("fetch2", "arm_with_torso");
39 
40  builder.setStartConfiguration({
41  0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
42  0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0, //
43  });
44 
45  builder.initialize();
46 
47  darts::TSR::Specification goal1_spec;
48  goal1_spec.setFrame("fetch1", "wrist_roll_link", "base_link");
49  goal1_spec.setPose(0.4, 0.3, 0.92, //
50  // 0.5, -0.5, 0.5, 0.5);
51  0.707, 0, 0, 0.707);
52 
53  darts::TSR::Specification goal2_spec;
54  goal2_spec.setFrame("fetch2", "wrist_roll_link", "base_link");
55  goal2_spec.setPose(0.4, -0.3, 0.92, //
56  0.707, 0, 0, -0.707);
57 
58  auto goal1_tsr = std::make_shared<darts::TSR>(world, goal1_spec);
59  auto goal2_tsr = std::make_shared<darts::TSR>(world, goal2_spec);
60 
61  auto goal = builder.getGoalTSR({goal1_tsr, goal2_tsr});
62  builder.setGoal(goal);
63 
64  auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
65  rrt->setRange(1.);
66  builder.ss->setPlanner(rrt);
67 
68  builder.setup();
69  builder.ss->print();
70 
71  window.run([&]() {
73  while (true)
74  {
75  goal->startSampling();
76  ompl::base::PlannerStatus solved = builder.ss->solve(30.0);
77  goal->stopSampling();
78 
80  if (solved)
81  {
82  RBX_INFO("Found solution!");
83  window.animatePath(builder, builder.getSolutionPath());
84  }
85  else
86  RBX_WARN("No solution found");
87 
88  builder.ss->clear();
89  }
90  });
91 
92  return 0;
93 }
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.
TSRGoalPtr getGoalTSR(const TSRPtr &tsr)
Set a TSR as the goal for the planning problem (will create a TSRGoal)
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.
The specification of a TSR.
Definition: tsr.h:70
void setPose(const RobotPose &other)
Set the pose of the TSR.
Definition: tsr.cpp:93
void setFrame(const std::string &structure, const std::string &target, const std::string &base=magic::ROOT_FRAME)
Set the base and target frame.
Definition: tsr.cpp:48
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, char **)
Definition: fetch_ik.cpp:21
#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
T sleep_for(T... args)