basic/robots/R_OpenChain.cpp

Go to the documentation of this file.
00001 #pragma warning( disable : 4786 )
00002 #include "debug/debug.h"
00003 #include "geometry/Frame.h"
00004 #include "Kinematics/DH_Link.h"
00005 #include "Kinematics/LinkBase.h"
00006 #include "robots/R_OpenChain.h"
00007 #include <stdio.h>
00008 
00009 //=============================================================================
00010 // R_OpenChain::R_OpenChain
00011 //=============================================================================
00012 R_OpenChain::R_OpenChain (const R_OpenChain& right)
00013   : RobotBase( right )
00014 {
00015         //improve: is there a more elegant way of doing this?
00016         for( int i = 0; i < right.links.size(); i++ )
00017         {
00018                 links.push_back( right.links[ i ]->Clone() ) ;
00019         }
00020 
00021         for (i = 0; i<right.m_ToolFrames.size(); i++)
00022         {
00023                 m_ToolFrames.push_back(right.m_ToolFrames[i]);
00024                 m_ToolFrameBases.push_back(right.m_ToolFrameBases[i]);
00025         }
00026 }
00027 
00028 //=============================================================================
00029 // R_OpenChain::R_OpenChain
00030 //=============================================================================
00031 R_OpenChain::R_OpenChain( FrameManager* frameManager )
00032   : RobotBase( frameManager )
00033 {
00034     //nothing
00035 }
00036 
00037 //=============================================================================
00038 // R_OpenChain::~R_OpenChain
00039 //=============================================================================
00040 R_OpenChain::~R_OpenChain()
00041 {
00042         for( int i = 0; i < links.size(); i++ )
00043         {
00044                 delete links[ i ] ;
00045                 links[ i ] = NULL ;
00046         }
00047 }
00048 
00049 //=============================================================================
00050 // AddToolFrame
00051 //
00052 // Purpose: adds a tool frame to a particular robot
00053 //=============================================================================
00054 void R_OpenChain::AddToolFrame (const Frame& frame, const int baseFrameNum)
00055 {
00056         //
00057         // Get the frame manager
00058         //
00059         int toolFrameNum = frameManager->AddFrame();
00060         Frame* newFrame = frameManager->GetFrameRef( toolFrameNum );
00061         newFrame->SetValues(frame);
00062         m_ToolFrames.push_back( toolFrameNum );
00063         m_ToolFrameBases.push_back( baseFrameNum );
00064 }
00065 
00066 //=============================================================================
00067 // R_OpenChain::GetToolFrame
00068 //
00069 // Purpose: allows access to a particular tool frame
00070 //=============================================================================
00071 int R_OpenChain::GetToolFrame( int index ) 
00072 {
00073         if (m_ToolFrames.size()==0)
00074                 return -1;
00075         else
00076                 return m_ToolFrames[ index ];
00077 }
00078 
00079 //=============================================================================
00080 // R_OpenChain::AppendLink 
00081 //
00082 // Purpose: adds a particular link to the open chain robot
00083 //=============================================================================
00084 void R_OpenChain::AppendLink (const LinkBase* link)
00085 {
00086         IJG_Assert( link != NULL ) ; //IMPROVE: do something smarter if a null value is passed
00087         LinkBase* addme = link->Clone() ;
00088         links.push_back( addme ) ;
00089         
00090         //if this is the first link, make sure the base frame has been set to null
00091         if( links.size() == 1 )
00092         {
00093                 IJG_Assert( addme->BaseFrameNum() == 0 ) ;      
00094         }
00095 
00096         //IMPROVE: need to mark this link as a dependant link
00097 }
00098 
00099 unsigned int R_OpenChain::DOF () const
00100 {
00101   //## begin R_OpenChain::DOF%924391857.body preserve=yes
00102         return links.size() ;
00103   //## end R_OpenChain::DOF%924391857.body
00104 }
00105 
00106 Entity* R_OpenChain::Clone () const
00107 {
00108   //## begin R_OpenChain::Clone%924739813.body preserve=yes
00109         R_OpenChain* returnme = new( R_OpenChain )( *this ) ;
00110 
00111         return returnme ;
00112   //## end R_OpenChain::Clone%924739813.body
00113 }
00114 
00115 std::list< LinkBase*> R_OpenChain::GetAllLinks () const
00116 {
00117         std::list< LinkBase* > returnMe ;
00118         for( int i = 0; i < links.size(); i++ )
00119         {
00120                 returnMe.insert( returnMe.end(), links[ i ] ) ;
00121         }
00122         return returnMe ;
00123 }
00124 
00125 //=============================================================================
00126 // GetAllToolFrames
00127 //
00128 // Purpose: adds a tool frame to a particular robot
00129 //=============================================================================
00130 std::list< int > R_OpenChain::GetAllToolFrames() const
00131 {
00132         std::list< int > returnMe;
00133         std::vector< int >::const_iterator i;
00134         for( i = m_ToolFrames.begin(); i != m_ToolFrames.end(); i++ )
00135         {
00136                 const int addMe = *i;
00137                 returnMe.insert( returnMe.end(), addMe );
00138         }
00139         return returnMe;
00140 }
00141 
00142 //=============================================================================
00143 // R_OpenChain::GetLink
00144 //
00145 // Purpose: allows access to a particular link of the robot
00146 //=============================================================================
00147 LinkBase* R_OpenChain::GetLink( const unsigned int i )
00148 {
00149         if (i >= links.size())
00150                 return NULL;
00151     LinkBase* returnMe = links[ i ];
00152     return returnMe;
00153 }
00154 
00155 bool R_OpenChain::CanCheckInterference (const Entity* entity) const
00156 {
00157   //## begin R_OpenChain::CanCheckInterference%926300303.body preserve=yes
00158         //check each entity in the robot with this entity
00159         return false ;
00160   //## end R_OpenChain::CanCheckInterference%926300303.body
00161 }
00162 
00163 bool R_OpenChain::IsInterfering (const Entity* entity) const
00164 {
00165   //## begin R_OpenChain::IsInterfering%926300304.body preserve=yes
00166         //assert( false ) ; //IMPROVE: this function is not yet written, it should not be called
00167         return false ;
00168   //## end R_OpenChain::IsInterfering%926300304.body
00169 }
00170 
00171 // Additional Declarations
00172   //## begin R_OpenChain%3718ED82005A.declarations preserve=yes
00173 bool R_OpenChain::Deserialize( IfstreamWithComments& is ) 
00174 {
00175         RobotBase::Deserialize( is ) ;
00176 
00177         char line[ 1000 ] = "";
00178         is.eatwhite() ;
00179         is >> line ;
00180     if( stricmp( line, "#links" ) != 0 )
00181     {
00182         printf( "R_OpenChain::Deserialize - expected #links, got '%s'", line );
00183             IJG_Assert( stricmp( line, "#links" ) == 0 ) ;
00184     }
00185         int numberOfLinks = -1;
00186         is >> numberOfLinks ;
00187 
00188     int i;
00189         for( i = 0; i < numberOfLinks; i++ )
00190         {
00191                 LinkBase* link = LinkBase::DeSerializeAbstract( is, this->frameManager ) ;
00192                 if (link == NULL)
00193                 {
00194                         //If fail to get one of the links
00195                         for( int l = 0; l < links.size(); l++ )
00196                         {
00197                                 delete links[ l ] ;
00198                                 links[ l ] = NULL ;
00199                         }
00200                         return false;
00201                 }
00202 
00203                 this->AppendLink( link ) ;
00204                 int rdof = this->DOF() ;
00205                 delete link ;
00206                 link = NULL ;
00207         }
00208 
00209         //need to read in the DH parameters for the tool frame
00210         is.eatwhite() ;
00211         is >> line ;
00212         IJG_Assert( stricmp( line, "#toolframes" ) == 0 ) ;
00213         int numberOfToolFrames = -1 ;
00214         is >> numberOfToolFrames ;
00215         is.eatwhite() ;
00216         for( i = 0; i < numberOfToolFrames; i++ )
00217         {
00218                 double a ;
00219                 double alpha ;
00220                 double d ;
00221                 double theta ;
00222                 int baseFrameNumber ;
00223                 is >> a ;
00224                 is >> alpha ;
00225                 is >> d ;
00226                 is >> theta ;
00227                 is >> baseFrameNumber ;
00228                 Frame offset ;
00229 
00230                 DH_Link l( this->frameManager ) ;
00231                 l.SetA( a ) ;
00232                 l.SetAlpha( alpha ) ;
00233                 l.SetD( d ) ;
00234                 l.SetTheta( theta ) ;
00235                 Frame toolFrame = l.GetFrame() ;
00236                 this->AddToolFrame( toolFrame, baseFrameNumber ) ;
00237         }
00238         return true;
00239 }
00240   //## end R_OpenChain%3718ED82005A.declarations
00241 
00242 //## begin module%3718ED82005A.epilog preserve=yes
00243 //## end module%3718ED82005A.epilog

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