00001 00003 // 00004 //Contents: Class CJoints 00005 // 00006 //Relations: 00007 // CJoints --> CActive ---o CRedundant 00008 // |---> CPassive -| 00009 // 00010 // Class CActive/CPassive is derived from class CJoints 00011 // Class CRedundant constains entities of CActive and CPassive 00012 // 00013 //CJoints is pure virtual class, it represents a chain of joint. 00014 // 00015 //Revision History: 00016 // Date Author Description 00017 // --------------------------------------------------------- 00018 // Mar-2003: Z.Yao First version implemented 00019 // 00020 //Others: 00021 // a.[Mar-2003] 00023 00024 #include "kinematics/linkbase.h" 00025 #include <math.h> 00026 #include "math\math2.h" 00027 #include "Joints.h" 00028 00029 //------------------------------------------------------------------ 00030 // 00031 //Construction and Deconstruction function 00032 // 00033 //------------------------------------------------------------------ 00034 CJoints::CJoints() 00035 { 00036 baseFrame = firstJoint = lastJoint = jointNum = 0; 00037 } 00038 00039 CJoints::CJoints(FrameManager* frameManager) 00040 :frameManager(frameManager) 00041 { 00042 baseFrame = firstJoint = lastJoint = jointNum = 0; 00043 } 00044 00045 CJoints::~CJoints() 00046 {} 00047 00048 //------------------------------------------------------------------ 00049 //This function is used to compute the distance between two 00050 //joint variables. 00051 // 00052 //Input Parameter: 00053 // q1/q2: two joint variables 00054 // link: corresponding robot link 00055 // 00056 //Ouput Parameter: 00057 // N.A 00058 // 00059 //Return Value: 00060 // distance in double precise; 00061 //------------------------------------------------------------------ 00062 double CJoints::Distance(LinkBase *link, double q1, double q2) 00063 { 00064 double dist = 0 ; 00065 double jmax = link->JointMax() ; 00066 double jmin = link->JointMin() ; 00067 double dist1 = fabs( q2 - q1 ) ; 00068 if(link->JointWraps() ) 00069 { 00070 double dist2 = fabs( jmax - q1 ) + fabs( q2 - jmin ) ; 00071 double dist3 = fabs( jmax - q2 ) + fabs( q1 - jmin ) ; 00072 dist = Min( dist1, dist2, dist3 ) ; //IMPROVE: this is a rapid funciton 00073 } 00074 else 00075 { 00076 dist = dist1 ; 00077 } 00078 return dist; 00079 } 00080 00081 //------------------------------------------------------------------ 00082 // 00083 //Set the robot in the environment 00084 // 00085 //------------------------------------------------------------------ 00086 void CJoints::SetRobot(R_OpenChain *robot) 00087 { 00088 this->robot =robot; 00089 std::list< LinkBase* > allLinks = robot->GetAllLinks() ; 00090 for( std::list< LinkBase* >::iterator i = allLinks.begin(); i != allLinks.end(); i++ ) 00091 { 00092 LinkBase* link = ( *i )->Clone(); 00093 links.push_back( link ) ; 00094 } 00095 } 00096 00097 //------------------------------------------------------------------ 00098 // 00099 //Set Frame Manager 00100 // 00101 //------------------------------------------------------------------ 00102 void CJoints::SetFrameManager(FrameManager* frameManager) 00103 { 00104 this->frameManager = frameManager; 00105 } 00106 00107 //------------------------------------------------------------------ 00108 // 00109 //Set base frame of this joint chain 00110 // 00111 //------------------------------------------------------------------ 00112 void CJoints::SetBaseFrame(unsigned int frame) 00113 { 00114 baseFrame = frame; 00115 } 00116 00117 //------------------------------------------------------------------ 00118 // 00119 //Set the first joint in the joint chain 00120 // 00121 //------------------------------------------------------------------ 00122 void CJoints::SetFirstJoint(unsigned int joint) 00123 { 00124 firstJoint = joint; 00125 } 00126 00127 //------------------------------------------------------------------ 00128 // 00129 //Set the last joint in the joint chain 00130 // 00131 //------------------------------------------------------------------ 00132 void CJoints::SetLastJoint(unsigned int joint) 00133 { 00134 lastJoint = joint; 00135 jointNum = lastJoint-firstJoint+1; 00136 }