Robowflex  v0.1
Making MoveIt Easy
ur5_cylinder.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
10 
11 using namespace robowflex;
12 
13 /* \file ur5_cylinder.cpp
14  * A simple script that demonstrates how to use RViz with Robowflex with the UR5
15  * robot. Here, the goal is created using the `addCylinderSideGrasp` function,
16  * which creates a more complicated grasp to grasp any side of a cylinder. See
17  * https://kavrakilab.github.io/robowflex/rviz.html for how to use RViz
18  * visualization. Here, the scene, the pose goal, and motion plan displayed in
19  * RViz.
20  */
21 
22 int main(int argc, char **argv)
23 {
24  // Startup ROS
25  ROS ros(argc, argv);
26 
27  // Create the default UR5 robot.
28  auto ur5 = std::make_shared<UR5Robot>();
29  ur5->initialize();
30 
31  // Create an RViz visualization helper. Publishes all topics and parameter under `/robowflex` by default.
32  IO::RVIZHelper rviz(ur5);
33 
34  RBX_INFO("RViz Initialized! Press enter to continue (after your RViz is setup)...");
35  std::cin.get();
36 
37  // Create the cylinder we want to grasp
38  RobotPose pose = RobotPose::Identity();
39  pose.translate(Eigen::Vector3d{-0.268, -0.826, 1.313});
40 
41  auto cylinder = Geometry::makeCylinder(0.025, 0.1);
42 
43  // Create an empty scene.
44  auto scene = std::make_shared<Scene>(ur5);
45  scene->updateCollisionObject("cylinder", cylinder, pose);
46 
47  // Visualize the scene.
48  rviz.updateScene(scene);
49 
50  // Create the default planner for the UR5.
51  auto planner = std::make_shared<OMPL::UR5OMPLPipelinePlanner>(ur5);
52  planner->initialize();
53 
54  // Create a motion planning request with a pose goal.
55  MotionRequestBuilder request(planner, "manipulator");
56  request.setStartConfiguration({0.0677, -0.8235, 0.9860, -0.1624, 0.0678, 0.0});
57 
58  request.addCylinderSideGrasp("ee_link", "world", //
59  pose, cylinder, //
60  0.15, 0.04, 16); //
61 
62  rviz.addGoalMarker("goal", request); // Visualize the grasping regions
63  rviz.updateMarkers();
64 
65  RBX_INFO("Scene and Goal displayed! Press enter to plan...");
66  std::cin.get();
67 
68  // Do motion planning!
69  planning_interface::MotionPlanResponse res = planner->plan(scene, request.getRequest());
70  if (res.error_code_.val != moveit_msgs::MoveItErrorCodes::SUCCESS)
71  return 1;
72 
73  // Publish the trajectory to a topic to display in RViz
74  rviz.updateTrajectory(res);
75 
76  RBX_INFO("Press enter to remove goal and scene.");
77  std::cin.get();
78 
79  rviz.removeMarker("goal");
80  rviz.updateMarkers();
81 
82  rviz.removeScene();
83 
84  RBX_INFO("Press enter to exit.");
85  std::cin.get();
86 
87  return 0;
88 }
static GeometryPtr makeCylinder(double radius, double length)
Create a cylinder.
Definition: geometry.cpp:58
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.
A helper class to build motion planning requests for a robowflex::Planner.
Definition: builder.h:34
void addCylinderSideGrasp(const std::string &ee_name, const std::string &base_name, const RobotPose &pose, const GeometryConstPtr &cylinder, double distance, double depth, unsigned int n)
Adds a set of regions to grasp a cylinder from the side. This function assumes the X-axis of the end-...
Definition: builder.cpp:355
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
RAII-pattern for starting up ROS.
Definition: util.h:52
#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_
int main(int argc, char **argv)