28 #include <stomp_moveit/utils/multivariate_gaussian.h> 33 #include <boost/filesystem.hpp> 48 namespace noise_generators
52 name_(
"GoalGuidedMultivariateGaussian"),
71 const JointModelGroup* joint_group = robot_model_ptr->getJointModelGroup(group_name);
74 ROS_ERROR(
"Invalid joint group %s",group_name.c_str());
101 ROS_ERROR(
"%s the 'stddev' parameter has fewer elements than the number of joints",
getName().c_str());
106 for(
auto i = 0u; i < stddev_param.
size(); i++)
108 stddev_[i] =
static_cast<double>(stddev_param[i]);
123 const moveit_msgs::MotionPlanRequest &req,
125 moveit_msgs::MoveItErrorCodes& error_code)
134 const moveit_msgs::MotionPlanRequest &req,
136 moveit_msgs::MoveItErrorCodes& error_code)
138 using namespace Eigen;
141 auto fill_diagonal = [](Eigen::MatrixXd& m,
double coeff,
int diag_index)
143 std::size_t size = m.rows() - std::abs(diag_index);
144 m.diagonal(diag_index) = VectorXd::Constant(size,coeff);
149 Eigen::MatrixXd
A = MatrixXd::Zero(num_timesteps,num_timesteps);
157 Eigen::MatrixXd covariance = MatrixXd::Identity(num_timesteps,num_timesteps);
158 covariance = A.transpose() * A;
159 covariance = covariance.fullPivLu().inverse();
160 double max_val = covariance.array().abs().matrix().maxCoeff();
161 covariance /= max_val;
174 error_code.val = error_code.SUCCESS;
181 const moveit_msgs::MotionPlanRequest &req,
183 moveit_msgs::MoveItErrorCodes& error_code)
185 using namespace Eigen;
187 using namespace utils::kinematics;
200 const std::vector<moveit_msgs::Constraints>& goals = req.goal_constraints;
203 ROS_ERROR(
"A goal constraint was not provided");
204 error_code.val = error_code.INVALID_GOAL_CONSTRAINTS;
207 bool found_valid =
false;
208 for(
const auto& g: goals)
213 state_->updateLinkTransforms();
214 Eigen::Affine3d start_tool_pose =
state_->getGlobalLinkTransform(
tool_link_);
216 if(cartesian_constraints.is_initialized())
218 Eigen::Affine3d tool_goal_pose;
233 ROS_DEBUG(
"%s a cartesian goal pose in MotionPlanRequest was not provided,using default cartesian tolerance",
getName().c_str());
242 error_code.val = error_code.SUCCESS;
248 std::size_t start_timestep,
249 std::size_t num_timesteps,
250 int iteration_number,
252 Eigen::MatrixXd& parameters_noise,
253 Eigen::MatrixXd& noise)
255 using namespace Eigen;
258 VectorXd goal_joint_pose, goal_joint_noise;
259 if(parameters.rows() !=
stddev_.size())
261 ROS_ERROR(
"%s Number of rows in parameters %i differs from expected number of joints",
getName().c_str(),
int(parameters.rows()));
267 goal_joint_noise = goal_joint_pose - parameters.rightCols(1);
271 ROS_DEBUG(
"%s failed to generate random goal pose in the task space, not applying noise at goal",
getName().c_str());
272 goal_joint_noise = VectorXd::Zero(parameters.rows());
277 for(
auto d = 0u;
d < parameters.rows() ;
d++)
282 sign = goal_joint_noise(
d) > 0 ? 1 : -1;
284 raw_noise_.size(),0,std::abs(goal_joint_noise(
d)));
287 parameters_noise = parameters + noise;
294 using namespace Eigen;
300 for(
auto d = 0u;
d < noise.size();
d++)
306 state_->setJointGroupPositions(
group_,reference_joint_pose);
307 state_->updateLinkTransforms();
310 Affine3d noisy_tool_pose = tool_pose * Translation3d(Vector3d(n(0),n(1),n(2)))*
311 AngleAxisd(n(3),Vector3d::UnitX())*AngleAxisd(n(4),Vector3d::UnitY())*AngleAxisd(n(5),Vector3d::UnitZ());
315 ROS_DEBUG(
"%s could not solve ik, returning noiseless goal pose",
getName().c_str());
316 goal_joint_pose= reference_joint_pose;
moveit::core::RobotStatePtr state_
stomp_moveit::utils::kinematics::IKSolverPtr ik_solver_
virtual bool configure(const XmlRpc::XmlRpcValue &config) override
Sets internal members of the plugin from the configuration data.
virtual bool generateRandomGoal(const Eigen::VectorXd &reference_joint_pose, Eigen::VectorXd &goal_joint_pose)
Genereates a random tool pose by apply noise on the redundant axis to a reference tool pose;...
bool decodeCartesianConstraint(moveit::core::RobotModelConstPtr model, const moveit_msgs::Constraints &constraints, Eigen::Affine3d &tool_pose, std::vector< double > &tolerance, std::string target_frame="")
static const double DEFAULT_POS_TOLERANCE
virtual bool setupNoiseGeneration(const planning_scene::PlanningSceneConstPtr &planning_scene, const moveit_msgs::MotionPlanRequest &req, const stomp_core::StompConfiguration &config, moveit_msgs::MoveItErrorCodes &error_code)
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.
static const std::vector< int > ACC_MATRIX_DIAGONAL_INDICES
virtual bool initialize(moveit::core::RobotModelConstPtr robot_model_ptr, const std::string &group_name, const XmlRpc::XmlRpcValue &config) override
Initializes and configures.
static const int CARTESIAN_DOF_SIZE
virtual bool generateNoise(const Eigen::MatrixXd ¶meters, std::size_t start_timestep, std::size_t num_timesteps, int iteration_number, int rollout_number, Eigen::MatrixXd ¶meters_noise, Eigen::MatrixXd &noise) override
Generates a noisy trajectory from the parameters.
const std::vector< std::string > & getLinkModelNames() const
boost::variate_generator< RGNType, boost::uniform_real<> > RandomGenerator
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)
This class generates noisy trajectories to an under-constrained cartesian goal pose.
moveit::core::RobotModelConstPtr robot_model_
std::vector< double > stddev_
The standard deviations applied to each joint, [num_dimensions x 1.
const std::vector< std::string > & getActiveJointModelNames() const
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
std::vector< utils::MultivariateGaussianPtr > traj_noise_generators_
Randomized numerical distribution generators, [6 x 1].
#define ROS_DEBUG_STREAM(args)
This class generates noisy trajectories to an under-constrained cartesian goal pose.
bool isCartesianConstraints(const moveit_msgs::Constraints &c)
static const double DEFAULT_ROT_TOLERANCE
Eigen::VectorXd tool_goal_tolerance_
static const std::vector< double > ACC_MATRIX_DIAGONAL_VALUES
const std::vector< const JointModel * > & getActiveJointModels() const
virtual std::string getName() const
virtual ~GoalGuidedMultivariateGaussian()
GoalGuidedMultivariateGaussian()
PLUGINLIB_EXPORT_CLASS(stomp_moveit::noise_generators::GoalGuidedMultivariateGaussian, stomp_moveit::noise_generators::StompNoiseGenerator)
Eigen::VectorXd raw_noise_
The noise vector.
virtual bool setupGoalConstraints(const planning_scene::PlanningSceneConstPtr &planning_scene, const moveit_msgs::MotionPlanRequest &req, const stomp_core::StompConfiguration &config, moveit_msgs::MoveItErrorCodes &error_code)