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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #ifndef CHOMP_COLLISION_POINT_H_
00038 #define CHOMP_COLLISION_POINT_H_
00039
00040 #include <kdl/frames.hpp>
00041 #include <vector>
00042 #include <Eigen/Core>
00043 #include <Eigen/Geometry>
00044 #include <algorithm>
00045
00046 namespace chomp
00047 {
00048
00049 class ChompCollisionPoint
00050 {
00051 public:
00052 ChompCollisionPoint(const std::vector<int>& parent_joints, double radius, double clearance,
00053 int segment_number, const KDL::Vector& position);
00054 ChompCollisionPoint(const ChompCollisionPoint &point, const std::vector<int>& parent_joints);
00055 virtual ~ChompCollisionPoint();
00056
00057 bool isParentJoint(int joint) const;
00058 double getRadius() const;
00059 double getVolume() const;
00060 double getClearance() const;
00061 double getInvClearance() const;
00062 int getSegmentNumber() const;
00063 const KDL::Vector& getPosition() const;
00064
00065 const std::vector<int>& getParentJoints() const {
00066 return parent_joints_;
00067 }
00068
00069 void getTransformedPosition(std::vector<KDL::Frame>& segment_frames, KDL::Vector& position) const;
00070
00071 template<typename Derived>
00072 void getJacobian(std::vector<Eigen::Map<Eigen::Vector3d> >& joint_pos, std::vector<Eigen::Map<Eigen::Vector3d> >& joint_axis,
00073 Eigen::Map<Eigen::Vector3d>& collision_point_pos, Eigen::MatrixBase<Derived>& jacobian, const std::vector<int>& group_joint_to_kdl_joint_index) const;
00074
00075 private:
00076 std::vector<int> parent_joints_;
00077 double radius_;
00078 double volume_;
00079 double clearance_;
00080 double inv_clearance_;
00081 int segment_number_;
00082 KDL::Vector position_;
00083 };
00084
00085 inline bool ChompCollisionPoint::isParentJoint(int joint) const
00086 {
00087 return(find(parent_joints_.begin(), parent_joints_.end(), joint) != parent_joints_.end());
00088 }
00089
00090 inline double ChompCollisionPoint::getRadius() const
00091 {
00092 return radius_;
00093 }
00094
00095 inline double ChompCollisionPoint::getVolume() const
00096 {
00097 return volume_;
00098 }
00099
00100 inline double ChompCollisionPoint::getClearance() const
00101 {
00102 return clearance_;
00103 }
00104
00105 inline double ChompCollisionPoint::getInvClearance() const
00106 {
00107 return inv_clearance_;
00108 }
00109
00110 inline int ChompCollisionPoint::getSegmentNumber() const
00111 {
00112 return segment_number_;
00113 }
00114
00115 inline const KDL::Vector& ChompCollisionPoint::getPosition() const
00116 {
00117 return position_;
00118 }
00119
00120 template<typename Derived>
00121 void ChompCollisionPoint::getJacobian(std::vector<Eigen::Map<Eigen::Vector3d> >& joint_pos, std::vector<Eigen::Map<Eigen::Vector3d> >& joint_axis,
00122 Eigen::Map<Eigen::Vector3d>& collision_point_pos, Eigen::MatrixBase<Derived>& jacobian, const std::vector<int>& group_joint_to_kdl_joint_index) const
00123 {
00124
00125 for(unsigned int joint = 0; joint < group_joint_to_kdl_joint_index.size(); joint++) {
00126 if(!isParentJoint(group_joint_to_kdl_joint_index[joint])) {
00127
00128 jacobian.col(joint).setZero();
00129 }
00130 else
00131 {
00132 int kj = group_joint_to_kdl_joint_index[joint];
00133 jacobian.col(joint) = joint_axis[kj].cross(collision_point_pos - joint_pos[kj]);
00134 }
00135 }
00136 }
00137
00138 inline void ChompCollisionPoint::getTransformedPosition(std::vector<KDL::Frame>& segment_frames, KDL::Vector& position) const
00139 {
00140 position = segment_frames[segment_number_] * position_;
00141 }
00142
00143 }
00144
00145 #endif