Robowflex  v0.1
Making MoveIt Easy
fetch_visualization.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 /* Modified by: Juan D. Hernandez */
3 
12 #include <robowflex_library/util.h>
13 
14 using namespace robowflex;
15 
16 /* \file fetch_visualization.cpp
17  * A simple script that demonstrates how to use RViz with Robowflex with the
18  * Fetch robot. See https://kavrakilab.github.io/robowflex/rviz.html for how to
19  * use RViz visualization. Here, the scene, the pose goal, and motion plan
20  * displayed in RViz.
21  */
22 
23 static const std::string GROUP = "arm_with_torso";
24 
25 int main(int argc, char **argv)
26 {
27  // Startup ROS
28  ROS ros(argc, argv);
29 
30  // Create the default Fetch robot.
31  auto fetch = std::make_shared<FetchRobot>();
32  fetch->initialize();
33 
34  // Create an RViz visualization helper. Publishes all topics and parameter under `/robowflex` by
35  // default.
36  IO::RVIZHelper rviz(fetch);
38  bc.start();
39 
40  RBX_INFO("RViz Initialized! Press enter to continue (after your RViz is setup)...");
41  std::cin.get();
42 
43  // Load a scene from a YAML file.
44  auto scene = std::make_shared<Scene>(fetch);
45  scene->fromYAMLFile("package://robowflex_library/yaml/test_fetch.yml");
46 
47  // Visualize the scene in RViz.
48  rviz.updateScene(scene);
49 
50  // Create the default planner for the UR5.
51  auto planner = std::make_shared<OMPL::FetchOMPLPipelinePlanner>(fetch, "default");
52  planner->initialize();
53 
54  // Create a motion planning request with a pose goal.
55  MotionRequestBuilder request(planner, GROUP);
56  fetch->setGroupState(GROUP, {0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0}); // Stow
57  request.setStartConfiguration(fetch->getScratchState());
58 
59  // Create a motion planning request with a pose goal. Cube3
60  RobotPose pose = RobotPose::Identity();
61  pose.translate(Eigen::Vector3d{0.4, 0.6, 0.92});
62 
63  Eigen::Quaterniond orn{0.5, -0.5, 0.5, 0.5};
64 
65  auto region = Geometry::makeSphere(0.01);
66 
67  request.setGoalRegion("wrist_roll_link", "base_link", // links
68  pose, region, // position
69  orn, {0.1, 0.1, 0.1} // orientation
70  );
71 
72  // Display the goal region in RViz.
73  rviz.addGoalMarker("goal", request);
74  rviz.updateMarkers();
75 
76  RBX_INFO("Scene and Goal 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  // Create a trajectory object for better manipulation.
88  auto trajectory = std::make_shared<Trajectory>(res.trajectory_);
89 
90  // Output path to a file for visualization.
91  trajectory->toYAMLFile("fetch_pick.yml");
92 
93  RBX_INFO("Press enter to remove goal and scene.");
94  std::cin.get();
95 
96  // Clean up RViz.
97  rviz.removeMarker("goal");
98  rviz.updateMarkers();
99  rviz.removeScene();
100 
101  RBX_INFO("Press enter to exit.");
102  std::cin.get();
103 
104  return 0;
105 }
static GeometryPtr makeSphere(double radius)
Create a sphere.
Definition: geometry.cpp:43
RVIZ visualization helper. See Live Visualization with RViz for more information.
Definition: visualization.h:38
void removeMarker(const std::string &name)
Removes a marker that was added through addMarker().
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 addGoalMarker(const std::string &name, const MotionRequestBuilder &request)
Adds the current goal of the motion request builder as a set of markers in the marker array.
void updateTrajectory(const planning_interface::MotionPlanResponse &response)
Updates the trajectory being visualized.
Helper class to broadcast transform information on TF and joint states.
Definition: broadcaster.h:24
void start()
Begin publishing TF and joint information.
Definition: broadcaster.cpp:37
A helper class to build motion planning requests for a robowflex::Planner.
Definition: builder.h:34
void setStartConfiguration(const std::vector< double > &joints)
Set the start configuration from a vector joints. All joints are assumed to be specified and in the d...
Definition: builder.cpp:189
planning_interface::MotionPlanRequest & getRequest()
Get a reference to the currently built motion planning request.
Definition: builder.cpp:493
void setGoalRegion(const std::string &ee_name, const std::string &base_name, const RobotPose &pose, const GeometryConstPtr &geometry, const Eigen::Quaterniond &orientation, const Eigen::Vector3d &tolerances)
Set a goal region for an end-effector ee_name. Sets the position constraint from geometry at a pose p...
Definition: builder.cpp:403
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
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24
Functions for loading and animating scenes in Blender.
moveit_msgs::MoveItErrorCodes error_code_
robot_trajectory::RobotTrajectoryPtr trajectory_
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")