constrained_cartesian_goal.cpp
Go to the documentation of this file.
1 
29 #include <ros/console.h>
30 #include <Eigen/Geometry>
35 #include <XmlRpcException.h>
36 
38 
39 static int CARTESIAN_DOF_SIZE = 6;
40 static const double DEFAULT_POS_TOLERANCE = 0.001;
41 static const double DEFAULT_ROT_TOLERANCE = 0.01;
42 
43 namespace stomp_moveit
44 {
45 namespace update_filters
46 {
47 
49  name_("ConstrainedCartesianGoal")
50 {
51 
52 }
53 
55 {
56 
57 }
58 
59 bool ConstrainedCartesianGoal::initialize(moveit::core::RobotModelConstPtr robot_model_ptr,
60  const std::string& group_name,const XmlRpc::XmlRpcValue& config)
61 {
62  group_name_ = group_name;
63  robot_model_ = robot_model_ptr;
64  ik_solver_.reset(new stomp_moveit::utils::kinematics::IKSolver(robot_model_ptr,group_name));
65 
66  return configure(config);
67 }
68 
70 {
71  using namespace XmlRpc;
72  return true;
73 }
74 
75 bool ConstrainedCartesianGoal::setMotionPlanRequest(const planning_scene::PlanningSceneConstPtr& planning_scene,
76  const moveit_msgs::MotionPlanRequest &req,
77  const stomp_core::StompConfiguration &config,
78  moveit_msgs::MoveItErrorCodes& error_code)
79 {
80  using namespace Eigen;
81  using namespace moveit::core;
82  using namespace utils::kinematics;
83 
84  const JointModelGroup* joint_group = robot_model_->getJointModelGroup(group_name_);
85  int num_joints = joint_group->getActiveJointModels().size();
86  tool_link_ = joint_group->getLinkModelNames().back();
87  state_.reset(new RobotState(robot_model_));
88  robotStateMsgToRobotState(req.start_state,*state_);
89 
90  // update kinematic model
91  ik_solver_->setKinematicState(*state_);
92 
93  const std::vector<moveit_msgs::Constraints>& goals = req.goal_constraints;
94  if(goals.empty())
95  {
96  ROS_ERROR("A goal constraint was not provided");
97  error_code.val = error_code.INVALID_GOAL_CONSTRAINTS;
98  return false;
99  }
100 
101  // save tool goal pose and constraints
102  bool found_goal = false;
103  for(const auto& g: goals)
104  {
106  {
107  // tool cartesian goal data
108  state_->updateLinkTransforms();
109  Eigen::Affine3d start_tool_pose = state_->getGlobalLinkTransform(tool_link_);
110  boost::optional<moveit_msgs::Constraints> cartesian_constraints = utils::kinematics::curateCartesianConstraints(g,start_tool_pose);
111  if(cartesian_constraints.is_initialized())
112  {
114  robot_model_->getRootLinkName());
115  }
116 
117  if(found_goal)
118  {
119  break; // a Cartesian goal was found, done
120  }
121  }
122  }
123 
124 
125  // compute the tool goal pose from the goal joint configuration if there exists any
126  if(!found_goal)
127  {
128  ROS_DEBUG("%s a cartesian goal pose in MotionPlanRequest was not provided,calculating it from FK",getName().c_str());
129 
130  for(const auto& g: goals)
131  {
132  // check joint constraints
133  if(g.joint_constraints.empty())
134  {
135  ROS_WARN_STREAM("No joint values for the goal were found");
136  continue;
137  }
138 
139  // compute FK to obtain tool pose
140  const std::vector<moveit_msgs::JointConstraint>& joint_constraints = g.joint_constraints;
141 
142  // copying goal values into state
143  for(auto& jc: joint_constraints)
144  {
145  state_->setVariablePosition(jc.joint_name,jc.position);
146  }
147 
148  // storing tool goal pose and tolerance
149  state_->update(true);
150  tool_goal_pose_ = state_->getGlobalLinkTransform(tool_link_);
152  double ptol = DEFAULT_POS_TOLERANCE;
153  double rtol = DEFAULT_ROT_TOLERANCE;
154  tool_goal_tolerance_ << ptol, ptol, ptol, rtol, rtol, rtol;
155  found_goal = true;
156  break;
157  }
158  }
159 
160  if(!found_goal)
161  {
162  ROS_ERROR("%s No valid goal pose was found",getName().c_str());
163  error_code.val = error_code.INVALID_GOAL_CONSTRAINTS;
164  return false;
165  }
166 
167  error_code.val = error_code.SUCCESS;
168  return true;
169 }
170 
171 bool ConstrainedCartesianGoal::filter(std::size_t start_timestep,
172  std::size_t num_timesteps,
173  int iteration_number,
174  const Eigen::MatrixXd& parameters,
175  Eigen::MatrixXd& updates,
176  bool& filtered)
177 {
178  using namespace Eigen;
179  using namespace moveit::core;
180  using namespace stomp_moveit::utils;
181 
182 
183  filtered = false;
184  VectorXd goal_joint_pose;
185  VectorXd seed = parameters.rightCols(1) + updates.rightCols(1);
186 
187  // solve kinematics
188  if(ik_solver_->solve(seed,tool_goal_pose_,goal_joint_pose,tool_goal_tolerance_))
189  {
190  filtered = true;
191  updates.rightCols(1) = goal_joint_pose - parameters.rightCols(1);
192  }
193  else
194  {
195  ROS_DEBUG("%s failed failed to solve ik using noisy goal pose as seed, zeroing updates",getName().c_str());
196  filtered = true;
197  updates.rightCols(1) = Eigen::VectorXd::Zero(updates.rows());
198  }
199 
200  return true;
201 }
202 
203 } /* namespace update_filters */
204 } /* namespace stomp_moveit */
bool decodeCartesianConstraint(moveit::core::RobotModelConstPtr model, const moveit_msgs::Constraints &constraints, Eigen::Affine3d &tool_pose, std::vector< double > &tolerance, std::string target_frame="")
virtual bool filter(std::size_t start_timestep, std::size_t num_timesteps, int iteration_number, const Eigen::MatrixXd &parameters, Eigen::MatrixXd &updates, bool &filtered) override
Forces the goal to be within the tool&#39;s task manifold.
virtual bool setMotionPlanRequest(const planning_scene::PlanningSceneConstPtr &planning_scene, const moveit_msgs::MotionPlanRequest &req, const stomp_core::StompConfiguration &config, moveit_msgs::MoveItErrorCodes &error_code) override
Stores the planning details.
const std::vector< std::string > & getLinkModelNames() const
Eigen::Affine3d tool_goal_pose_
The desired goal pose for the active plan request.
boost::optional< moveit_msgs::Constraints > curateCartesianConstraints(const moveit_msgs::Constraints &c, const Eigen::Affine3d &ref_pose, double default_pos_tol=0.0005, double default_rot_tol=M_PI)
static int CARTESIAN_DOF_SIZE
This defines a underconstrained goal update filter. It forces the goal cartesian tool pose into the t...
static const double DEFAULT_ROT_TOLERANCE
virtual bool configure(const XmlRpc::XmlRpcValue &config) override
Sets internal members of the plugin from the configuration data.
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
#define ROS_WARN_STREAM(args)
bool isCartesianConstraints(const moveit_msgs::Constraints &c)
PLUGINLIB_EXPORT_CLASS(stomp_moveit::update_filters::ConstrainedCartesianGoal, stomp_moveit::update_filters::StompUpdateFilter)
Forces the goal cartesian tool pose into the task space.
stomp_moveit::utils::kinematics::IKSolverPtr ik_solver_
virtual bool initialize(moveit::core::RobotModelConstPtr robot_model_ptr, const std::string &group_name, const XmlRpc::XmlRpcValue &config) override
Initializes and configures.
static const double DEFAULT_POS_TOLERANCE
const std::vector< const JointModel * > & getActiveJointModels() const
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


stomp_plugins
Author(s): Jorge Nicho
autogenerated on Fri May 8 2020 03:35:53