Robowflex  v0.1
Making MoveIt Easy
trajopt_planner.cpp
Go to the documentation of this file.
1 /* Author: Carlos Quintero Pena */
2 
3 // MoveIt
4 #include <moveit/robot_state/conversions.h>
5 #include <moveit_msgs/MoveItErrorCodes.h>
6 
7 // Robowflex
11 #include <robowflex_library/util.h>
13 
14 // Tesseract
15 #include <trajopt/file_write_callback.hpp>
16 
17 // TrajOptPlanner
20 
21 using namespace robowflex;
22 using namespace trajopt;
23 
24 TrajOptPlanner::TrajOptPlanner(const RobotPtr &robot, const std::string &group_name, const std::string &name)
25  : Planner(robot, name), group_(group_name)
26 {
27 }
28 
30 {
31  // Save manipulator name.
32  manip_ = manip;
33 
34  // Start KDL environment with the robot information.
35  env_ = std::make_shared<tesseract::tesseract_ros::KDLEnv>();
36 
37  if (!env_->init(robot_->getURDF(), robot_->getSRDF()))
38  {
39  RBX_ERROR("Error loading robot %s", robot_->getName());
40  return false;
41  }
42 
43  // Check if manipulator was correctly loaded.
44  if (!env_->hasManipulator(manip_))
45  {
46  RBX_ERROR("No manipulator found in KDL environment");
47  return false;
48  }
49 
50  // Initialize trajectory.
51  trajectory_ = std::make_shared<robot_trajectory::RobotTrajectory>(robot_->getModelConst(), group_);
52 
53  return true;
54 }
55 
56 bool TrajOptPlanner::initialize(const std::string &base_link, const std::string &tip_link)
57 {
58  // Save manipulator name.
59  manip_ = "manipulator";
60 
61  // Start KDL environment with the robot information.
62  env_ = std::make_shared<tesseract::tesseract_ros::KDLEnv>();
63 
64  if (!robot_->getModelConst()->hasLinkModel(base_link))
65  {
66  RBX_ERROR("%s does not exist in robot description", base_link);
67  return false;
68  }
69 
70  if (!robot_->getModelConst()->hasLinkModel(tip_link))
71  {
72  RBX_ERROR("%s does not exist in robot description", tip_link);
73  return false;
74  }
75 
76  if (options.verbose)
77  RBX_INFO("Adding manipulator %s from %s to %s", manip_, base_link, tip_link);
78 
79  TiXmlDocument srdf_doc;
80  srdf_doc.Parse(robot_->getSRDFString().c_str());
81 
82  auto *group_element = new TiXmlElement("group");
83  group_element->SetAttribute("name", manip_.c_str());
84  srdf_doc.FirstChildElement("robot")->LinkEndChild(group_element);
85 
86  auto *chain_element = new TiXmlElement("chain");
87  chain_element->SetAttribute("base_link", base_link.c_str());
88  chain_element->SetAttribute("tip_link", tip_link.c_str());
89  group_element->LinkEndChild(chain_element);
90 
91  srdf::ModelSharedPtr srdf;
92  srdf.reset(new srdf::Model());
93  srdf->initXml(*(robot_->getURDF()), &srdf_doc);
94 
95  if (!env_->init(robot_->getURDF(), srdf))
96  {
97  RBX_ERROR("Error loading robot %s", robot_->getName());
98  return false;
99  }
100 
101  // Check if manipulator was correctly loaded.
102  if (!env_->hasManipulator(manip_))
103  {
104  RBX_ERROR("No manipulator found in KDL environment");
105  return false;
106  }
107 
108  // Initialize trajectory.
109  trajectory_ = std::make_shared<robot_trajectory::RobotTrajectory>(robot_->getModelConst(), group_);
110 
111  return true;
112 }
113 
114 void TrajOptPlanner::setInitialTrajectory(const robot_trajectory::RobotTrajectoryPtr &init_trajectory)
115 {
117  init_type_ = InitInfo::Type::GIVEN_TRAJ;
118 }
119 
120 void TrajOptPlanner::setInitialTrajectory(const TrajArray &init_trajectory)
121 {
122  initial_trajectory_ = init_trajectory;
123  init_type_ = InitInfo::Type::GIVEN_TRAJ;
124 }
125 
126 void TrajOptPlanner::setInitType(const InitInfo::Type &init_type)
127 {
128  if (init_type != InitInfo::Type::GIVEN_TRAJ)
129  init_type_ = init_type;
130  else
131  RBX_ERROR("init type can only be set to GIVEN_TRAJ calling the setInitialTrajectory() function");
132 }
133 
134 const robot_trajectory::RobotTrajectoryPtr &TrajOptPlanner::getTrajectory() const
135 {
136  return trajectory_;
137 }
138 
139 const trajopt::TrajArray &TrajOptPlanner::getTesseractTrajectory() const
140 {
141  return tesseract_trajectory_;
142 }
143 
145 {
146  if (env_->checkInitialized())
147  return env_->getLinkNames();
148  else
149  throw Exception(1, "KDL environment not initialized with robot links!");
150 }
151 
153 {
154  if (env_->hasManipulator(manip_))
155  return env_->getManipulator(manip_)->getLinkNames();
156  else
157  throw Exception(1, "There is no loaded manipulator!");
158 }
159 
161 {
162  if (env_->hasManipulator(manip_))
163  return env_->getManipulator(manip_)->getJointNames();
164  else
165  throw Exception(1, "There is no loaded manipulator!");
166 }
167 
169 {
170  return time_;
171 }
172 
174 {
175  if (!env_->hasManipulator(manip_))
176  throw Exception(1, "There is no loaded manipulator!");
177  else
178  {
179  const auto &joint_names = env_->getManipulator(manip_)->getJointNames();
180  for (const auto &name : joints)
181  {
182  auto it = std::find(joint_names.begin(), joint_names.end(), name);
183  if (it == joint_names.end())
184  throw Exception(1, "One of the joints to be fixed does not exist");
185  else
186  {
187  int index = std::distance(joint_names.begin(), it);
188  fixed_joints_.push_back(index);
189  }
190  }
191  }
192 }
193 
196 {
198 
199  // Extract start state.
200  auto start_state = robot_->allocState();
201  moveit::core::robotStateMsgToRobotState(request.start_state, *start_state);
202  start_state->update(true);
203 
204  // Use the start state as reference state to build trajectory_.
205  ref_state_ = std::make_shared<robot_state::RobotState>(*start_state);
206 
207  // Extract goal state.
208  auto goal_state = robot_->allocState();
209  if (request.goal_constraints.size() != 1)
210  {
211  RBX_ERROR("Ambiguous goal, %lu goal goal_constraints exist, returning default goal",
212  request.goal_constraints.size());
213  res.error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS;
214  return res;
215  }
216  if (request.goal_constraints[0].joint_constraints.empty())
217  {
218  RBX_ERROR("No joint constraints specified, returning default goal");
219  res.error_code_.val = moveit_msgs::MoveItErrorCodes::INVALID_GOAL_CONSTRAINTS;
220  return res;
221  }
222 
223  std::map<std::string, double> variable_map;
224  for (const auto &joint : request.goal_constraints[0].joint_constraints)
225  variable_map[joint.joint_name] = joint.position;
226 
227  // Start state includes attached objects and values for the non-group links.
228  moveit::core::robotStateMsgToRobotState(request.start_state, *goal_state);
229  goal_state->setVariablePositions(variable_map);
230  goal_state->update(true);
231 
232  // If planner runs until timeout, use the allowed_planning_time from the request.
234  options.max_planning_time = request.allowed_planning_time;
235 
236  // Plan.
237  auto result = plan(scene, start_state, goal_state);
238  res.error_code_.val = moveit_msgs::MoveItErrorCodes::FAILURE;
239  if (result.first and result.second)
240  {
241  res.planning_time_ = time_;
242  res.trajectory_ = trajectory_;
243  res.error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
244  }
245 
246  return res;
247 }
248 
250  const robot_state::RobotStatePtr &start_state,
251  const robot_state::RobotStatePtr &goal_state)
252 {
253  // Create the tesseract environment from the scene.
255  {
256  // Attach bodies to KDL env.
258 
259  // Fill in the problem construction info and initialization.
260  auto pci = std::make_shared<ProblemConstructionInfo>(env_);
262 
263  // Add velocity cost.
264  addVelocityCost(pci);
265 
266  // Add start state.
267  addStartState(start_state, pci);
268 
269  // Add collision costs to all waypoints in the trajectory.
272 
273  // Add goal state.
274  addGoalState(goal_state, pci);
275 
276  return solve(scene, pci);
277  }
278 
279  return PlannerResult(false, false);
280 }
281 
283  const robot_state::RobotStatePtr &start_state,
284  const RobotPose &goal_pose, const std::string &link)
285 {
286  if (init_type_ == InitInfo::Type::JOINT_INTERPOLATED)
287  {
288  RBX_ERROR("Straight line interpolation can not be done with a goal_pose.");
289  return PlannerResult(false, false);
290  }
291 
292  auto begin_it = env_->getManipulator(manip_)->getLinkNames().begin();
293  auto end_it = env_->getManipulator(manip_)->getLinkNames().end();
294  auto link_it = std::find(begin_it, end_it, link);
295  if (link_it == end_it)
296  {
297  RBX_ERROR("Link %s is not part of robot manipulator", link);
298  return PlannerResult(false, false);
299  }
300 
301  // Use the start state as reference state to build trajectory_.
302  ref_state_ = std::make_shared<robot_state::RobotState>(*start_state);
303 
304  // Create the tesseract environment from the scene.
306  {
307  // Attach bodies to KDL env.
309 
310  // Fill in the problem construction info and initialization.
311  auto pci = std::make_shared<ProblemConstructionInfo>(env_);
313 
314  // Add velocity cost.
315  addVelocityCost(pci);
316 
317  // Add start state
318  addStartState(start_state, pci);
319 
320  // Add collision costs to all waypoints in the trajectory.
322 
323  // Add goal pose for link.
324  addGoalPose(goal_pose, link, pci);
325 
326  return solve(scene, pci);
327  }
328 
329  return PlannerResult(false, false);
330 }
331 
333  const std::unordered_map<std::string, double> &start_state,
334  const RobotPose &goal_pose, const std::string &link)
335 {
336  if (init_type_ == InitInfo::Type::JOINT_INTERPOLATED)
337  {
338  RBX_ERROR("Straight line interpolation can not be done with a goal_pose.");
339  return PlannerResult(false, false);
340  }
341 
342  auto begin_it = env_->getManipulator(manip_)->getLinkNames().begin();
343  auto end_it = env_->getManipulator(manip_)->getLinkNames().end();
344  auto link_it = std::find(begin_it, end_it, link);
345  if (link_it == end_it)
346  {
347  RBX_ERROR("Link %s is not part of robot manipulator", link);
348  return PlannerResult(false, false);
349  }
350 
351  // Create the tesseract environment from the scene.
353  {
354  // Fill in the problem construction info and initialization.
355  auto pci = std::make_shared<ProblemConstructionInfo>(env_);
357 
358  // Add velocity cost.
359  addVelocityCost(pci);
360 
361  // Add start state
362  addStartState(start_state, pci);
363 
364  // Add collision costs to all waypoints in the trajectory.
366 
367  // Add goal pose for link.
368  addGoalPose(goal_pose, link, pci);
369 
370  return solve(scene, pci);
371  }
372 
373  return PlannerResult(false, false);
374 }
375 
377  const std::string &start_link, const RobotPose &goal_pose,
378  const std::string &goal_link)
379 {
380  if (init_type_ == InitInfo::Type::JOINT_INTERPOLATED)
381  {
382  RBX_ERROR("Straight line interpolation can not be done with a start_pose or a goal_pose");
383  return PlannerResult(false, false);
384  }
385 
386  auto begin_it = env_->getManipulator(manip_)->getLinkNames().begin();
387  auto end_it = env_->getManipulator(manip_)->getLinkNames().end();
388  auto start_it = std::find(begin_it, end_it, start_link);
389  auto goal_it = std::find(begin_it, end_it, goal_link);
390  if ((start_it == end_it) or (goal_it == end_it))
391  {
392  RBX_ERROR("Given links %s or %s are not part of robot manipulator", start_link, goal_link);
393  return PlannerResult(false, false);
394  }
395 
396  // Create the tesseract environment from the scene.
398  {
399  // Fill in the problem construction info and initialization
400  auto pci = std::make_shared<ProblemConstructionInfo>(env_);
402 
403  // Add velocity cost.
404  addVelocityCost(pci);
405 
406  // Add start_pose for start_link.
407  addStartPose(start_pose, start_link, pci);
408 
409  // Add collision costs to all waypoints in the trajectory.
411 
412  // Add goal_pose for goal_link.
413  addGoalPose(goal_pose, goal_link, pci);
414 
415  return solve(scene, pci);
416  }
417 
418  return PlannerResult(false, false);
419 }
420 
422  const robot_state::RobotStatePtr &start_state)
423 {
424  throw Exception(1, "You need to implement virtual method TrajOptPlanner::plan() in your derived class");
425 }
426 
428 {
430  config.push_back("trajopt");
431  return config;
432 }
433 
434 void TrajOptPlanner::setWriteFile(bool file_write_cb, const std::string &file_path)
435 {
436  file_write_cb_ = file_write_cb;
437  stream_ptr_ = std::make_shared<std::ofstream>();
438  boost::filesystem::path path(file_path);
439  path /= "file_output.csv";
440  file_path_ = path.string();
441  if (file_write_cb_)
442  stream_ptr_->open(file_path_, std::ofstream::out | std::ofstream::trunc);
443 }
444 
446 {
447  pci->basic_info.convex_solver = options.backend_optimizer;
448  pci->kin = env_->getManipulator(manip_);
449  pci->basic_info.n_steps = options.num_waypoints;
450  pci->basic_info.manip = manip_;
451  pci->basic_info.dt_lower_lim = options.dt_lower_lim;
452  pci->basic_info.dt_upper_lim = options.dt_upper_lim;
453  pci->basic_info.start_fixed = options.start_fixed;
454  pci->basic_info.dofs_fixed = fixed_joints_;
455  pci->basic_info.use_time = options.use_time;
456  pci->init_info.type = init_type_;
457  pci->init_info.dt = options.init_info_dt;
458  if (init_type_ == InitInfo::Type::GIVEN_TRAJ)
459  pci->init_info.data = initial_trajectory_;
460 
461  if (options.verbose)
462  RBX_INFO("TrajOpt initialization: %d", init_type_);
463 }
464 
466 {
467  // Add joint velocity cost (without time) to penalize longer paths.
468  auto jv = std::make_shared<JointVelTermInfo>();
469  jv->targets = std::vector<double>(pci->kin->numJoints(), 0.0);
470  jv->coeffs = std::vector<double>(pci->kin->numJoints(), options.joint_vel_coeffs);
471  jv->term_type = TT_COST;
472  jv->first_step = 0;
473  jv->last_step = options.num_waypoints - 1;
474  jv->name = "joint_velocity_cost";
475  pci->cost_infos.push_back(jv);
476 }
477 
479 {
480  auto collision = std::make_shared<CollisionTermInfo>();
481  collision->name = "collision_cost";
482  collision->term_type = TT_COST;
483  collision->continuous = options.use_cont_col_avoid;
484  collision->first_step = 0;
485  collision->last_step = options.num_waypoints - 1;
486  collision->gap = options.collision_gap;
487  collision->info = createSafetyMarginDataVector(pci->basic_info.n_steps, options.default_safety_margin,
489  pci->cost_infos.push_back(collision);
490 }
491 
494 {
495  // Extract start state from request.
496  addStartState(request->getStartConfiguration(), pci);
497 }
498 
499 void TrajOptPlanner::addStartState(const robot_state::RobotStatePtr &start_state,
501 {
502  // Extract start state values.
503  std::vector<double> values(start_state->getVariablePositions(),
504  start_state->getVariablePositions() + (int)start_state->getVariableCount());
505 
506  // Set the start_state into the Tesseract environment.
507  env_->setState(start_state->getVariableNames(), values);
508  pci->basic_info.start_fixed = true;
509 }
510 
513 {
514  // Set the start_state into the Tesseract environment.
515  env_->setState(start_state);
516  pci->basic_info.start_fixed = true;
517 }
518 
519 void TrajOptPlanner::addStartPose(const RobotPose &start_pose, const std::string &link,
521 {
522  Eigen::Quaterniond rotation(start_pose.linear());
523  auto pose_constraint = std::make_shared<CartPoseTermInfo>();
524  pose_constraint->term_type = TT_CNT;
525  pose_constraint->link = link;
526  pose_constraint->timestep = 0;
527  pose_constraint->xyz = start_pose.translation();
528  pose_constraint->wxyz = Eigen::Vector4d(rotation.w(), rotation.x(), rotation.y(), rotation.z());
529  pose_constraint->pos_coeffs = Eigen::Vector3d::Constant(options.pose_cnt_pos_coeffs);
530  pose_constraint->rot_coeffs = Eigen::Vector3d::Constant(options.pose_cnt_rot_coeffs);
531  pose_constraint->name = "start_pose_cnt_link_" + link;
532  pci->cnt_infos.push_back(pose_constraint);
533 }
534 
537 {
538  // Extract goal_state from request.
539  addGoalState(request->getGoalConfiguration(), pci);
540 }
541 
542 void TrajOptPlanner::addGoalState(const robot_state::RobotStatePtr &goal_state,
544 {
545  const auto &manip_joint_names = env_->getManipulator(manip_)->getJointNames();
546 
547  // Transform (robot) goal_state to manip state.
548  std::vector<double> goal_state_values;
549  hypercube::robotStateToManipState(goal_state, manip_joint_names, goal_state_values);
550 
551  // Add goal state as a joint constraint.
552  addGoalState(goal_state_values, pci);
553 }
554 
557 {
558  auto joint_pos_constraint = std::make_shared<JointPosTermInfo>();
559  joint_pos_constraint->term_type = TT_CNT;
560  joint_pos_constraint->name = "goal_state_cnt";
561  joint_pos_constraint->coeffs = std::vector<double>(pci->kin->numJoints(), options.joint_pos_cnt_coeffs);
562  joint_pos_constraint->targets = goal_state;
563  joint_pos_constraint->first_step = options.num_waypoints - 1;
564  joint_pos_constraint->last_step = options.num_waypoints - 1;
565  pci->cnt_infos.push_back(joint_pos_constraint);
566 
567  if (init_type_ == InitInfo::Type::JOINT_INTERPOLATED)
568  pci->init_info.data =
569  Eigen::Map<const Eigen::VectorXd>(goal_state.data(), static_cast<long int>(goal_state.size()));
570 }
571 
572 void TrajOptPlanner::addGoalPose(const RobotPose &goal_pose, const std::string &link,
574 {
575  Eigen::Quaterniond rotation(goal_pose.linear());
576  auto pose_constraint = std::make_shared<CartPoseTermInfo>();
577  pose_constraint->term_type = TT_CNT;
578  pose_constraint->link = link;
579  pose_constraint->timestep = options.num_waypoints - 1;
580  pose_constraint->xyz = goal_pose.translation();
581  pose_constraint->wxyz = Eigen::Vector4d(rotation.w(), rotation.x(), rotation.y(), rotation.z());
582  pose_constraint->pos_coeffs = Eigen::Vector3d::Constant(options.pose_cnt_pos_coeffs);
583  pose_constraint->rot_coeffs = Eigen::Vector3d::Constant(options.pose_cnt_rot_coeffs);
584  pose_constraint->name = "goal_pose_cnt_link_" + link;
585  pci->cnt_infos.push_back(pose_constraint);
586 }
587 
590 {
591  PlannerResult planner_result(false, false);
592 
593  // Create optimizer and populate parameters.
594  TrajOptProbPtr prob = ConstructProblem(*pci);
595  sco::BasicTrustRegionSQP opt(prob);
596  opt.setParameters(getTrustRegionSQPParameters());
597 
598  // Add write file callback.
599  if (file_write_cb_)
600  {
601  if (!stream_ptr_->is_open())
602  stream_ptr_->open(file_path_, std::ofstream::out | std::ofstream::trunc);
603 
604  opt.addCallback(WriteCallback(stream_ptr_, prob));
605  }
606 
607  // If the planner needs to run more than once, add noise to the initial trajectory.
609  options.perturb_init_traj = true;
610 
611  // Initialize.
612  double total_time = 0.0;
613  double best_cost = std::numeric_limits<double>::infinity();
614 
615  while (true)
616  {
617  // Perturb initial trajectory if needed.
618  auto init_trajectory = prob->GetInitTraj();
620  {
621  // Perturb all waypoints but start and goal.
622  int rows = options.num_waypoints - 2;
623  int cols = pci->kin->numJoints();
624  double noise = options.noise_init_traj;
625 
626  init_trajectory.block(1, 0, rows, cols) += (Eigen::MatrixXd::Constant(rows, cols, -noise) +
627  2 * noise *
628  (Eigen::MatrixXd::Random(rows, cols) * 0.5 +
629  Eigen::MatrixXd::Constant(rows, cols, 0.5)));
630  }
631 
632  opt.initialize(trajToDblVec(init_trajectory));
633 
634  // Optimize.
635  ros::Time tStart = ros::Time::now();
636  opt.optimize();
637 
638  // Measure and print time.
639  double time = (ros::Time::now() - tStart).toSec();
640  total_time += time;
641  time_ = total_time;
642 
643  if (opt.results().status == sco::OptStatus::OPT_CONVERGED)
644  {
645  // Optimization problem converged.
646  planner_result.first = true;
647 
648  // Check for collisions.
649  auto tss_current_traj = getTraj(opt.x(), prob->GetVars());
650  auto current_traj =
651  std::make_shared<robot_trajectory::RobotTrajectory>(robot_->getModelConst(), group_);
653  current_traj);
654  auto const &ct = std::make_shared<Trajectory>(current_traj);
655  bool is_ct_collision_free = ct->isCollisionFree(scene);
656 
657  // If trajectory is better than current, update the trajectory and cost.
658  if ((opt.results().total_cost < best_cost) and is_ct_collision_free)
659  {
660  // Update best cost.
661  best_cost = opt.results().total_cost;
662 
663  // Clear current trajectory.
664  trajectory_->clear();
665 
666  // Update trajectory.
667  tesseract_trajectory_ = tss_current_traj;
668  trajectory_ = current_traj;
669 
670  // Solution is collision-free.
671  planner_result.second = true;
672  }
673  }
674 
676  (options.return_after_timeout and (total_time >= options.max_planning_time)) or
678  (planner_result.second or (total_time >= options.max_planning_time))))
679  break;
680  }
681 
682  // Print status
683  if (options.verbose)
684  {
685  RBX_INFO("OPTIMIZATION STATUS: %s", sco::statusToString(opt.results().status));
686  RBX_INFO("TOTAL PLANNING TIME: %.3f", time_);
687  RBX_INFO("COST: %.3f", best_cost);
688  RBX_INFO("COLLISION STATUS: %s", (planner_result.second) ? "COLLISION FREE" : "IN COLLISION");
689 
690  if (planner_result.first)
692  }
693 
694  // Write optimization results in file.
695  if (file_write_cb_)
696  stream_ptr_->close();
697 
698  return planner_result;
699 }
700 
701 sco::BasicTrustRegionSQPParameters TrajOptPlanner::getTrustRegionSQPParameters() const
702 {
703  sco::BasicTrustRegionSQPParameters params;
704 
705  params.improve_ratio_threshold = options.improve_ratio_threshold;
706  params.min_trust_box_size = options.min_trust_box_size;
707  params.min_approx_improve = options.min_approx_improve;
708  params.min_approx_improve_frac = options.min_approx_improve_frac;
709  params.max_iter = options.max_iter;
710  params.trust_shrink_ratio = options.trust_shrink_ratio;
711  params.trust_expand_ratio = options.trust_expand_ratio;
712  params.cnt_tolerance = options.cnt_tolerance;
713  params.max_merit_coeff_increases = options.max_merit_coeff_increases;
714  params.merit_coeff_increase_ratio = options.merit_coeff_increase_ratio;
715  params.merit_error_coeff = options.merit_error_coeff;
716  params.trust_box_size = options.trust_box_size;
717 
718  return params;
719 }
T c_str(T... args)
Exception that contains a message and an error code.
Definition: util.h:15
A shared pointer wrapper for robowflex::MotionRequestBuilder.
An abstract interface to a motion planning algorithm.
A shared pointer wrapper for robowflex::Robot.
A const shared pointer wrapper for robowflex::Scene.
const trajopt::TrajArray & getTesseractTrajectory() const
Get the trajectory that resulted in the last call to plan() in Tesseract format.
void addGoalState(const MotionRequestBuilderPtr &request, std::shared_ptr< trajopt::ProblemConstructionInfo > pci) const
Add a (joint) configuration constraint in the last waypoint taken from request.
trajopt::TrajArray tesseract_trajectory_
std::shared_ptr< std::ofstream > stream_ptr_
Debug file stream.
std::string manip_
Name of manipulator chain to check for collisions.
robot_state::RobotStatePtr ref_state_
Reference state to build moveit trajectory waypoints.
double getPlanningTime() const
Get the time spent by the planner the last time it was called.
const std::vector< std::string > & getManipulatorJoints() const
Get the joint names of the env manipulator.
const std::vector< std::string > & getEnvironmentLinks() const
Get the link names in the tesseract KDL environment.
sco::BasicTrustRegionSQPParameters getTrustRegionSQPParameters() const
Get parameters of the SQP.
double time_
Time taken by the optimizer the last time it was called.
void addCollisionAvoidance(std::shared_ptr< trajopt::ProblemConstructionInfo > pci) const
Add collision avoidance cost to the trajectory optimization for all waypoints.
struct robowflex::TrajOptPlanner::Options options
void setWriteFile(bool file_write_cb, const std::string &file_path="")
Set whether a report file (for the optimization) should be written or not.
void setInitialTrajectory(const robot_trajectory::RobotTrajectoryPtr &init_trajectory)
Set initial trajectory for TrajOpt and set init_type to GIVEN_TRAJ.
void addGoalPose(const RobotPose &goal_pose, const std::string &link, std::shared_ptr< trajopt::ProblemConstructionInfo > pci) const
Add a cartesian pose constraint goal_pose for link in the last waypoint.
void addVelocityCost(std::shared_ptr< trajopt::ProblemConstructionInfo > pci) const
Add velocity cost to the trajectory optimization.
const std::vector< std::string > & getManipulatorLinks() const
Get the link names of the env manipulator.
std::vector< std::string > getPlannerConfigs() const override
Get planner configurations offered by this planner. Any of the configurations returned can be set as ...
bool file_write_cb_
Whether to write a debug file or not.
void problemConstructionInfo(std::shared_ptr< trajopt::ProblemConstructionInfo > pci) const
Create a TrajOpt problem construction info object with default values.
trajopt::TrajArray initial_trajectory_
Initial trajectory (if any).
void fixJoints(const std::vector< std::string > &joints)
Constrain certain joints during optimization to their initial value.
std::pair< bool, bool > PlannerResult
Planner result: first->converged, second->collision_free.
PlannerResult solve(const SceneConstPtr &scene, const std::shared_ptr< trajopt::ProblemConstructionInfo > &pci)
Solve SQP optimization problem.
trajopt::InitInfo::Type init_type_
robot_trajectory::RobotTrajectoryPtr trajectory_
const robot_trajectory::RobotTrajectoryPtr & getTrajectory() const
Get the trajectory that resulted in the last call to plan().
std::string group_
Name of group to plan for.
std::string file_path_
Path of debug file.
void addStartState(const MotionRequestBuilderPtr &request, std::shared_ptr< trajopt::ProblemConstructionInfo > pci)
Add a (joint) configuration constraint in the first waypoint taken from request.
void addStartPose(const RobotPose &start_pose, const std::string &link, std::shared_ptr< trajopt::ProblemConstructionInfo > pci) const
Add a cartesian pose constraint start_pose for link in the first waypoint.
planning_interface::MotionPlanResponse plan(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
Plan a motion given a request and a scene.
bool initialize(const std::string &manip)
Initialize planner. The user must specify a chain group defined in the robot's srdf that contains all...
void setInitType(const trajopt::InitInfo::Type &init_type)
Set type of initialization to use for the trajectory optimization. Current options are: STATIONARY JO...
std::vector< int > fixed_joints_
TrajOptPlanner(const RobotPtr &robot, const std::string &group_name, const std::string &name="trajopt")
Constructor.
tesseract::tesseract_ros::KDLEnvPtr env_
KDL environment.
T data(T... args)
T distance(T... args)
T find(T... args)
T infinity(T... args)
#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
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
moveit_msgs::MotionPlanRequest MotionPlanRequest
Functions for loading and animating robots in Blender.
void manipTesseractTrajToRobotTraj(const tesseract::TrajArray &tesseract_traj, const robot_state::RobotStatePtr &ref_state, const std::string &manip, const tesseract::tesseract_ros::KDLEnvPtr &env, robot_trajectory::RobotTrajectoryPtr trajectory)
Transform a tesseract trajectory to a robot trajectory.
bool sceneToTesseractEnv(const robowflex::SceneConstPtr &scene, tesseract::tesseract_ros::KDLEnvPtr env)
Add scene collision objects to a (previously initialized) KDL environment.
Definition: conversions.cpp:17
bool addAttachedBodiesToTesseractEnv(const robot_state::RobotStatePtr &state, tesseract::tesseract_ros::KDLEnvPtr env)
Add bodies attached to the robot scratch state to the KDL environment.
void robotTrajToManipTesseractTraj(const robot_trajectory::RobotTrajectoryPtr &robot_traj, const std::string &manip, const tesseract::tesseract_ros::KDLEnvPtr &env, tesseract::TrajArray &trajectory)
Transform a robot_trajectory to a tesseract manipulator trajectory.
void robotStateToManipState(const robot_state::RobotStatePtr &robot_state, const std::vector< std::string > &manip_joint_names, std::vector< double > &manip_joint_values)
Transform a robot_state to a vector representing joint values for the manipulator (in the order given...
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.
T push_back(T... args)
T size(T... args)
moveit_msgs::MoveItErrorCodes error_code_
robot_trajectory::RobotTrajectoryPtr trajectory_
double pose_cnt_rot_coeffs
Coefficients for pose constraints (rotation).
bool use_time
Whether any cost/cnt use time.
bool use_cont_col_avoid
Whether to use continuous collision avoidance or not.
double merit_coeff_increase_ratio
Ratio that we increate coeff each time.
sco::ModelType backend_optimizer
Optimizer to use.
double joint_vel_coeffs
Coefficients for joint_vel costs.
double max_merit_coeff_increases
Number of times that we jack up penalty coefficient.
double joint_pos_cnt_coeffs
Coefficients for joint position constraints.
double default_safety_margin
Default safety margin for collision avoidance.
double merit_error_coeff
Initial penalty coefficient.
double init_info_dt
Value of dt in init_info.
bool start_fixed
Whether to use the current env state as a fixed initial state.
int num_waypoints
Number of waypoints.
double trust_box_size
Current size of trust region (component-wise).
double max_iter
The max number of iterations.
double pose_cnt_pos_coeffs
Coefficients for pose constraints (position).
double default_safety_margin_coeffs
Coefficients for safety margin.