basic/kinematics/LinkBase.cpp

Go to the documentation of this file.
00001 #include <math/math2.h>
00002 #include <string\string2.h>
00003 #include <assert.h>
00004 #include "streams\mystreams.h"
00005 #include "Kinematics\DH_Link.h"
00006 #include "Kinematics\LinkBase.h"
00007 #include "additional\streams\IfstreamWithComments.h"
00008 #include <stdio.h>
00009 
00010 #pragma warning( disable : 4786 )
00011 
00012 LinkBase::LinkBase (FrameManager* frameManager)
00013   : 
00014         baseFrame( 0 ), //IMPROVE: is this initialization needed?
00015         frameManager( frameManager ),
00016         jointMax( 180 ),
00017         jointMin( -180 ),
00018         jointWraps( false ) 
00019 {
00020     //nothing
00021 }
00022 
00023 LinkBase::LinkBase (const LinkBase& right)
00024   : 
00025         NamedElement( right ),
00026         baseFrame( right.baseFrame ),
00027         frameManager( right.frameManager ),
00028         jointMax( right.jointMax ),
00029         jointMin( right.jointMin ),
00030         jointWraps( right.jointWraps ),
00031         positioningFrame( right.positioningFrame )
00032 {
00033         controlledFrames.clear() ;
00034     int i;
00035         for( i = 0; i < right.controlledFrames.size(); i++ )
00036         {
00037                 controlledFrames.push_back( right.controlledFrames[ i ] ) ;
00038         }
00039 
00040         //copy all the objects
00041         for( i = 0; i < right.objects.size(); i++ )
00042         {
00043                 ObjectBase* cloneMe = right.objects[ i ];
00044                 ObjectBase* cloned = dynamic_cast<ObjectBase*>( cloneMe->Clone() );
00045                 objects.push_back( cloned ) ;
00046         }
00047         
00048 }
00049 
00050 
00051 LinkBase::~LinkBase()
00052 {
00053   //## begin LinkBase::~LinkBase%.body preserve=yes
00054 
00055         for( int i = 0 ; i < objects.size(); i++ )
00056         {
00057                 delete objects[ i ] ;
00058                 objects[ i ] = NULL ;
00059         }
00060   //## end LinkBase::~LinkBase%.body
00061 }
00062 
00063 
00064 
00065 //## Other Operations (implementation)
00066 void LinkBase::SetBaseFrame (const unsigned int frame)
00067 {
00068   //## begin LinkBase::SetBaseFrame%924379573.body preserve=yes
00069         baseFrame = frame ;
00070   //## end LinkBase::SetBaseFrame%924379573.body
00071 }
00072 
00073 unsigned int LinkBase::BaseFrameNum () const
00074 {
00075   //## begin LinkBase::BaseFrameNum%924379575.body preserve=yes
00076         return( baseFrame ) ;
00077   //## end LinkBase::BaseFrameNum%924379575.body
00078 }
00079 
00080 void LinkBase::SetFrameManager (FrameManager* frameManager)
00081 {
00082   //## begin LinkBase::SetFrameManager%924978290.body preserve=yes
00083         this->frameManager = frameManager ;
00084         this->frameManager->AddFrame();
00085   //## end LinkBase::SetFrameManager%924978290.body
00086 }
00087 
00088 double LinkBase::JointMax () const
00089 {
00090   //## begin LinkBase::JointMax%928194468.body preserve=yes
00091         return jointMax ;
00092   //## end LinkBase::JointMax%928194468.body
00093 }
00094 
00095 double LinkBase::JointMin () const
00096 {
00097   //## begin LinkBase::JointMin%928194469.body preserve=yes
00098         return jointMin ;
00099   //## end LinkBase::JointMin%928194469.body
00100 }
00101 
00102 bool LinkBase::JointWraps () const
00103 {
00104   //## begin LinkBase::JointWraps%928194470.body preserve=yes
00105         return jointWraps ;
00106   //## end LinkBase::JointWraps%928194470.body
00107 }
00108 
00109 void LinkBase::SetJointMax (const double jointMax)
00110 {
00111   //## begin LinkBase::SetJointMax%928263336.body preserve=yes
00112         this->jointMax = jointMax ;
00113   //## end LinkBase::SetJointMax%928263336.body
00114 }
00115 
00116 void LinkBase::SetJointMin (const double jointMin)
00117 {
00118   //## begin LinkBase::SetJointMin%928263337.body preserve=yes
00119         this->jointMin = jointMin ;
00120   //## end LinkBase::SetJointMin%928263337.body
00121 }
00122 
00123 void LinkBase::SetJointLimits (const double limit1, const double limit2)
00124 {
00125   //## begin LinkBase::SetJointLimits%928263338.body preserve=yes
00126         SetJointMax( Max( limit1, limit2 ) ) ;
00127         SetJointMin( Min( limit1, limit2 ) ) ;
00128   //## end LinkBase::SetJointLimits%928263338.body
00129 }
00130 
00131 void LinkBase::Serialize (ostream& os) const
00132 {
00133   //## begin LinkBase::Serialize%933801285.body preserve=yes
00134         using std::endl ;
00135 
00136         //IMPROVE: does this output enough data
00137         os << "#linkbase" << endl ;
00138         os << baseFrame << '\t' ;
00139         os << jointMin << '\t' ;
00140         os << jointMax << '\t' ;
00141         os << jointWraps << '\t' ;
00142         os << endl ;
00143         os << "#end_linkbase" << endl ;
00144   //## end LinkBase::Serialize%933801285.body
00145 }
00146 
00147 LinkBase* LinkBase::DeSerializeAbstract (IfstreamWithComments& is, FrameManager* frameManager)
00148 {
00149   //## begin LinkBase::DeSerializeAbstract%935084509.body preserve=yes
00150         char marker[ 300 ] = "" ;
00151 
00152         //verify the first few lines - header lines
00153         is.eatwhite() ;
00154         is.getline( marker, 300 ) ;
00155     if( strcmp( marker, "#link" ) != 0 )
00156     {
00157         printf( "LinkBase::DeSerializeAbstract - expected #link got '%s'\n", marker );
00158             assert( strcmp( marker, "#link" ) == 0 ) ;
00159     }
00160 
00161         is.eatwhite() ;
00162         is.getline( marker, 300 ) ;
00163         
00164         LinkBase* link = NULL ;
00165         if( stricmp( marker, "#DH_LINK" ) == 0 )
00166         {
00167                 link = new DH_Link( frameManager ) ;            //IMPROVE: null is a bad idea here
00168         }
00169         if (link == NULL)
00170                 return NULL;
00171 
00172         if (link->DeSerialize( is ) == false)
00173         {
00174                 delete link;
00175                 return NULL;
00176         }
00177 
00178         is.GetSolidLine( marker, 300 ) ;
00179         assert( stricmp( marker, "#end_link" ) == 0 ) ;
00180 
00181         return link ;
00182   //## end LinkBase::DeSerializeAbstract%935084509.body
00183 }
00184 
00185 void LinkBase::SetPositioningFrame (const Matrix4x4& positioningFrame)
00186 {
00187   //## begin LinkBase::SetPositioningFrame%969569781.body preserve=yes
00188         this->positioningFrame.SetValues( positioningFrame );
00189   //## end LinkBase::SetPositioningFrame%969569781.body
00190 }
00191 
00192 bool LinkBase::DeSerialize (IfstreamWithComments& is)
00193 {
00194   //## begin LinkBase::DeSerialize%935084510.body preserve=yes
00195         is.eatwhite() ;
00196         char marker[ 300 ] = "";
00197 
00198         //read in the linkbase marker
00199         is.getline( marker, 300 ) ;
00200 
00201         is.eatwhite() ;
00202         is >> baseFrame ;
00203         is >> jointMin ;
00204         is >> jointMax ;
00205 
00206         int jointWrapsInt ;
00207         is >> jointWrapsInt ;
00208         jointWraps = ( jointWrapsInt != 0 );    //convert to bool
00209 
00210         eatwhite( is ) ;
00211         is.getline( marker, 300 ) ;
00212         assert( strcmp( marker, "#end_linkbase" ) == 0 ) ;
00213         return true;
00214   //## end LinkBase::DeSerialize%935084510.body
00215 }
00216 
00217 // Additional Declarations
00218   //## begin LinkBase%3707C4E603CA.declarations preserve=yes
00219 //-----------------------------------------------------------------------------
00220 std::ostream & operator<<( std::ostream &os, const LinkBase& v )
00221 {
00222         //IMPROVE: this is an abstract class - can this ever be called?
00223         assert( false ) ;
00224         return os ;
00225 };
00226 //-----------------------------------------------------------------------------
00227 std::istream & operator>>( std::istream &is, LinkBase& v )
00228 {
00229         //IMPROVE: this is an abstract class - can this ever be called?
00230         assert( false ) ;
00231         return is ;
00232 };
00233 //-----------------------------------------------------------------------------
00234 
00235   //## end LinkBase%3707C4E603CA.declarations
00236 //## begin module%3707C4E603CA.epilog preserve=yes
00237 //## end module%3707C4E603CA.epilog

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