00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef CART_TRAJECTORY_PT_H_
00026 #define CART_TRAJECTORY_PT_H_
00027
00028 #include <moveit/kinematic_constraints/kinematic_constraint.h>
00029 #include "descartes_core/trajectory_pt.h"
00030 #include "ros/console.h"
00031
00032 typedef boost::shared_ptr<kinematic_constraints::PositionConstraint> PositionConstraintPtr;
00033 typedef boost::shared_ptr<kinematic_constraints::OrientationConstraint> OrientationConstraintPtr;
00034
00035 namespace descartes_trajectory
00036 {
00041 struct ToleranceBase
00042 {
00049 template <typename T>
00050 static T createSymmetric(double x, double y, double z, double x_tol, double y_tol, double z_tol)
00051 {
00052 double x_lower = x - x_tol / 2.0;
00053 double x_upper = x + x_tol / 2.0;
00054
00055 double y_lower = y - y_tol / 2.0;
00056 double y_upper = y + y_tol / 2.0;
00057
00058 double z_lower = z - z_tol / 2.0;
00059 double z_upper = z + z_tol / 2.0;
00060
00061 return (T(x_lower, x_upper, y_lower, y_upper, z_lower, z_upper));
00062 }
00063
00069 template <typename T>
00070 static T createSymmetric(const double &x, const double &y, const double &z, const double &tol)
00071 {
00072 return (createSymmetric<T>(x, y, z, tol, tol, tol));
00073 }
00074
00079 template <typename T>
00080 static T zeroTolerance(const double &x, const double &y, const double &z)
00081 {
00082 return (createSymmetric<T>(x, y, z, 0.0, 0.0, 0.0));
00083 }
00084
00088 ToleranceBase() : x_upper(0.), y_upper(0.), z_upper(0.), x_lower(0.), y_lower(0.), z_lower(0.)
00089 {
00090 }
00091
00096 ToleranceBase(double x_lower_lim, double x_upper_lim, double y_lower_lim, double y_upper_lim, double z_lower_lim,
00097 double z_upper_lim)
00098 : x_upper(x_upper_lim)
00099 , y_upper(y_upper_lim)
00100 , z_upper(z_upper_lim)
00101 , x_lower(x_lower_lim)
00102 , y_lower(y_lower_lim)
00103 , z_lower(z_lower_lim)
00104 {
00105 ROS_DEBUG_STREAM("Creating fully defined Tolerance(base type)");
00106 ROS_DEBUG_STREAM("Initializing x tolerance (lower/upper)" << x_lower << "/" << x_upper);
00107 ROS_DEBUG_STREAM("Initializing y tolerance (lower/upper)" << y_lower << "/" << y_upper);
00108 ROS_DEBUG_STREAM("Initializing z tolerance (lower/upper)" << z_lower << "/" << z_upper);
00109 }
00110
00111 void clear()
00112 {
00113 x_upper = y_upper = z_upper = x_lower = y_lower = z_lower = 0.;
00114 }
00115
00116 double x_upper, y_upper, z_upper, x_lower, y_lower, z_lower;
00117 };
00118
00122 struct PositionTolerance : public ToleranceBase
00123 {
00124 PositionTolerance() : ToleranceBase()
00125 {
00126 }
00127
00128 PositionTolerance(double x_lower_lim, double x_upper_lim, double y_lower_lim, double y_upper_lim, double z_lower_lim,
00129 double z_upper_lim)
00130 : ToleranceBase(x_lower_lim, x_upper_lim, y_lower_lim, y_upper_lim, z_lower_lim, z_upper_lim)
00131 {
00132 ROS_DEBUG_STREAM("Created fully defined Position Tolerance");
00133 }
00134 };
00135
00139 struct OrientationTolerance : public ToleranceBase
00140 {
00141 OrientationTolerance() : ToleranceBase()
00142 {
00143 }
00144
00145 OrientationTolerance(double x_lower_lim, double x_upper_lim, double y_lower_lim, double y_upper_lim,
00146 double z_lower_lim, double z_upper_lim)
00147 : ToleranceBase(x_lower_lim, x_upper_lim, y_lower_lim, y_upper_lim, z_lower_lim, z_upper_lim)
00148 {
00149 ROS_DEBUG_STREAM("Created fully defined Orientation Tolerance");
00150 }
00151 };
00152
00156 struct TolerancedFrame : public descartes_core::Frame
00157 {
00158 TolerancedFrame(){};
00159 TolerancedFrame(const Eigen::Affine3d &a) : descartes_core::Frame(a)
00160 {
00161 Eigen::Vector3d t = a.translation();
00162 Eigen::Matrix3d m = a.rotation();
00163 Eigen::Vector3d rxyz = m.eulerAngles(0, 1, 2);
00164 position_tolerance = ToleranceBase::createSymmetric<PositionTolerance>(t(0), t(1), t(2), 0);
00165 orientation_tolerance = ToleranceBase::createSymmetric<OrientationTolerance>(rxyz(0), rxyz(1), rxyz(2), 0);
00166 };
00167 TolerancedFrame(const descartes_core::Frame &a) : descartes_core::Frame(a)
00168 {
00169 Eigen::Vector3d t = a.frame.translation();
00170 Eigen::Matrix3d m = a.frame.rotation();
00171 Eigen::Vector3d rxyz = m.eulerAngles(0, 1, 2);
00172 position_tolerance = ToleranceBase::createSymmetric<PositionTolerance>(t(0), t(1), t(2), 0);
00173 orientation_tolerance = ToleranceBase::createSymmetric<OrientationTolerance>(rxyz(0), rxyz(1), rxyz(2), 0);
00174 };
00175
00176 TolerancedFrame(const Eigen::Affine3d &a, const PositionTolerance &pos_tol, const OrientationTolerance &orient_tol)
00177 : Frame(a), position_tolerance(pos_tol), orientation_tolerance(orient_tol)
00178 {
00179 }
00180
00181 PositionTolerance position_tolerance;
00182 OrientationTolerance orientation_tolerance;
00183 PositionConstraintPtr position_constraint;
00184 OrientationConstraintPtr orientation_constraint;
00185 };
00186
00207 class CartTrajectoryPt : public descartes_core::TrajectoryPt
00208 {
00209 public:
00210 EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
00211
00212 public:
00216 CartTrajectoryPt(const descartes_core::TimingConstraint &timing = descartes_core::TimingConstraint());
00217
00227 CartTrajectoryPt(const descartes_core::Frame &wobj_base, const TolerancedFrame &wobj_pt,
00228 const descartes_core::Frame &tool_base, const TolerancedFrame &tool_pt, double pos_increment,
00229 double orient_increment,
00230 const descartes_core::TimingConstraint &timing = descartes_core::TimingConstraint());
00231
00240 CartTrajectoryPt(const TolerancedFrame &wobj_pt, double pos_increment, double orient_increment,
00241 const descartes_core::TimingConstraint &timing = descartes_core::TimingConstraint());
00242
00249 CartTrajectoryPt(const descartes_core::Frame &wobj_pt,
00250 const descartes_core::TimingConstraint &timing = descartes_core::TimingConstraint());
00251
00252 virtual ~CartTrajectoryPt(){};
00253
00258
00259 virtual bool getClosestCartPose(const std::vector<double> &seed_state, const descartes_core::RobotModel &model,
00260 Eigen::Affine3d &pose) const;
00261
00262
00263 virtual bool getNominalCartPose(const std::vector<double> &seed_state, const descartes_core::RobotModel &model,
00264 Eigen::Affine3d &pose) const;
00265
00266
00267 virtual void getCartesianPoses(const descartes_core::RobotModel &model, EigenSTL::vector_Affine3d &poses) const;
00274
00275 virtual bool getClosestJointPose(const std::vector<double> &seed_state, const descartes_core::RobotModel &model,
00276 std::vector<double> &joint_pose) const;
00277
00278 virtual bool getNominalJointPose(const std::vector<double> &seed_state, const descartes_core::RobotModel &model,
00279 std::vector<double> &joint_pose) const;
00280
00281
00282 virtual void getJointPoses(const descartes_core::RobotModel &model,
00283 std::vector<std::vector<double> > &joint_poses) const;
00286
00287 virtual bool isValid(const descartes_core::RobotModel &model) const;
00293 virtual bool setDiscretization(const std::vector<double> &discretization);
00294
00295 virtual descartes_core::TrajectoryPtPtr copy() const
00296 {
00297 return descartes_core::TrajectoryPtPtr(new CartTrajectoryPt(*this));
00298 }
00299
00300 inline void setTool(const descartes_core::Frame &base, const TolerancedFrame &pt)
00301 {
00302 tool_base_ = base;
00303 tool_pt_ = pt;
00304 }
00305
00306 inline void setWobj(const descartes_core::Frame &base, const TolerancedFrame &pt)
00307 {
00308 wobj_base_ = base;
00309 wobj_pt_ = pt;
00310 }
00311
00312 protected:
00313 bool computeCartesianPoses(EigenSTL::vector_Affine3d &poses) const;
00314
00315 protected:
00316 descartes_core::Frame tool_base_;
00317 TolerancedFrame tool_pt_;
00318 descartes_core::Frame wobj_base_;
00319 TolerancedFrame wobj_pt_;
00321 double pos_increment_;
00322 double orient_increment_;
00323 };
00324
00325 }
00326
00327 #endif