planners/inversekin/Redundant.cpp

Go to the documentation of this file.
00001 
00002 //
00003 //Contents: Class CRedundant
00004 // 
00005 //Relations:
00006 //      CJoints --> CActive  ---o CRedundant
00007 //            |---> CPassive -|
00008 //
00009 //      Class CActive/CPassive is derived from class CJoints
00010 //      Class CRedundant constains entities of CActive and CPassive
00011 //
00012 //CRedundant is used to do configuration generation for redundant robots.
00013 //It can generate a configuration randomly, or generate a configuration 
00014 //to statisfy a end-effector certain pose. For the latter case, generally, 
00015 // it partition robot into active joints and passive joint, while the 
00016 //active joint variables are randomly generated and the passive joint 
00017 //variables are computed by pose of active joints and required end-effector pose.
00018 //
00019 //The basic idea is similar to the following paper, for more information, 
00020 //please refer to that.
00021 //
00022 //      L.Han and N.Amato. A kinematics-based probabilistic roadmap method
00023 //      for closed kinematic chains. Workshop on Algorithmic Foundations of
00024 //      Robotics, 2000.
00025 //
00026 //Revision History:
00027 //       Date     Author    Description
00028 //      ---------------------------------------------------------
00029 //     Mar-2003:  Z.Yao     First version implemented
00030 //
00031 //Other Notes:
00032 //     a. [Mar-2003]: We actually assume only one active chain and 
00033 //        one passive joint chain for every redundant robot. 
00034 //        Each chain might contain a certain number of joints. 
00035 //
00037 
00038 #include "math\math2.h"
00039 #include "Redundant.h"
00040 #include "robots\r_openchain.h"
00041 #include <windows.h>
00042 
00043 //------------------------------------------------------------------
00044 //
00045 //Construction and Deconstruction function
00046 //
00047 //------------------------------------------------------------------
00048 CRedundant::CRedundant()
00049 {}
00050 
00051 CRedundant::CRedundant(FrameManager *frameManager)
00052                 :passive(frameManager),
00053                 active(frameManager),
00054                 frameManager(frameManager)
00055 {}
00056 
00057 CRedundant::~CRedundant()
00058 {}
00059 
00060 //------------------------------------------------------------------
00061 //
00062 //Set Frame Manager
00063 //
00064 //------------------------------------------------------------------
00065 void CRedundant::SetFrameManager(FrameManager* frameManager)
00066 {
00067         this->frameManager = frameManager;
00068         active.SetFrameManager(frameManager);
00069         passive.SetFrameManager(frameManager);
00070 }
00071 
00072 //------------------------------------------------------------------
00073 //
00074 //Set base frame of passive joints
00075 //
00076 //------------------------------------------------------------------
00077 void CRedundant::SetPassiveBaseFrame(unsigned int frame)
00078 {
00079         //Default: be the frame {0}
00080         passive.SetBaseFrame(frame);
00081 }
00082 
00083 //------------------------------------------------------------------
00084 //
00085 //Set the first joint in the passive joint chain
00086 //
00087 //------------------------------------------------------------------
00088 void CRedundant::SetPassiveFirstJoint(unsigned int joint)
00089 {
00090         passive.SetFirstJoint(joint);
00091 }
00092 
00093 //------------------------------------------------------------------
00094 //
00095 //Set the last joint in the passive joint chain
00096 //
00097 //------------------------------------------------------------------
00098 void CRedundant::SetPassiveLastJoint(unsigned int joint)
00099 {
00100         passive.SetLastJoint(joint);
00101         passiveJointNum = passive.jointNum;
00102         //passive.SetEndEffectFrame(joint+1);
00103 }
00104 
00105 //------------------------------------------------------------------
00106 //
00107 //Set the base frame of passive joints
00108 //
00109 //------------------------------------------------------------------
00110 void CRedundant::SetActiveBaseFrame(unsigned int frame)
00111 {
00112         active.SetBaseFrame(frame);
00113 }
00114 
00115 //------------------------------------------------------------------
00116 //
00117 //Set the first joint in the active joint chain
00118 //
00119 //------------------------------------------------------------------
00120 void CRedundant::SetActiveFirstJoint(unsigned int joint)
00121 {
00122         active.SetFirstJoint(joint);
00123 }
00124 
00125 //------------------------------------------------------------------
00126 //
00127 //Set the last joint in the active joint chain
00128 //
00129 //------------------------------------------------------------------
00130 void CRedundant::SetActiveLastJoint(unsigned int joint)
00131 {
00132         active.SetLastJoint(joint);
00133         activeJointNum = active.jointNum;
00134 }
00135 
00136 //------------------------------------------------------------------
00137 //This function is use to set collision detector;
00138 //
00139 //Input Parameter:
00140 //      collisionDetector: Collision detector
00141 //
00142 //Ouput Parameter:
00143 //      N.A
00144 //
00145 //Return Value:
00146 //      N.A
00147 //------------------------------------------------------------------
00148 void CRedundant::SetCollisionDetector (CD_BasicStyle* collisionDetector)
00149 {
00150         this->collisionDetector = collisionDetector;
00151         if( dynamic_cast<R_OpenChain*>(collisionDetector->GetRobot(0)) )
00152         {
00153                 this->robot = (R_OpenChain *)collisionDetector->GetRobot(0);
00154                 active.SetRobot(this->robot);
00155                 passive.SetRobot(this->robot);
00156 
00157                 std::list< LinkBase* > allLinks = robot->GetAllLinks() ;
00158                 for( std::list< LinkBase* >::iterator i = allLinks.begin(); i != allLinks.end(); i++ )
00159                 {
00160                         LinkBase* link = ( *i )->Clone();
00161                         links.push_back( link ) ;
00162                 }
00163         }
00164         else
00165         {
00166                 this->robot = NULL;
00167         }
00168 }
00169 
00170 //------------------------------------------------------------------
00171 //This function is use to get a end-effector frame by a given
00172 //configuration
00173 //
00174 //Input Parameter:
00175 //      conf: given configuration
00176 //
00177 //Ouput Parameter:
00178 //      frame: corresponding pose
00179 //
00180 //Return Value:
00181 //      N.A
00182 //------------------------------------------------------------------
00183 void CRedundant::GetDesireFrameByConfiguration(const Configuration &conf, Frame &frame) const
00184 {
00185         collisionDetector->SetConfiguration(conf);
00186 
00187         Frame *endFrame = frameManager->GetFrameRef(robot->GetToolFrame(0));
00188 
00189         DH_Link *link = (DH_Link*)links[activeJointNum+passiveJointNum-1];
00190 
00191         frame *= frameManager->GetTransformRelative(link->FrameNum(), 0);
00192         //frame *= frameManager->GetTransformRelative(robot->GetToolFrame(0), 0);
00193 
00194         if (endFrame!=NULL)
00195                 frame *= *(endFrame);
00196 }
00197 
00198 //------------------------------------------------------------------
00199 //This function is use to combine active joint variables and
00200 //passive joint variables into a complete configuration.
00201 //
00202 //Input Parameter:
00203 //      activeConf: Active joint variables
00204 //      passiveConf: Passive joint variables
00205 //
00206 //Ouput Parameter:
00207 //      conf: complete configuration
00208 //
00209 //Return Value:
00210 //      N.A
00211 //------------------------------------------------------------------
00212 void CRedundant::CombineConfiguration(Configuration &conf, Configuration &activeConf, Configuration &passiveConf)
00213 {
00214         int i;
00215 
00216         conf.SetLength(activeJointNum+passiveJointNum);
00217 
00218         //Here, we just suppose that the passive chain is at the end of robot chain
00219         for (i=0; i<activeJointNum; i++)
00220         {
00221                 conf.SetJointVar(i, activeConf[i]);
00222         }
00223 
00224         for (i=activeJointNum; i<(activeJointNum+passiveJointNum); i++)
00225         {
00226                 conf.SetJointVar(i, passiveConf[i-activeJointNum]);
00227         }
00228 }
00229 
00230 //------------------------------------------------------------------
00231 //This function is use to update active joint variables to robot
00232 //so that the base frame of the passive joint chain can be 
00233 //computed and updated.
00234 //
00235 //Input Parameter:
00236 //      active: Active joint variables
00237 //
00238 //Ouput Parameter:
00239 //      N.A
00240 //
00241 //Return Value:
00242 //      N.A
00243 //------------------------------------------------------------------
00244 void CRedundant::UpdateActiveConfiguration(Configuration &active)
00245 {
00246         Frame frame;
00247         Frame currentFrame;
00248 
00249         /*
00250           DH_Link *link = (DH_Link*)links[activeJointNum-1];
00251          
00252           for (int i=0; i<active.DOF(); i++)
00253           {
00254             links[i]->SetJointVariable(active[i]);
00255             links[i]->UpdateFrames();
00256           }
00257           
00258           frame *= frameManager->GetTransformRelative(link->FrameNum(), 0);
00259          
00260         */
00261         for (int i=0; i<active.DOF(); i++)
00262         {
00263                 links[i]->SetJointVariable(active[i]);
00264                 links[i]->UpdateFrames();
00265                 ((DH_Link *)links[i])->GetFrame(currentFrame);
00266                 frame *= currentFrame;
00267                 //currentFrame
00268         }
00269 
00270         passive.SetFirstFrame(frame);
00271 }
00272 
00273 //------------------------------------------------------------------
00274 //This function is use to get a totally random configuration
00275 //
00276 //Input Parameter:
00277 //      N.A
00278 //
00279 //Ouput Parameter:
00280 //      conf: A random configuration
00281 //
00282 //Return Value:
00283 //      true, if success; 
00284 //      false, otherwise;
00285 //------------------------------------------------------------------
00286 bool CRedundant::GetRandomConfiguration(Configuration &conf)
00287 {
00288         Configuration activeConf, passiveConf;
00289 
00290         activeConf.SetLength(activeJointNum);
00291         if (!active.GetConfiguration(activeConf))
00292                 return false;
00293 
00294         passiveConf.SetLength(passiveJointNum);
00295         if (!passive.GetRandomConfiguration(passiveConf))
00296                 return false;
00297 
00298         CombineConfiguration(conf, activeConf, passiveConf);
00299         return true;
00300 }
00301 
00302 //------------------------------------------------------------------
00303 //This function is use to get a totally random configuration
00304 //whose end-effector pose is same as given configuration
00305 //
00306 //Input Parameter:
00307 //      desire: Given configuration
00308 //
00309 //Ouput Parameter:
00310 //      conf: Satisfactory configuration
00311 //
00312 //Return Value:
00313 //      true, if success; 
00314 //      false, otherwise;
00315 //------------------------------------------------------------------
00316 bool CRedundant::GetRandomConfiguration(Configuration &conf, Configuration &desire)
00317 {
00318         Frame frame;
00319 
00320         GetDesireFrameByConfiguration(desire, frame);
00321 
00322         return GetRandomConfiguration(conf, frame);
00323 }
00324 
00325 //------------------------------------------------------------------
00326 //This function is used to get a random configuration
00327 //whose end-effector pose is same as given configuration, 
00328 //in a neighbour area of bias.
00329 //
00330 //Input Parameter:
00331 //      bias: Given bias configuration
00332 //      desire: Given configuration for desired pose
00333 //      dist: Deviation allowed for each joint variables
00334 //
00335 //Ouput Parameter:
00336 //      conf: Satisfactory configuration
00337 //
00338 //Return Value:
00339 //      true, if success; 
00340 //      false, otherwise;
00341 //------------------------------------------------------------------
00342 bool CRedundant::GetRandomConfiguration(Configuration &conf, Configuration &bias, Configuration &desire, double dist)
00343 {
00344         Frame frame;
00345 
00346         GetDesireFrameByConfiguration(desire, frame);
00347 
00348         return GetRandomConfiguration(conf, bias, frame, dist);
00349 }
00350 
00351 //------------------------------------------------------------------
00352 //This function is used to get a random configuration
00353 //whose end-effector pose satisfies given frame. 
00354 //
00355 //Input Parameter:
00356 //      frame: Given frame, might include orientation/position
00357 //             but only position is considerred in currently
00358 //
00359 //Ouput Parameter:
00360 //      conf: Satisfactory configuration
00361 //
00362 //Return Value:
00363 //      true, if success; 
00364 //      false, otherwise;
00365 //------------------------------------------------------------------
00366 bool CRedundant::GetRandomConfiguration(Configuration &conf, Frame &frame)
00367 {
00368         Configuration activeConf, passiveConf;
00369 
00370         passive.SetDesireEndEffect(frame);
00371 
00372         activeConf.SetLength(activeJointNum);
00373         if (!active.GetConfiguration(activeConf))
00374                 return false;
00375 
00376         UpdateActiveConfiguration(activeConf);
00377 
00378         passiveConf.SetLength(passiveJointNum);
00379         if (!passive.GetConfiguration(passiveConf))
00380                 return false;
00381 
00382         CombineConfiguration(conf, activeConf, passiveConf);
00383         return true;
00384 }
00385 
00386 //------------------------------------------------------------------
00387 //This function is used to get a random configuration
00388 //whose end-effector pose satisfies given frame. 
00389 //in a neighbour area of bias.
00390 //
00391 //Input Parameter:
00392 //      bias: Given bias configuration
00393 //      frame: Given frame, might include orientation/position
00394 //             but only position is considerred in currently
00395 //      dist: Deviation allowed for each joint variables
00396 //
00397 //Ouput Parameter:
00398 //      conf: Satisfactory configuration
00399 //
00400 //Return Value:
00401 //      true, if success; 
00402 //      false, otherwise;
00403 //------------------------------------------------------------------
00404 bool CRedundant::GetRandomConfiguration(Configuration &conf, Configuration &bias, Frame &frame, double dist)
00405 {
00406         int i;
00407 
00408         Configuration activeConf, passiveConf;
00409         Configuration activeBias, passiveBias;
00410 
00411         passive.SetDesireEndEffect(frame);
00412 
00413         activeConf.SetLength(activeJointNum);
00414         activeBias.SetLength(activeJointNum);
00415         for (i=0; i<activeJointNum; i++)
00416                 activeBias[i] = bias[i];
00417         if (!active.GetConfiguration(activeConf, activeBias, Rad2Deg(dist)))
00418                 return false;
00419 
00420         UpdateActiveConfiguration(activeConf);
00421 
00422         passiveConf.SetLength(passiveJointNum);
00423         passiveBias.SetLength(passiveJointNum);
00424         for (i=0; i<passiveJointNum; i++)
00425                 passiveBias[i] = bias[activeJointNum+i];
00426         if (!passive.GetConfiguration(passiveConf, passiveBias, Rad2Deg(dist)))
00427                 return false;
00428 
00429         CombineConfiguration(conf, activeConf, passiveConf);
00430         return true;
00431 }
00432 
00433 //------------------------------------------------------------------
00434 //This function is used to get a configuration by active joint variables,
00435 //computing the passive joint variables to satisfy given frame. 
00436 //
00437 //Input Parameter:
00438 //      active: Active joint variables
00439 //      frame: Given frame, might include orientation/position
00440 //             but only position is considerred in currently
00441 //
00442 //Ouput Parameter:
00443 //      conf: Satisfactory configuration
00444 //
00445 //Return Value:
00446 //      true, if success; 
00447 //      false, otherwise;
00448 //------------------------------------------------------------------
00449 bool CRedundant::GetConfigurationByActive(Configuration &conf, Configuration &active, Frame &frame)
00450 {
00451         Configuration activeConf, passiveConf;
00452 
00453         activeConf.SetLength(activeJointNum);
00454 
00455         passive.SetDesireEndEffect(frame);
00456 
00457         for (int i=0; i<activeJointNum; i++)
00458         {
00459                 activeConf[i] = active[i];
00460         }
00461         UpdateActiveConfiguration(activeConf);
00462 
00463         passiveConf.SetLength(passiveJointNum);
00464         if (!passive.GetConfiguration(passiveConf))
00465                 return false;
00466 
00467         CombineConfiguration(conf, activeConf, passiveConf);
00468         return true;
00469 }
00470 
00471 //------------------------------------------------------------------
00472 //This function is used to get a closest configuration to the
00473 //bias by active joint variables, computing the passive joint 
00474 //variables to satisfy given frame. 
00475 //
00476 //Input Parameter:
00477 //      active: Active joint variables
00478 //      frame: Given frame, might include orientation/position
00479 //             but only position is considerred in currently
00480 //
00481 //Ouput Parameter:
00482 //      conf: Satisfactory configuration
00483 //
00484 //Return Value:
00485 //      true, if success; 
00486 //      false, otherwise;
00487 //------------------------------------------------------------------
00488 bool CRedundant::GetConfigurationByActive(Configuration &conf, Configuration &active, Configuration &bias, Frame &frame)
00489 {
00490         Configuration activeConf, passiveConf, passiveBias;
00491 
00492         activeConf.SetLength(activeJointNum);
00493 
00494         passive.SetDesireEndEffect(frame);
00495 
00496         for (int i=0; i<activeJointNum; i++)
00497         {
00498                 activeConf[i] = active[i];
00499         }
00500         UpdateActiveConfiguration(activeConf);
00501 
00502         passiveConf.SetLength(passiveJointNum);
00503         passiveBias.SetLength(passiveJointNum);
00504         for (i=0; i<passiveJointNum; i++)
00505                 passiveBias[i] = bias[activeJointNum+i];
00506         if (!passive.GetConfiguration(passiveConf, passiveBias))
00507                 return false;
00508 
00509         CombineConfiguration(conf, activeConf, passiveConf);
00510         return true;
00511 }
00512 
00513 //------------------------------------------------------------------
00514 //This function is used to get a configuration in a neighbour area 
00515 //of bias by active joint variables, computing the passive joint 
00516 //variables to satisfy given frame. 
00517 //
00518 //Input Parameter:
00519 //      active: Active joint variables
00520 //      frame: Given frame, might include orientation/position
00521 //             but only position is considerred in currently
00522 //      dist: Deviation allowed for each joint variables
00523 //
00524 //Ouput Parameter:
00525 //      conf: Satisfactory configuration
00526 //
00527 //Return Value:
00528 //      true, if success; 
00529 //      false, otherwise;
00530 //------------------------------------------------------------------
00531 bool CRedundant::GetConfigurationByActive(Configuration &conf, Configuration &active, Configuration &bias, Frame &frame, double dist)
00532 {
00533         Configuration activeConf, passiveConf, passiveBias;
00534 
00535         activeConf.SetLength(activeJointNum);
00536 
00537         passive.SetDesireEndEffect(frame);
00538 
00539         for (int i=0; i<activeJointNum; i++)
00540         {
00541                 activeConf[i] = active[i];
00542         }
00543         UpdateActiveConfiguration(activeConf);
00544 
00545         passiveConf.SetLength(passiveJointNum);
00546         passiveBias.SetLength(passiveJointNum);
00547         for (i=0; i<passiveJointNum; i++)
00548                 passiveBias[i] = bias[activeJointNum+i];
00549         if (!passive.GetConfiguration(passiveConf, passiveBias, Rad2Deg(dist)))
00550                 return false;
00551 
00552         CombineConfiguration(conf, activeConf, passiveConf);
00553         return true;
00554 }

Generated on Sat Apr 1 21:30:44 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO