Go to the documentation of this file.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 #include <collision_proximity_planner/treefksolverjointposaxis.hpp>
00038 #include <iostream>
00039
00040 using namespace std;
00041
00042 namespace KDL {
00043
00044 TreeFkSolverJointPosAxis::TreeFkSolverJointPosAxis(const Tree& tree, const std::string& reference_frame):
00045 tree_(tree),
00046 reference_frame_(reference_frame)
00047 {
00048 segment_names_.clear();
00049 assignSegmentNumber(tree_.getRootSegment());
00050 std::map<std::string, int>::iterator reference_frame_it = segment_name_to_index_.find(reference_frame);
00051 if (reference_frame_it == segment_name_to_index_.end())
00052 {
00053 cout << "TreeFkSolverJointPosAxis: Reference frame " << reference_frame << " could not be found! Forward kinematics will be performed in world frame.";
00054 }
00055 else
00056 {
00057 reference_frame_index_ = reference_frame_it->second;
00058 }
00059 num_segments_ = segment_names_.size();
00060 num_joints_ = tree_.getNrOfJoints();
00061 }
00062
00063 TreeFkSolverJointPosAxis::~TreeFkSolverJointPosAxis()
00064 {
00065 }
00066
00067 int TreeFkSolverJointPosAxis::JntToCart(const JntArray& q_in, std::vector<Vector>& joint_pos, std::vector<Vector>& joint_axis, std::vector<Frame>& segment_frames) const
00068 {
00069 joint_pos.resize(num_joints_);
00070 joint_axis.resize(num_joints_);
00071 segment_frames.resize(num_segments_);
00072
00073
00074 treeRecursiveFK(q_in, joint_pos, joint_axis, segment_frames, Frame::Identity(), tree_.getRootSegment(), 0);
00075
00076
00077 Frame inv_ref_frame = segment_frames[reference_frame_index_].Inverse();
00078
00079
00080 for (int i=0; i<num_segments_; i++)
00081 {
00082 segment_frames[i] = inv_ref_frame * segment_frames[i];
00083 }
00084
00085
00086 for (int i=0; i<num_joints_; i++)
00087 {
00088 joint_axis[i] = inv_ref_frame * joint_axis[i];
00089 joint_pos[i] = inv_ref_frame * joint_pos[i];
00090 }
00091
00092 return 0;
00093 }
00094
00095 int TreeFkSolverJointPosAxis::treeRecursiveFK(const JntArray& q_in, std::vector<Vector>& joint_pos, std::vector<Vector>& joint_axis, std::vector<Frame>& segment_frames,
00096 const Frame& previous_frame, const SegmentMap::const_iterator this_segment, int segment_nr) const
00097 {
00098 Frame this_frame = previous_frame;
00099
00100
00101 double jnt_p = 0;
00102 if (this_segment->second.segment.getJoint().getType() != Joint::None)
00103 {
00104 int q_nr = this_segment->second.q_nr;
00105 jnt_p = q_in(q_nr);
00106 joint_pos[q_nr] = this_frame * this_segment->second.segment.getJoint().JointOrigin();
00107 joint_axis[q_nr] = this_frame.M * this_segment->second.segment.getJoint().JointAxis();
00108 }
00109
00110
00111 this_frame = this_frame * this_segment->second.segment.pose(jnt_p);
00112 segment_frames[segment_nr] = this_frame;
00113 segment_nr++;
00114
00115
00116 for (vector<SegmentMap::const_iterator>::const_iterator child=this_segment->second.children.begin(); child !=this_segment->second.children.end(); child++)
00117 segment_nr = treeRecursiveFK(q_in, joint_pos, joint_axis, segment_frames, this_frame, *child, segment_nr);
00118 return segment_nr;
00119 }
00120
00121 void TreeFkSolverJointPosAxis::assignSegmentNumber(const SegmentMap::const_iterator this_segment)
00122 {
00123 int num = segment_names_.size();
00124 segment_names_.push_back(this_segment->first);
00125 segment_name_to_index_[this_segment->first] = num;
00126
00127
00128 for (vector<SegmentMap::const_iterator>::const_iterator child=this_segment->second.children.begin(); child !=this_segment->second.children.end(); child++)
00129 {
00130 assignSegmentNumber(*child);
00131 }
00132 }
00133
00134 const std::vector<std::string> TreeFkSolverJointPosAxis::getSegmentNames() const
00135 {
00136 return segment_names_;
00137 }
00138
00139 const std::map<std::string, int> TreeFkSolverJointPosAxis::getSegmentNameToIndex() const
00140 {
00141 return segment_name_to_index_;
00142 }
00143
00144 int TreeFkSolverJointPosAxis::segmentNameToIndex(std::string name) const
00145 {
00146 return segment_name_to_index_.find(name)->second;
00147 }
00148
00149 }