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 ),
00015 frameManager( frameManager ),
00016 jointMax( 180 ),
00017 jointMin( -180 ),
00018 jointWraps( false )
00019 {
00020
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
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
00054
00055 for( int i = 0 ; i < objects.size(); i++ )
00056 {
00057 delete objects[ i ] ;
00058 objects[ i ] = NULL ;
00059 }
00060
00061 }
00062
00063
00064
00065
00066 void LinkBase::SetBaseFrame (const unsigned int frame)
00067 {
00068
00069 baseFrame = frame ;
00070
00071 }
00072
00073 unsigned int LinkBase::BaseFrameNum () const
00074 {
00075
00076 return( baseFrame ) ;
00077
00078 }
00079
00080 void LinkBase::SetFrameManager (FrameManager* frameManager)
00081 {
00082
00083 this->frameManager = frameManager ;
00084 this->frameManager->AddFrame();
00085
00086 }
00087
00088 double LinkBase::JointMax () const
00089 {
00090
00091 return jointMax ;
00092
00093 }
00094
00095 double LinkBase::JointMin () const
00096 {
00097
00098 return jointMin ;
00099
00100 }
00101
00102 bool LinkBase::JointWraps () const
00103 {
00104
00105 return jointWraps ;
00106
00107 }
00108
00109 void LinkBase::SetJointMax (const double jointMax)
00110 {
00111
00112 this->jointMax = jointMax ;
00113
00114 }
00115
00116 void LinkBase::SetJointMin (const double jointMin)
00117 {
00118
00119 this->jointMin = jointMin ;
00120
00121 }
00122
00123 void LinkBase::SetJointLimits (const double limit1, const double limit2)
00124 {
00125
00126 SetJointMax( Max( limit1, limit2 ) ) ;
00127 SetJointMin( Min( limit1, limit2 ) ) ;
00128
00129 }
00130
00131 void LinkBase::Serialize (ostream& os) const
00132 {
00133
00134 using std::endl ;
00135
00136
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
00145 }
00146
00147 LinkBase* LinkBase::DeSerializeAbstract (IfstreamWithComments& is, FrameManager* frameManager)
00148 {
00149
00150 char marker[ 300 ] = "" ;
00151
00152
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 ) ;
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
00183 }
00184
00185 void LinkBase::SetPositioningFrame (const Matrix4x4& positioningFrame)
00186 {
00187
00188 this->positioningFrame.SetValues( positioningFrame );
00189
00190 }
00191
00192 bool LinkBase::DeSerialize (IfstreamWithComments& is)
00193 {
00194
00195 is.eatwhite() ;
00196 char marker[ 300 ] = "";
00197
00198
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 );
00209
00210 eatwhite( is ) ;
00211 is.getline( marker, 300 ) ;
00212 assert( strcmp( marker, "#end_linkbase" ) == 0 ) ;
00213 return true;
00214
00215 }
00216
00217
00218
00219
00220 std::ostream & operator<<( std::ostream &os, const LinkBase& v )
00221 {
00222
00223 assert( false ) ;
00224 return os ;
00225 };
00226
00227 std::istream & operator>>( std::istream &is, LinkBase& v )
00228 {
00229
00230 assert( false ) ;
00231 return is ;
00232 };
00233
00234
00235
00236
00237