builder.cpp
Go to the documentation of this file.
00001 #include "moveit_goal_builder/builder.h"
00002 
00003 #include <map>
00004 #include <string>
00005 
00006 #include "geometry_msgs/Pose.h"
00007 #include "moveit/robot_state/conversions.h"
00008 #include "moveit/robot_state/robot_state.h"
00009 #include "moveit_msgs/BoundingVolume.h"
00010 #include "moveit_msgs/Constraints.h"
00011 #include "moveit_msgs/JointConstraint.h"
00012 #include "moveit_msgs/MoveGroupGoal.h"
00013 #include "moveit_msgs/PositionConstraint.h"
00014 #include "shape_msgs/SolidPrimitive.h"
00015 
00016 #include "ros/ros.h"
00017 
00018 typedef std::map<std::string, double> JointValues;
00019 typedef std::map<std::string, geometry_msgs::Pose> PoseGoals;
00020 
00021 namespace moveit_goal_builder {
00022 Builder::Builder(const std::string& planning_frame,
00023                  const std::string& group_name)
00024     : planning_frame(planning_frame),
00025       group_name(group_name),
00026       plan_only(false),
00027       workspace_parameters(),
00028       planning_time(5.0),
00029       planner_id(kRRTConnect),
00030       num_planning_attempts(1),
00031       max_velocity_scaling_factor(1.0),
00032       max_acceleration_scaling_factor(1.0),
00033       can_look(false),
00034       can_replan(false),
00035       replan_attempts(3),
00036       replan_delay(2.0),
00037       joint_tolerance(1e-4),
00038       position_tolerance(1e-4),
00039       orientation_tolerance(1e-3),
00040       joint_goal_(),
00041       pose_goals_(),
00042       start_state_(),
00043       active_target_(JOINT) {}
00044 
00045 void Builder::Build(moveit_msgs::MoveGroupGoal* goal) const {
00046   goal->request.group_name = group_name;
00047   goal->request.num_planning_attempts = num_planning_attempts;
00048   goal->request.max_velocity_scaling_factor = max_velocity_scaling_factor;
00049   goal->request.max_acceleration_scaling_factor =
00050       max_acceleration_scaling_factor;
00051   goal->request.allowed_planning_time = planning_time;
00052   goal->request.planner_id = planner_id;
00053   goal->request.workspace_parameters = workspace_parameters;
00054 
00055   if (start_state_) {
00056     robot_state::robotStateToRobotStateMsg(*start_state_,
00057                                            goal->request.start_state);
00058   } else {
00059     goal->request.start_state.is_diff = true;
00060   }
00061 
00062   if (active_target_ == JOINT) {
00063     goal->request.goal_constraints.resize(1);
00064     moveit_msgs::Constraints c1;
00065     for (JointValues::const_iterator it = joint_goal_.begin();
00066          it != joint_goal_.end(); ++it) {
00067       moveit_msgs::JointConstraint jc;
00068       jc.joint_name = it->first;
00069       jc.position = it->second;
00070       jc.tolerance_above = joint_tolerance;
00071       jc.tolerance_below = joint_tolerance;
00072       jc.weight = 1.0;
00073       c1.joint_constraints.push_back(jc);
00074     }
00075     goal->request.goal_constraints[0] = c1;
00076   } else if (active_target_ == POSE) {
00077     goal->request.goal_constraints.resize(1);
00078     moveit_msgs::Constraints& constraint = goal->request.goal_constraints[0];
00079 
00080     for (PoseGoals::const_iterator it = pose_goals_.begin();
00081          it != pose_goals_.end(); ++it) {
00082       // Add position constraint
00083       moveit_msgs::PositionConstraint pc;
00084       pc.header.frame_id = planning_frame;
00085       pc.link_name = it->first;
00086       shape_msgs::SolidPrimitive sp;
00087       sp.type = shape_msgs::SolidPrimitive::SPHERE;
00088       sp.dimensions.push_back(position_tolerance);
00089       moveit_msgs::BoundingVolume bv;
00090       bv.primitives.push_back(sp);
00091       bv.primitive_poses.push_back(it->second);
00092       pc.constraint_region = bv;
00093       pc.weight = 1.0;
00094       constraint.position_constraints.push_back(pc);
00095 
00096       moveit_msgs::OrientationConstraint oc;
00097       oc.header.frame_id = planning_frame;
00098       oc.link_name = it->first;
00099       oc.orientation = it->second.orientation;
00100       oc.absolute_x_axis_tolerance = orientation_tolerance;
00101       oc.absolute_y_axis_tolerance = orientation_tolerance;
00102       oc.absolute_z_axis_tolerance = orientation_tolerance;
00103       oc.weight = 1.0;
00104       constraint.orientation_constraints.push_back(oc);
00105     }
00106   } else {
00107     ROS_ERROR_NAMED("moveit_goal_builder",
00108                     "Unable to construct goal representation");
00109   }
00110 
00111   goal->request.path_constraints = path_constraints_;
00112 
00113   goal->planning_options.plan_only = plan_only;
00114   goal->planning_options.look_around = can_look;
00115   goal->planning_options.replan = can_replan;
00116   goal->planning_options.replan_attempts = replan_attempts;
00117   goal->planning_options.replan_delay = replan_delay;
00118   goal->planning_options.planning_scene_diff.is_diff = true;
00119   goal->planning_options.planning_scene_diff.robot_state.is_diff = true;
00120 }
00121 
00122 void Builder::GetJointGoal(std::map<std::string, double>* joint_goal) const {
00123   *joint_goal = joint_goal_;
00124 }
00125 
00126 void Builder::SetJointGoal(const std::map<std::string, double>& joints) {
00127   active_target_ = JOINT;
00128   joint_goal_ = joints;
00129 }
00130 
00131 void Builder::GetPoseGoals(
00132     std::map<std::string, geometry_msgs::Pose>* pose_goals) const {
00133   *pose_goals = pose_goals_;
00134 }
00135 
00136 void Builder::SetPoseGoals(
00137     const std::map<std::string, geometry_msgs::Pose>& pose_goals) {
00138   active_target_ = POSE;
00139   pose_goals_ = pose_goals;
00140 }
00141 
00142 void Builder::ClearPoseGoals() { pose_goals_.clear(); }
00143 
00144 void Builder::AddPoseGoal(const std::string& ee_link,
00145                           const geometry_msgs::Pose& goal) {
00146   active_target_ = POSE;
00147   pose_goals_[ee_link] = goal;
00148 }
00149 
00150 void Builder::GetPathConstraints(moveit_msgs::Constraints* constraints) const {
00151   *constraints = path_constraints_;
00152 }
00153 
00154 void Builder::SetPathConstraints(const moveit_msgs::Constraints& constraints) {
00155   path_constraints_ = constraints;
00156 }
00157 
00158 void Builder::ClearPathConstraints() {
00159   path_constraints_.joint_constraints.clear();
00160   path_constraints_.orientation_constraints.clear();
00161   path_constraints_.position_constraints.clear();
00162   path_constraints_.visibility_constraints.clear();
00163 }
00164 
00165 void Builder::AddPathOrientationConstraint(
00166     const moveit_msgs::OrientationConstraint& oc) {
00167   path_constraints_.orientation_constraints.push_back(oc);
00168 }
00169 
00170 robot_state::RobotStatePtr Builder::StartState() const { return start_state_; }
00171 
00172 void Builder::SetStartState(const robot_state::RobotState& start_state) {
00173   start_state_.reset(new robot_state::RobotState(start_state));
00174 }
00175 
00176 void Builder::SetStartStateToCurrentState() { start_state_.reset(); }
00177 }  // namespace moveit_goal_builder


moveit_goal_builder
Author(s):
autogenerated on Sat Jun 8 2019 18:52:57