Robowflex  v0.1
Making MoveIt Easy
fetch_tabletop_inits.cpp
Go to the documentation of this file.
1 /* Author: Carlos Quintero Pena*/
2 
6 #include <robowflex_library/io.h>
11 
12 using namespace robowflex;
13 
14 /* \file fetch_tabletop_inits.cpp
15  * A simple script that shows how to use TrajOpt to plan in a manipulation task using different
16  * initializations. The scene and request are loaded from yaml files. Three initializations are possible:
17  * STATIONARY, JOINT_INTERPOLATED and GIVEN_TRAJ. This script shows example of the first two.
18  */
19 
20 static const std::string GROUP = "arm";
21 
22 int main(int argc, char **argv)
23 {
24  // Startup ROS
25  ROS ros(argc, argv);
26 
27  // Create the default Fetch robot.
28  auto fetch = std::make_shared<FetchRobot>();
29  fetch->initialize(false);
30 
31  // Load tabletop scene.
32  auto scene = std::make_shared<Scene>(fetch);
33  scene->fromYAMLFile("package://robowflex_tesseract/scenes/table/scene.yaml");
34 
35  // Attach object to end effector.
36  scene->attachObject(*fetch->getScratchState(), "Can1");
37 
38  // Create a TrajOpt planner for Fetch.
39  auto planner = std::make_shared<TrajOptPlanner>(fetch, GROUP);
40  planner->initialize("torso_lift_link", "gripper_link");
41 
42  // Set planner parameters.
43  planner->options.num_waypoints = 8; // Select number of waypoints in trajectory.
44 
45  // Load request.
46  const auto &request = std::make_shared<MotionRequestBuilder>(fetch);
47  request->fromYAMLFile("package://robowflex_tesseract/scenes/table/request.yaml");
48 
49  // RVIZ helper.
50  const auto &rviz = std::make_shared<IO::RVIZHelper>(fetch);
51  rviz->updateScene(scene);
52  rviz->visualizeState(request->getStartConfiguration());
53 
54  RBX_INFO("Visualizing start state");
55  RBX_INFO("Press Enter to try to plan with STATIONARY initialization");
56  std::cin.ignore();
57 
58  // Initialize all waypoints at the start state. This is the default initialization.
59  planner->setInitType(trajopt::InitInfo::Type::STATIONARY);
60 
61  // Do motion planning.
62  auto res = planner->plan(scene, request->getRequest());
63  if (res.error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
64  rviz->updateTrajectory(res);
65 
66  rviz->visualizeState(request->getGoalConfiguration());
67 
68  RBX_INFO("Visualizing goal state");
69  RBX_INFO("Press Enter to try to plan with JOINT_INTERPOLATED initialization");
70  std::cin.ignore();
71 
72  // Initialize using a straight-line between start and goal in C-Space.
73  planner->setInitType(trajopt::InitInfo::Type::JOINT_INTERPOLATED);
74 
75  // Do motion planning.
76  res = planner->plan(scene, request->getRequest());
77  if (res.error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
78  rviz->updateTrajectory(res);
79 
80  rviz->visualizeState(request->getGoalConfiguration());
81 
82  RBX_INFO("Visualizing goal state");
83  RBX_INFO("Press Enter to exit");
84  std::cin.ignore();
85 
86  return 0;
87 }
RAII-pattern for starting up ROS.
Definition: util.h:52
int main(int argc, char **argv)
static const std::string GROUP
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
Functions for loading and animating scenes in Blender.