Robowflex  v0.1
Making MoveIt Easy
ur5_cartesian.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
10 #include <robowflex_library/util.h>
11 
12 using namespace robowflex;
13 
14 /* \file ur5_cartesian.cpp
15  * Simple demonstration of how to use the SimpleCartesianPlanner with the UR5 combined with visualization.
16  */
17 
18 int main(int argc, char **argv)
19 {
20  // Startup ROS
21  ROS ros(argc, argv);
22 
23  // Create the default UR5 robot.
24  auto ur5 = std::make_shared<UR5Robot>();
25  ur5->initialize();
26  ur5->setGroupState("manipulator", {0.0677, -0.8235, 0.9860, -0.1624, 0.0678, 0.0});
27 
28  // Create an RViz visualization helper. Publishes all topics and parameter under `/robowflex` by default.
29  IO::RVIZHelper rviz(ur5);
30 
31  RBX_INFO("RViz Initialized! Press enter to continue (after your RViz is setup)...");
32  std::cin.get();
33 
34  auto scene = std::make_shared<Scene>(ur5);
35 
36  // Create a Cartesian planner for the UR5.
37  auto cartesian_planner = std::make_shared<SimpleCartesianPlanner>(ur5, "cartesian");
38 
39  EigenSTL::vector_Vector3d directions = {
40  {0.0, -0.3, 0.0}, {0.0, 0.0, -0.2}, {0.0, 0.3, 0.0}, {0.0, 0.0, 0.2}, // Move in an YZ rectangle
41  {0.2, 0.0, 0.0}, {0.0, -0.3, 0.0}, {-0.2, 0.0, 0.0}, {0.0, 0.3, 0.0}, // Move in an XY rectangle
42  {0.4, -0.3, 0.2}, {-0.4, 0.3, -0.2} // Diagonal move
43  };
44 
45  for (const auto &direction : directions)
46  {
47  RBX_INFO("Moving end-effector in direction [%1%, %2%, %3%]", //
48  direction[0], direction[1], direction[2]);
49 
50  // Visualize the scene.
51  scene->getCurrentState() = *ur5->getScratchState();
52  rviz.updateScene(scene);
53 
54  // Create the IK Query, and then set the scene for collision checking.
55  // Uses directional offset IKQuery constructor.
56  Robot::IKQuery query("manipulator", "ee_link", *ur5->getScratchState(), direction);
57  query.scene = scene;
58 
59  // Plan for a straight interpolation of the end-effector to the query.
60  auto response = cartesian_planner->plan(*ur5->getScratchState(), query);
61  if (response.error_code_.val != moveit_msgs::MoveItErrorCodes::SUCCESS)
62  {
63  RBX_ERROR("Planning failed!");
64  return 1;
65  }
66 
67  // Publish the trajectory to a topic to display in RViz
68  Trajectory trajectory(response.trajectory_);
70 
71  // Set the scratch state to the end of the computed trajectory.
72  ur5->setState(trajectory.getFinalPositions());
73 
74  RBX_INFO("Press enter to continue to next direction.");
75  std::cin.get();
76  }
77 
78  // Visualize the final pose.
79  scene->getCurrentState() = *ur5->getScratchState();
80  rviz.updateScene(scene);
81 
82  RBX_INFO("Press enter to exit.");
83  std::cin.get();
84 
85  return 0;
86 }
RVIZ visualization helper. See Live Visualization with RViz for more information.
Definition: visualization.h:38
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
The Trajectory class is a wrapper around MoveIt!'s robot_trajectory::RobotTrajectory,...
Definition: trajectory.h:43
#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.
Robot IK Query options. IK queries in Robowflex consist of: a) A position specified by some geometric...
SceneConstPtr scene
If provided, use this scene for collision checking.
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")
int main(int argc, char **argv)