Robowflex  v0.1
Making MoveIt Easy
ur5_custom_planning.cpp File Reference

Go to the source code of this file.

Classes

class  CustomTrajOptPlanner
 
struct  CustomTrajOptPlanner::CartCnt
 

Functions

int main (int argc, char **argv)
 

Variables

static const std::string GROUP = "manipulator"
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 86 of file ur5_custom_planning.cpp.

87 {
88  // Startup ROS
89  ROS ros(argc, argv);
90 
91  // Create the default UR5 robot.
92  auto ur5 = std::make_shared<UR5Robot>();
93  ur5->initialize();
94 
95  // Set start state and get the ee pose.
96  ur5->setGroupState(GROUP, {0.0677, -0.8235, 0.9860, -0.1624, 0.0678, 0.0});
97  const auto &ee = ur5->getModel()->getEndEffectors()[0]->getLinkModelNames()[0];
98  RobotPose pose = ur5->getLinkTF(ee);
99 
100  // Create an RViz visualization helper.
101  IO::RVIZHelper rviz(ur5);
102  RBX_INFO("RViz Initialized! Press enter to continue (after your RViz is setup)...");
103  std::cin.get();
104 
105  // Create and visualize scene.
106  auto scene = std::make_shared<Scene>(ur5);
107  scene->getCurrentState() = *ur5->getScratchState();
108  rviz.updateScene(scene);
109 
110  // Create a custom TrajOpt planner
111  auto planner = std::make_shared<CustomTrajOptPlanner>(ur5, GROUP);
112  planner->initialize(GROUP);
113  planner->options.num_waypoints = 17; // Set number of waypoints in trajectory.
114 
115  // Define desired motion of the end-effector.
116  EigenSTL::vector_Vector3d directions = {
117  {0.0, -0.3, 0.0}, {0.0, 0.0, -0.2}, {0.0, 0.3, 0.0}, {0.0, 0.0, 0.2}};
118 
119  // Define a Cartesian constraint for each location.
120  for (size_t i = 0; i < directions.size(); ++i)
121  {
123  pose.translate(directions[i]);
124  term.pose = pose;
125  term.timestep = (i + 1) * 4;
126  term.link = ee;
127  term.pos_coeffs = 1.0;
128  term.rot_coeffs = 1.0;
129 
130  planner->constraints_.push_back(term);
131  }
132 
133  // Do planning with cartesian constraints.
134  auto response = planner->plan(scene, ur5->getScratchState());
135  if (!response.first)
136  {
137  RBX_INFO("Optimization did not converge");
138  return 0;
139  }
140 
141  // Publish the trajectory to a topic to display in RViz
142  Trajectory trajectory(planner->getTrajectory());
143  rviz.updateTrajectory(trajectory);
144 
145  // Visualize the final pose.
146  scene->getCurrentState() = *ur5->getScratchState();
147  rviz.updateScene(scene);
148 
149  RBX_INFO("Press enter to exit.");
150  std::cin.get();
151 
152  return 0;
153 }
RVIZ visualization helper. See Live Visualization with RViz for more information.
Definition: visualization.h:38
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_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
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.
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")
static const std::string GROUP

Variable Documentation

◆ GROUP

const std::string GROUP = "manipulator"
static

Definition at line 20 of file ur5_custom_planning.cpp.