Robowflex  v0.1
Making MoveIt Easy
fetch_se2.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <chrono>
4 #include <thread>
5 
8 
9 #include <robowflex_dart/gui.h>
10 #include <robowflex_dart/io.h>
12 #include <robowflex_dart/robot.h>
13 #include <robowflex_dart/space.h>
14 #include <robowflex_dart/world.h>
15 #include <robowflex_dart/acm.h>
16 
17 #include <ompl/geometric/SimpleSetup.h>
18 #include <ompl/geometric/planners/rrt/RRTstar.h>
19 
20 using namespace robowflex;
21 
22 int main(int argc, char **argv)
23 {
24  auto world = std::make_shared<darts::World>();
25 
26  auto fetch = darts::loadMoveItRobot("fetch", //
27  "package://robowflex_resources/fetch/robots/fetch.urdf", //
28  "package://robowflex_resources/fetch/config/fetch.srdf");
29 
30  // Reparent Fetch with a planar joint
31  auto *base_link = fetch->getFrame("base_link");
32  dart::dynamics::PlanarJoint::Properties planar_joint;
33  planar_joint.mName = "planar_joint";
34 
35  base_link->moveTo<dart::dynamics::PlanarJoint>(nullptr, planar_joint);
36 
37  // Construct new group out of base and head
38  fetch->addJointToGroup("observation", "planar_joint");
39  fetch->addJointToGroup("observation", "head_pan_joint");
40  fetch->addJointToGroup("observation", "head_tilt_joint");
41 
42  world->addRobot(fetch);
43 
44  // Add obstacle
45  auto scene = std::make_shared<darts::Structure>("object");
46  scene->addGround(-0.01, 10);
47 
48  size_t nobs = 20;
49 
50  for (size_t i = 0; i < nobs; ++i)
51  {
52  dart::dynamics::WeldJoint::Properties box_joint;
53  box_joint.mName = log::format("box%1%", i);
54  box_joint.mT_ParentBodyToJoint.translation() =
55  Eigen::Vector3d(RNG::uniformReal(-4, 4), RNG::uniformReal(-4, 4), 0.5);
56  scene->addWeldedFrame(box_joint, darts::makeBox(0.5, 0.5, 1));
57  }
58 
59  for (size_t i = 0; i < nobs; ++i)
60  for (size_t j = i + 1; j < nobs; ++j)
61  scene->getACM()->disableCollision(log::format("box%1%", i), log::format("box%1%", j));
62 
63  world->addStructure(scene);
64 
65  // Planning
66 
67  darts::PlanBuilder builder(world);
68  builder.addGroup("fetch", "observation");
69 
70  builder.setStartConfiguration({
71  -5, -5, 1.57, 0., 0., //
72  });
73 
74  builder.initialize();
75 
76  auto goal = builder.getGoalConfiguration({
77  5, 5, -1.57, 0., 0., //
78  });
79 
80  builder.setGoal(goal);
81 
82  auto rrt = std::make_shared<ompl::geometric::RRTstar>(builder.info);
83  builder.ss->setPlanner(rrt);
84 
85  builder.setup();
86  builder.ss->print();
87 
88  darts::Window window(world);
89  window.run([&] {
90  ompl::base::PlannerStatus solved = builder.ss->solve(5.0);
91 
92  if (solved)
93  {
94  RBX_INFO("Found solution!");
95  window.animatePath(builder, builder.getSolutionPath(), 10);
96  }
97  else
98  RBX_WARN("No solution found");
99  });
100 
101  return 0;
102 }
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_se2.cpp:22
#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
double uniformReal(double lower_bound, double upper_bound)
Generate a random real within given bounds: [lower_bound, upper_bound)
Definition: random.cpp:25
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).
std::shared_ptr< dart::dynamics::BoxShape > makeBox(const Eigen::Ref< const Eigen::Vector3d > &v)
Create a box.
Definition: structure.cpp:370
std::string format(const std::string &fmt, Args &&... args)
Recursion base case, return string form of formatted arguments.
Definition: log.h:60
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
Functions for loading and animating scenes in Blender.