Robowflex  v0.1
Making MoveIt Easy
fetch_scenes_visualize.cpp
Go to the documentation of this file.
1 /* Author: Constantinos Chamzas */
2 
3 // Robowflex
10 
11 using namespace robowflex;
12 
13 /* \file fetch_scenes_visualize.cpp
14  * Visualizes a set of scenes and motion plans from requests in these scenes. A
15  * number of example scene and planning request pairs are included in
16  * 'package://robowflex_library/yaml/fetch_scenes'. See the associated
17  * `fetch_scenes_benchmark.cpp` for benchmarking over these scenes. See
18  * https://kavrakilab.github.io/robowflex/rviz.html for RViz visualization.
19  */
20 
21 static const std::string GROUP = "arm_with_torso";
22 
23 int main(int argc, char **argv)
24 {
25  // Startup ROS
26  ROS ros(argc, argv);
27 
28  // Create the default Fetch robot.
29  auto fetch = std::make_shared<FetchRobot>();
30 
31  // False does not add the virtual joint since the real robot does not have one.
32  fetch->initialize(false);
33 
34  // Create an RViz visualization helper.
35  // Publishes all topics and parameter under `/robowflex` by default.
36  IO::RVIZHelper rviz(fetch);
37 
38  RBX_INFO("RViz Initialized! Press enter to continue (after your RViz is setup)...");
39  std::cin.get();
40 
41  const int start = 1;
42  const int end = 10;
43  for (int i = start; i <= end; i++)
44  {
45  const auto &is = std::to_string(i);
46  const auto &index = std::string(4 - is.size(), '0') + is;
47 
48  const auto &scene_file =
49  "package://robowflex_library/yaml/fetch_scenes/scene_vicon" + index + ".yaml";
50  const auto &request_file = "package://robowflex_library/yaml/fetch_scenes/request" + index + ".yaml";
51 
52  // Create an empty Scene.
53  auto scene = std::make_shared<Scene>(fetch);
54  if (not scene->fromYAMLFile(scene_file))
55  {
56  RBX_ERROR("Failed to read file: %s for scene", scene_file);
57  continue;
58  }
59 
60  // Create the default planner for the Fetch.
61  auto planner = std::make_shared<OMPL::FetchOMPLPipelinePlanner>(fetch, "default");
62  planner->initialize();
63 
64  // Create an empty motion planning request.
65  auto request = std::make_shared<robowflex::MotionRequestBuilder>(planner, GROUP);
66  if (not request->fromYAMLFile(request_file))
67  {
68  RBX_ERROR("Failed to read file: %s for request", request_file);
69  continue;
70  }
71 
72  // Visualize the scene.
73  rviz.updateScene(scene);
74  rviz.updateMarkers();
75 
76  RBX_INFO("Scene displayed! Press enter to plan...");
77  std::cin.get();
78 
79  // Do motion planning!
80  planning_interface::MotionPlanResponse res = planner->plan(scene, request->getRequest());
81  if (res.error_code_.val != moveit_msgs::MoveItErrorCodes::SUCCESS)
82  return 1;
83 
84  // Publish the trajectory to a topic to display in RViz
85  rviz.updateTrajectory(res);
86 
87  RBX_INFO("Press enter to remove the scene.");
88  std::cin.get();
89 
90  rviz.removeScene();
91  }
92 }
RVIZ visualization helper. See Live Visualization with RViz for more information.
Definition: visualization.h:38
void updateMarkers()
Displays the managed list of markers. Keeps track of whether markers have already been displayed and ...
void removeScene()
Removes the scene being visualized.
void updateScene(const SceneConstPtr &scene)
Updates the scene being visualized.
void updateTrajectory(const planning_interface::MotionPlanResponse &response)
Updates the trajectory being visualized.
RAII-pattern for starting up ROS.
Definition: util.h:52
int main(int argc, char **argv)
static const std::string GROUP
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102
#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.
moveit_msgs::MoveItErrorCodes error_code_
T to_string(T... args)