Robowflex  v0.1
Making MoveIt Easy
fetch_pick.cpp File Reference
#include <chrono>
#include <thread>
#include <ompl/geometric/SimpleSetup.h>
#include <ompl/geometric/planners/rrt/RRTConnect.h>
#include <robowflex_library/builder.h>
#include <robowflex_library/detail/fetch.h>
#include <robowflex_library/log.h>
#include <robowflex_library/planning.h>
#include <robowflex_library/robot.h>
#include <robowflex_library/scene.h>
#include <robowflex_library/tf.h>
#include <robowflex_library/util.h>
#include <robowflex_dart/gui.h>
#include <robowflex_dart/planning.h>
#include <robowflex_dart/robot.h>
#include <robowflex_dart/space.h>
#include <robowflex_dart/tsr.h>
#include <robowflex_dart/world.h>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

static const std::string GROUP = "arm_with_torso"
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file fetch_pick.cpp.

28 {
29  // Startup ROS
30  ROS ros(argc, argv);
31 
32  //
33  // Standard Robowflex setup
34  // Create the default Fetch robot and scene.
35  //
36  auto fetch = std::make_shared<FetchRobot>();
37  fetch->initialize();
38 
39  auto scene = std::make_shared<Scene>(fetch);
40  scene->fromYAMLFile("package://robowflex_library/yaml/test_fetch.yml");
41 
42  //
43  // Convert to Dart
44  //
45  auto fetch_dart = std::make_shared<darts::Robot>(fetch);
46  auto fetch_name = fetch_dart->getName();
47  auto scene_dart = std::make_shared<darts::Structure>("scene", scene);
48 
49  // Setup world
50  auto world = std::make_shared<darts::World>();
51  world->addRobot(fetch_dart);
52  world->addStructure(scene_dart);
53 
54  fetch_dart->setJoint("r_gripper_finger_joint", 0.05);
55  fetch_dart->setJoint("l_gripper_finger_joint", 0.05);
56 
57  darts::Window window(world);
58 
59  const auto &plan_to_pick = [&]() {
60  darts::PlanBuilder builder(world);
61  builder.addGroup(fetch_name, GROUP);
62 
63  darts::TSR::Specification start_spec;
64  start_spec.setFrame(fetch_name, "wrist_roll_link", "base_link");
65  start_spec.setPose(-0.2, 0.6, 0.92, //
66  0.5, -0.5, 0.5, 0.5);
67 
68  darts::TSR start_tsr(world, start_spec);
69  start_tsr.useGroup(GROUP);
70  start_tsr.initialize();
71  start_tsr.solveWorld();
72 
73  builder.setStartConfigurationFromWorld();
74  builder.initialize();
75 
76  darts::TSR::Specification goal_spec;
77  goal_spec.setFrame(fetch_name, "wrist_roll_link", "base_link");
78  goal_spec.setPose(0.4, 0.6, 1.32, //
79  0.5, -0.5, 0.5, 0.5);
80 
81  auto goal_tsr = std::make_shared<darts::TSR>(world, goal_spec);
82  auto goal = builder.getGoalTSR(goal_tsr);
83  builder.setGoal(goal);
84 
85  auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
86  rrt->setRange(2);
87  builder.ss->setPlanner(rrt);
88 
89  builder.setup();
90 
91  goal->startSampling();
92  ompl::base::PlannerStatus solved = builder.ss->solve(60.0);
93  goal->stopSampling();
94 
96  if (solved)
97  {
98  RBX_INFO("Found solution!");
99  window.animatePath(builder, builder.getSolutionPath());
100  }
101  else
102  RBX_WARN("No solution found");
103  };
104 
105  const auto &plan_to_grasp = [&]() {
106  darts::PlanBuilder builder(world);
107  builder.addGroup(fetch_name, GROUP);
108  builder.setStartConfigurationFromWorld();
109 
110  darts::TSR::Specification constraint_spec;
111  constraint_spec.setFrame(fetch_name, "wrist_roll_link", "base_link");
112  constraint_spec.setPose(0.4, 0.6, 0.92, //
113  0.5, -0.5, 0.5, 0.5);
114  constraint_spec.setNoZPosTolerance();
115 
116  auto constraint_tsr = std::make_shared<darts::TSR>(world, constraint_spec);
117  builder.addConstraint(constraint_tsr);
118  builder.initialize();
119 
120  darts::TSR::Specification goal_spec;
121  goal_spec.setFrame(fetch_name, "wrist_roll_link", "base_link");
122  goal_spec.setPose(0.4, 0.6, 0.92, //
123  0.5, -0.5, 0.5, 0.5);
124 
125  auto goal_tsr = std::make_shared<darts::TSR>(world, goal_spec);
126  auto goal = builder.getGoalTSR(goal_tsr);
127  builder.setGoal(goal);
128 
129  auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
130  rrt->setRange(2);
131  builder.ss->setPlanner(rrt);
132 
133  builder.setup();
134 
135  goal->startSampling();
136  ompl::base::PlannerStatus solved = builder.ss->solve(60.0);
137  goal->stopSampling();
138 
140  if (solved)
141  {
142  RBX_INFO("Found solution!");
143  window.animatePath(builder, builder.getSolutionPath());
144  }
145  else
146  RBX_WARN("No solution found");
147  };
148 
149  const auto &plan_to_place = [&]() {
150  darts::PlanBuilder builder(world);
151  builder.addGroup(fetch_name, GROUP);
152  builder.setStartConfigurationFromWorld();
153  builder.initialize();
154 
155  darts::TSR::Specification goal_spec;
156  goal_spec.setFrame(fetch_name, "wrist_roll_link", "base_link");
157  goal_spec.setPose(-0.2, 0.6, 0.92, //
158  0.5, -0.5, 0.5, 0.5);
159 
160  auto goal_tsr = std::make_shared<darts::TSR>(world, goal_spec);
161  auto goal = builder.getGoalTSR(goal_tsr);
162  builder.setGoal(goal);
163 
164  auto rrt = std::make_shared<ompl::geometric::RRTConnect>(builder.info, true);
165  rrt->setRange(2);
166  builder.ss->setPlanner(rrt);
167 
168  builder.setup();
169 
170  goal->startSampling();
171  ompl::base::PlannerStatus solved = builder.ss->solve(60.0);
172  goal->stopSampling();
173 
175  if (solved)
176  {
177  RBX_INFO("Found solution!");
178  window.animatePath(builder, builder.getSolutionPath());
179  }
180  else
181  RBX_WARN("No solution found");
182  };
183 
184  window.run([&] {
186  plan_to_pick();
188  plan_to_grasp();
190 
191  auto *cube = scene_dart->getFrame("Cube3");
192  fetch_dart->reparentFreeFrame(cube, "wrist_roll_link");
193 
194  plan_to_place();
195  });
196 
197  return 0;
198 }
RAII-pattern for starting up ROS.
Definition: util.h:52
A helper class to setup common OMPL structures for planning.
The specification of a TSR.
Definition: tsr.h:70
void setNoZPosTolerance()
Set no position tolerance on the Z-axis.
Definition: tsr.cpp:228
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
A Task Space Region (TSR). TSRs are workspace regions that impose a constraints on a robot....
Definition: tsr.h:63
Open Scene Graph GUI for DART visualization.
Definition: gui.h:67
static const std::string GROUP
Definition: fetch_pick.cpp:25
#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
Functions for loading and animating scenes in Blender.
T sleep_for(T... args)

Variable Documentation

◆ GROUP

const std::string GROUP = "arm_with_torso"
static

Definition at line 25 of file fetch_pick.cpp.