42 namespace cost_functions
91 const moveit_msgs::MotionPlanRequest &req,
93 moveit_msgs::MoveItErrorCodes& error_code)
95 using namespace Eigen;
104 const std::vector<moveit_msgs::Constraints>& goals = req.goal_constraints;
107 ROS_ERROR(
"A goal constraint was not provided");
108 error_code.val = error_code.INVALID_GOAL_CONSTRAINTS;
113 bool found_goal =
false;
114 for(
const auto& g: goals)
120 state_->updateLinkTransforms();
121 Eigen::Affine3d start_tool_pose =
state_->getGlobalLinkTransform(
tool_link_);
123 if(cartesian_constraints.is_initialized())
127 ROS_DEBUG_STREAM(
"ToolGoalTolerance cost function will use tolerance: "<<tool_goal_tolerance_.transpose());
135 ROS_DEBUG(
"%s a cartesian goal pose in MotionPlanRequest was not provided,calculating it from FK",
getName().c_str());
138 if(g.joint_constraints.empty())
141 error_code.val = error_code.INVALID_GOAL_CONSTRAINTS;
146 const std::vector<moveit_msgs::JointConstraint>& joint_constraints = g.joint_constraints;
149 for(
auto& jc: joint_constraints)
151 state_->setVariablePosition(jc.joint_name,jc.position);
176 std::size_t start_timestep,
177 std::size_t num_timesteps,
178 int iteration_number,
180 Eigen::VectorXd& costs,
184 using namespace Eigen;
185 using namespace utils::kinematics;
188 auto compute_scaled_error = [](
const VectorXd& val,VectorXd&
min,VectorXd&
max) -> VectorXd
191 capped_val = (val.array() >
max.array()).select(
max,val);
192 capped_val = (val.array() < min.array()).select(min,val);
193 auto range =
max - min;
194 VectorXd scaled = (capped_val - min).array()/(range.array());
201 state_->updateLinkTransforms();
206 Eigen::Vector3d angles_err = tf.rotation().eulerAngles(2,1,0);
207 angles_err.reverseInPlace();
217 double pos_error = scaled_twist_error.head(3).cwiseAbs().maxCoeff();
218 double orientation_error = scaled_twist_error.tail(3).cwiseAbs().maxCoeff();
221 costs.resize(parameters.cols());
222 costs.setConstant(0.0);
230 void ToolGoalPose::done(
bool success,
int total_iterations,
double final_cost,
const Eigen::MatrixXd& parameters)
const std::string & getMessage() const
bool decodeCartesianConstraint(moveit::core::RobotModelConstPtr model, const moveit_msgs::Constraints &constraints, Eigen::Affine3d &tool_pose, std::vector< double > &tolerance, std::string target_frame="")
const std::vector< std::string > & getLinkModelNames() const
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)
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
double min(double a, double b)
#define ROS_DEBUG_STREAM(args)
bool isCartesianConstraints(const moveit_msgs::Constraints &c)
const std::vector< const JointModel * > & getActiveJointModels() const
#define ROS_ERROR_STREAM(args)
double max(double a, double b)