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
00011
00012 R_OpenChain::R_OpenChain (const R_OpenChain& right)
00013 : RobotBase( right )
00014 {
00015
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
00030
00031 R_OpenChain::R_OpenChain( FrameManager* frameManager )
00032 : RobotBase( frameManager )
00033 {
00034
00035 }
00036
00037
00038
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
00051
00052
00053
00054 void R_OpenChain::AddToolFrame (const Frame& frame, const int baseFrameNum)
00055 {
00056
00057
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
00068
00069
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
00081
00082
00083
00084 void R_OpenChain::AppendLink (const LinkBase* link)
00085 {
00086 IJG_Assert( link != NULL ) ;
00087 LinkBase* addme = link->Clone() ;
00088 links.push_back( addme ) ;
00089
00090
00091 if( links.size() == 1 )
00092 {
00093 IJG_Assert( addme->BaseFrameNum() == 0 ) ;
00094 }
00095
00096
00097 }
00098
00099 unsigned int R_OpenChain::DOF () const
00100 {
00101
00102 return links.size() ;
00103
00104 }
00105
00106 Entity* R_OpenChain::Clone () const
00107 {
00108
00109 R_OpenChain* returnme = new( R_OpenChain )( *this ) ;
00110
00111 return returnme ;
00112
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
00127
00128
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
00144
00145
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
00158
00159 return false ;
00160
00161 }
00162
00163 bool R_OpenChain::IsInterfering (const Entity* entity) const
00164 {
00165
00166
00167 return false ;
00168
00169 }
00170
00171
00172
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
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
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
00241
00242
00243