Odometry.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00017 #include "Odometry.h"
00018 
00019 // Module specification
00020 // <rtc-template block="module_spec">
00021 static const char* odometry_spec[] =
00022   {
00023     "implementation_id", "Odometry",
00024     "type_name",         "Odometry",
00025     "description",       "detect position by Odometry",
00026     "version",           "4.0.0",
00027     "vendor",            "AIST INVENT",
00028     "category",          "Localization",
00029     "activity_type",     "PERIODIC",
00030     "kind",              "DataFlowComponent",
00031     "max_instance",      "10",
00032     "language",          "C++",
00033     "lang_type",         "compile",
00034     "exec_cxt.periodic.rate", "1000.0",
00035     // Configuration variables
00036     "conf.default.leftWheelID", "0",
00037     "conf.default.rightWheelID", "1",
00038     "conf.default.radiusOfLeftWheel", "0.1",
00039     "conf.default.radiusOfRightWheel", "0.1",
00040     "conf.default.lengthOfAxle", "0.441",
00041     "conf.default.radiusOfBodyArea", "0.45",
00042     ""
00043   };
00044 // </rtc-template>
00045 
00050 Odometry::Odometry(RTC::Manager* manager)
00051     // <rtc-template block="initializer">
00052   : RTC::DataFlowComponentBase(manager),
00053     m_CurrentWheelAngleIn("CurrentWheelAngle", m_CurrentWheelAngle),
00054     m_LocalizedPositionIn("LocalizedPosition", m_LocalizedPosition),
00055     m_OdometryPositionOut("OdometryPosition", m_OdometryPosition)
00056 
00057     // </rtc-template>
00058 {
00059 }
00060 
00064 Odometry::~Odometry()
00065 {
00066 }
00067 
00068 
00072 RTC::ReturnCode_t Odometry::onInitialize()
00073 {
00074   // Registration: InPort/OutPort/Service
00075   // <rtc-template block="registration">
00076   // Set InPort buffers
00077   registerInPort("CurrentWheelAngle", m_CurrentWheelAngleIn);
00078   registerInPort("LocalizedPosition", m_LocalizedPositionIn);
00079   
00080   // Set OutPort buffer
00081   registerOutPort("OdometryPosition", m_OdometryPositionOut);
00082   
00083   // Set service provider to Ports
00084   
00085   // Set service consumers to Ports
00086   
00087   // Set CORBA Service Ports
00088   
00089   // </rtc-template>
00090 
00091   // <rtc-template block="bind_config">
00092   // Bind variables and configuration variable
00093   bindParameter("leftWheelID", m_leftWheelID, "0");
00094   bindParameter("rightWheelID", m_rightWheelID, "1");
00095   bindParameter("radiusOfLeftWheel", m_radiusOfLeftWheel, "0.1");
00096   bindParameter("radiusOfRightWheel", m_radiusOfRightWheel, "0.1");
00097   bindParameter("lengthOfAxle", m_lengthOfAxle, "0.441");
00098   bindParameter("radiusOfBodyArea", m_radiusOfBodyArea, "0.45");
00099   
00100   // </rtc-template>
00101 
00102 //--- [add] -------------------------------------
00103 std::cout << "OnInitialize()" << std::endl;
00104 
00105   //-- set STATIC PARAMETER            
00106         //Pi = 3.1415927;        
00107         RotationAngleBorder = 3.1415927/180.0; 
00108         RhoBorder = 10000.0;   
00109 
00110 
00111 #if CALLBACK
00112         //-- callback object
00113 //      m_CurrentWheelAngleIn.setOnWriteConvert(&m_debug);
00114 //      m_LocalizedPositionIn.setOnWriteConvert(&m_debug);
00115 #endif  
00116 //--- [add] -------------------------------------
00117 
00118   return RTC::RTC_OK;
00119 }
00120 
00121 /*
00122 RTC::ReturnCode_t Odometry::onFinalize()
00123 {
00124   return RTC::RTC_OK;
00125 }
00126 */
00127 
00128 /*
00129 RTC::ReturnCode_t Odometry::onStartup(RTC::UniqueId ec_id)
00130 {
00131   return RTC::RTC_OK;
00132 }
00133 */
00134 
00135 /*
00136 RTC::ReturnCode_t Odometry::onShutdown(RTC::UniqueId ec_id)
00137 {
00138   return RTC::RTC_OK;
00139 }
00140 */
00141 
00148 RTC::ReturnCode_t Odometry::onActivated(RTC::UniqueId ec_id)
00149 {
00150 //--- [add] -------------------------------------
00151   std::cout << "on Activated" << std::endl;
00152 
00153 //--initialize  TODO:[CHANGE] get CURRENT STATUS DATA, not 0.0!!
00154         // Body struct
00155         Body.wheelRadiusLeft = Body.wheelRadiusRight = Body.bodyRadius = Body.length = 0.0;
00156         Body.leftID = Body.rightID = -1;
00157 
00158         //--Current struct
00159         Current.BodyVel = Current.RightVel = Current.LeftVel = Current.BodyAccel = Current.Rho = Current.BodyOmega = 0.0;
00160         Current.x = 0.0;
00161         Current.y = 0.0;
00162         Current.xOld = 0.0;          
00163         Current.yOld = 0.0;
00164         Current.theta = 0.0;
00165         Current.thetaOld = 0.0; 
00166         Current.BodyVelOld = Current.BodyOmegaOld = Current.RhoOld = 0.0;
00167         Current.Time = Current.TimeOld = 0.0;
00168         //-- initialize time value for DataPort' Timed
00169         Current.sec = Current.nsec = Current.secOld = Current.nsecOld = 0;
00170 
00171         //-- initialize Flag
00172         InitialPositionFlag = InitialAngleFlag = false;
00173 
00174 #if DEBUG
00175         //--[debug] open file 
00176         ofs.open("odometry.dat");
00177 #endif
00178 
00179 //--get Model Parameter from Configulation
00180         Body.leftID = m_leftWheelID; // jointID of left wheel
00181         Body.rightID = m_rightWheelID; // jointID of right wheel
00182         Body.wheelRadiusLeft = m_radiusOfLeftWheel; // Wheel Radius(Left)
00183         Body.wheelRadiusRight = m_radiusOfRightWheel; // Wheel Radius(Right)
00184         Body.bodyRadius = 0.5 * m_lengthOfAxle; // Body Radius (half of length of Wheel Axle)
00185         Body.length = m_radiusOfBodyArea; // length from center of Body to corner of Body
00186 
00187 #if DEBUG       
00188         std::cout << "Body.leftID: " << Body.leftID << "   Body.rightID: " << Body.rightID << std::endl;        
00189         std::cout << "Body.wheelRadius[L]: " << Body.wheelRadiusLeft << "Body.wheelRadius[R]: " << Body.wheelRadiusRight << "   Body.bodyRadius: " << Body.bodyRadius << std::endl;     
00190 #endif
00191 
00192 //-- Update INPORT 
00193         m_CurrentWheelAngleIn.update();
00194         m_LocalizedPositionIn.update();  
00195 
00196 //-- set previous  data
00197         for(int i=0; i < Dof; i++){
00198         //Current.AngOld[i] = m_CurrentWheelAngle.data[i];  //TODO: [CHANGE] dummy start position  ->  get current status data someday!
00199                 Current.Ang[i] = Current.AngVel[i] = 0.0;
00200                 Current.AngOld[i] = Current.AngVelOld[i] = 0.0;
00201         }
00202 #if DEBUG2      
00203         counter = 0;
00204         ofs2.open("runtime.dat");
00205         ofs3.open("runtime2.dat");
00206         // timeval Initialize
00207         timerclear(&TotalTime);
00208         // Reset of time
00209         if(gettimeofday(&TotalTime, NULL)){
00210                 std::cout << "failed to gettimeofday" << std::endl;
00211         }
00212 #endif
00213 
00214 //--- [add] -------------------------------------
00215 
00216   return RTC::RTC_OK;
00217 }
00218 
00223 RTC::ReturnCode_t Odometry::onDeactivated(RTC::UniqueId ec_id)
00224 {
00225 //--- [add] -------------------------------------
00226         std::cout << "on Deactivated" << std::endl;
00227         //TODO:add ACTION
00228 
00229         // close file
00230 #if DEBUG       
00231         ofs.close();
00232 #endif
00233 #if DEBUG2      
00234         ofs2.close();
00235         ofs3.close();
00236 #endif
00237 
00238 //--- [add] -------------------------------------
00239 
00240   return RTC::RTC_OK;
00241 }
00242 
00250 RTC::ReturnCode_t Odometry::onExecute(RTC::UniqueId ec_id)
00251 {
00252 //--- [add] -------------------------------------
00253 //  std::cout << " ==================================== [onExecute] ====================================" << std::endl;
00254 //--- TIME DEBUG ---------------------------------------------------------------------------
00255 #if DEBUG2      
00256 //      std::cout << "" << std::endl;
00257         if(gettimeofday(&SetTime, NULL)){
00258                 std::cout << "failed to gettimeofday" << std::endl;
00259         }
00260         timerclear(&GetTime);
00261         timersub(&SetTime, &TotalTime, &GetTime);       
00262 
00263         unsigned long  sec_debug_start = GetTime.tv_sec;
00264         unsigned long nsec_debug_start = GetTime.tv_usec*1000;
00265         double starttime = sec_debug_start + 1.0e-9*nsec_debug_start;
00266 
00267 //      std::cout << "----[onExecute][START]   StartTime [sec] = " << starttime << std::endl;
00268 #endif
00269 //-----------------------------------------------------------------------------------------
00270 
00271         //-- action if the values of INPORT are updated 
00272 
00273         //-- get [LOCALIZED POSITION] data from INPORT  
00274 /*      if (m_LocalizedPositionIn.isNew()) {
00275                 getLocalizedPosition();
00276         } else {
00277 #if DEBUG
00278                 std::cout << "      ---[SKIP] can't get localized position data from [LocaliationRTC]---" << std::endl; 
00279 #endif
00280         }*/
00281 
00282         //H.T 20100822 リングバッファの最新の情報を読み取るために上のものを下のように改変
00283         while (!m_LocalizedPositionIn.isEmpty())
00284                 getLocalizedPosition();
00285 
00286         //-- after getting initialized data
00287 //      if (InitialPositionFlag) {
00288         if (true) {
00289                 //-- get [WHEEL ANGLE] data from INPORT and calc [ODOMETRY]
00290                 if (m_CurrentWheelAngleIn.isNew()) {
00291                         //-- get Previous wheel angle data from INPORT          
00292                         if (getWheelAngleData()) {
00293                                 //-- calc current position and posture angle by odometry
00294                                 calcOdometry(); 
00295                                 //-- set current data to previous
00296                                 setCurrentToOld();
00297                                 //-- output
00298                                 usleep(10000);
00299                                 outputData();
00300                         } 
00301                 } 
00302 else {
00303 #if DEBUG
00304                         std::cout << "      --------[SKIP] can't get wheel angle data from [MotorControlRTC]---" << std::endl;  
00305 #endif
00306                 }
00307         }
00308 
00309 #if DEBUG2      
00310         if(gettimeofday(&SetTime, NULL)){
00311                 std::cout << "failed to gettimeofday" << std::endl;
00312         }
00313         timerclear(&GetTime);
00314         timersub(&SetTime, &TotalTime, &GetTime);       
00315 
00316         unsigned long  sec_debug_end = GetTime.tv_sec;
00317         unsigned long nsec_debug_end = GetTime.tv_usec*1000;
00318         double endtime = sec_debug_end + 1.0e-9*nsec_debug_end;
00319 
00320         double deltaTime = 1.0e3*( endtime - starttime);
00321 
00322         std::cout << "----[RuntTime(" << counter << ")]   StartTime [sec] = " << starttime << "   EndTime [sec] = " << endtime << " [ " << deltaTime << " msec]" << std::endl;
00323 /*      if (deltaTime > 1.0){
00324                 std::cout << "----[1msecOver]---" << std::endl;
00325                 ofs3 << counter << "  " << deltaTime  << std::endl;
00326         }*/
00327 //      std::cout << "----------[END]   EndTime [sec] " << endtime << " [ " << 1.0e3*( endtime - starttime) << " msec]" << std::endl;
00328         std::cout << std::endl;
00329         ofs2 << counter++ << " , CurTime= " << Current.Time << " , dTime[ms]= " << deltaTime << std::endl;
00330 #endif
00331 
00332 //--- [add] -------------------------------------
00333 
00334   return RTC::RTC_OK;
00335 }
00336 
00337 
00338 
00339 /*********************************************************************************************************/
00340 //-- get LocalizedPosition data 
00341 /*********************************************************************************************************/
00342 inline void Odometry::getLocalizedPosition()
00343 {
00344 
00345         //-- get LocalizedPosition Data
00346         m_LocalizedPositionIn.read();
00347 
00348         //-- the actions when get first initial position data 
00349         if (!InitialPositionFlag) {
00350                 //-- initialized position data
00351                 /*
00352                 Current.xOld = m_LocalizedPosition.x;
00353                 Current.yOld = m_LocalizedPosition.y;
00354                 Current.thetaOld = m_LocalizedPosition.theta;
00355                 */
00356                 Current.xOld = m_LocalizedPosition.data.position.x;
00357                 Current.yOld = m_LocalizedPosition.data.position.y;
00358                 Current.thetaOld = m_LocalizedPosition.data.heading;
00359                 Current.secOld = 0;  //TODO: other value?
00360                 Current.nsecOld = 0;
00361                 Current.TimeOld = Current.secOld + 1.0e-9*Current.nsecOld;
00362                 InitialPositionFlag = true;
00363                 std::cout << " [INITIALIZED] X = " << Current.xOld << " , Y = " << Current.yOld << " , THETA =" << Current.thetaOld << std::endl;       
00364         } else if ( 1/*(Current.secOld == m_LocalizedPosition.tm.sec) && (Current.nsecOld == m_LocalizedPosition.tm.nsec) */) {  // if correspond to previous TimeStamp
00365                 //-- set localized data
00366                 /*
00367                 Current.xOld = m_LocalizedPosition.x;
00368                 Current.yOld = m_LocalizedPosition.y;
00369                 Current.thetaOld = m_LocalizedPosition.theta;
00370                 */              
00371                 Current.xOld = m_LocalizedPosition.data.position.x;
00372                 Current.yOld = m_LocalizedPosition.data.position.y;
00373                 Current.thetaOld = m_LocalizedPosition.data.heading;
00374         } else {
00375 #if DEBUG       
00376                 std::cout << "   -----[NoCorresponding  (LocalizedTime)--(previousTime)] LocalizedSEC = " << m_LocalizedPosition.tm.sec << " ,  LocalizedNSEC = " << m_LocalizedPosition.tm.nsec << " , SecOld =" << Current.secOld << " , NSecOld =" << Current.nsecOld << std::endl;  
00377 #endif
00378         }
00379 
00380         return ;
00381 }
00382 
00383 
00384 /*********************************************************************************************************/
00385 //-- get Previous data 
00386 /*********************************************************************************************************/
00387 inline bool Odometry::getWheelAngleData()
00388 {
00389 
00390         //-- get Previous Wheel Angle Data[rad]
00391         m_CurrentWheelAngleIn.read();
00392 
00393         //-- set Previous Wheel Angle Data
00394         Current.Ang[Body.leftID] = m_CurrentWheelAngle.data[Body.leftID];
00395         Current.Ang[Body.rightID] = m_CurrentWheelAngle.data[Body.rightID];
00396 
00397         //-- get Simulated Time
00398         Current.sec = m_CurrentWheelAngle.tm.sec;
00399         Current.nsec = m_CurrentWheelAngle.tm.nsec;
00400 
00401         //-- set Current Time (Simulated)
00402         Current.Time = Current.sec + 1.0e-9*Current.nsec;
00403 
00404         //-- the actions when get first initial angle data 
00405         if (!InitialAngleFlag) {
00406                 Current.AngOld[Body.leftID] = Current.Ang[Body.leftID];
00407                 Current.AngOld[Body.rightID] = Current.Ang[Body.rightID];
00408                 timeStep = 1.0e5;   // approximate
00409                 InitialAngleFlag = true;
00410                 std::cout << " [INITIALIZED] Angle[L] = " << Current.AngOld[Body.leftID] << " , Angle[R] = " << Current.AngOld[Body.rightID]  << std::endl;
00411         } else {
00412                 //calc timestep value
00413                 timeStep = Current.Time - Current.TimeOld; 
00414         }
00415 
00416 #if DEBUG       
00417         std::cout << std::endl;
00418         std::cout << "--[TIME(sec)]: " << Current.Time << "--------------------------------------" << std::endl;        
00419         std::cout << "   TimeStep[sec] =  " << timeStep  << std::endl;
00420         std::cout << "   [Current] currWheelAng[L] = " << m_CurrentWheelAngle.data[Body.leftID] << " / currWheelAng[R] = " << m_CurrentWheelAngle.data[Body.rightID] << " TIME1= " << m_CurrentWheelAngle.tm.sec << " TIME2=" << m_CurrentWheelAngle.tm.nsec << std::endl;
00421 #endif
00422 
00423         if (timeStep <= 0.0) {
00424                 std::cout << "== [ERROR(timeStep)] [Old or Same] timestamp's data were send, so couldn't calculate Odometry position values. " << std::endl;
00425                 return false;
00426         }
00427 
00428         //-- calc Wheel Angular Velocity's Datas by previous angle data
00429         Current.AngVel[Body.leftID] = (Current.Ang[Body.leftID] - Current.AngOld[Body.leftID]) / timeStep;
00430         Current.AngVel[Body.rightID] = (Current.Ang[Body.rightID] - Current.AngOld[Body.rightID]) / timeStep;
00431 
00432 
00433         return true;
00434 }
00435 
00436 
00437 /************************************************************************************************************/
00438 //-- calc Current Position by Odometry 
00439 /************************************************************************************************************/
00440 inline void Odometry::calcOdometry() {
00441 
00442         double dl,dfai,faiDummy;
00443 
00444         Current.LeftVel = Body.wheelRadiusLeft * Current.AngVel[Body.leftID];           // Trans Velocity of Left Wheel
00445         Current.RightVel = Body.wheelRadiusRight * Current.AngVel[Body.rightID];  // Trans Velocity of Right Wheel
00446 
00447 #if DEBUG       
00448         std::cout << "----calc CurrentPosition by Odometry-----------" << std::endl;
00449         std::cout  << "    [odometry] AngularVel[L] = " << Current.AngVel[Body.leftID] << " / AngularVel[R] = " << Current.AngVel[Body.rightID] << std::endl;
00450         std::cout  << "    [odometry] BodyleftVel = " << Current.LeftVel << " / BodyRightVel = " << Current.RightVel << std::endl;
00451 #endif
00452 
00453         //-- calc velocity/Acceleration of BODY & RotationAngle & RotationVel by velocity of both wheel    
00454         Current.BodyVel = 0.5 * (Current.RightVel + Current.LeftVel) * 9.0/5.5;              // 係数調整(2011.4.24)vBody = (vRight+vLeft)/2
00455         Current.BodyAccel = (Current.BodyVel - Current.BodyVelOld) / timeStep;
00456         Current.BodyOmega = 0.5 * (Current.RightVel - Current.LeftVel) * 9.0/5.5 / Body.bodyRadius;  // 係数調整(2011.4.24)RotAngVel: OMEGA = (vRight-vLeft)/2*Body.bodyRadius (turn anti-clockwise -> +)
00457 
00458         //dfai = 0.5 * (Current.BodyOmega + Current.BodyOmegaOld) * timeStep;        //deltaRotationAng:  AVERAGE:(current+previous)/2
00459         //dfai = Current.BodyOmega * timeStep;
00460         dfai = Current.BodyOmega * timeStep * 6.28/(6.28 - 0.2);  //TODO:[CONSIDER] //係数調整
00461 
00462         //--calc current posture angle  TODO:[CHANGE] must PreSet first position
00463         Current.theta = Current.thetaOld + dfai;
00464 
00465         //-- [offset] -180 < Current.theta < 180  (while roop : If TimeStep is so long -> dfai > 360)
00466         while (Current.theta <= -1.0*M_PI || Current.theta >= 1.0*M_PI) {
00467                 if( Current.theta <= -1.0*M_PI)                 Current.theta += 2.0*M_PI;
00468                 else if ( Current.theta >= 1.0*M_PI)            Current.theta -= 2.0*M_PI;
00469         }
00470 
00471 #if DEBUG                       
00472         std::cout << "    [odometry] BodyVel = " << Current.BodyVel << " / PreBodyVel = " << Current.BodyVelOld << " / BodyAccel = " << Current.BodyAccel << " / dfai[deg] = " << dfai*180/M_PI << " / CurrPostureAng[deg] = " << Current.theta*180/M_PI << " / Current.BodyOmega[deg/s] = " <<Current.BodyOmega*180/M_PI  << " / Current.BodyOmegaOLD[deg/s] = " <<Current.BodyOmegaOld*180/M_PI << std::endl; 
00473 #endif
00474 
00475         //--if difference from LeftWheelAngular Velocity to Right ->  calc [CurvatureRadius]
00476         if(dfai != 0.0) {                 
00477                 Current.Rho = Body.bodyRadius * (Current.RightVel + Current.LeftVel) / (Current.RightVel - Current.LeftVel);  //   rho = Body.bodyRadius*(vRight+vLeft)/(vRight-vLeft) (turn anti-clockwise -> [+] ) 
00478                 //double rho_ave = 0.5 * (Current.Rho + Current.RhoOld);
00479 
00480 #if DEBUG                       
00481                 //std::cout << "    [odometry] rho_ave = " << rho_ave << " Current.RhoOld = " << Current.RhoOld <<  " Current.rho = " << Current.Rho << std::endl;      
00482                 std::cout << "    [odometry]  Current.RhoOld = " << Current.RhoOld <<  " Current.rho = " << Current.Rho << std::endl;   
00483 #endif
00484 
00485                 //-- modify rho
00486                 if (fabs(Current.Rho) > RhoBorder  &&  Current.Rho >= 0.0 ) {
00487                         Current.Rho = RhoBorder;  //TODO:[CONSIDER]  if  rho > border  ->  almost STRAIGHT Line 
00488                         dl = 0.5 * (Current.BodyVel + Current.BodyVelOld) * timeStep;   //TODO:[CONSIDER]  x = t * ( V(i+1) + V(i) )/2 
00489                 } else if (fabs(Current.Rho) > RhoBorder  &&  Current.Rho < 0.0 ) {
00490                         Current.Rho = -1.0*RhoBorder;
00491                         dl = 0.5 * (Current.BodyVel + Current.BodyVelOld) * timeStep;   //TODO:[CONSIDER]  x = t * ( V(i+1) + V(i) )/2 
00492                 } else if(fabs(dfai) < RotationAngleBorder) {        // TODO:[CONSIDER] RotationAngleBorder -> HOW?
00493                         dl = Current.Rho * dfai;                    // deltaL = {rho}*{deltaFAI}   (if deltaFAI << 1)
00494                         //dl = rho_ave * dfai;
00495                 } else {
00496                         dl = 2.0 * Current.Rho * sin(0.5 * dfai);    // deltaL = {rho}*{deltaFAI}   (if deltaFAI >> 1)  
00497                         //dl = 2.0 * rho_ave * sin(0.5 * dfai); 
00498                 }
00499 
00500         } else {
00501                 Current.Rho = 0.0;  // TODO:[CONSIDER] if STRAIGHT orbit
00502                 dl = 0.5 * (Current.BodyVel + Current.BodyVelOld) * timeStep;   //TODO:[CONSIDER]  x = t * ( V(i+1) + V(i) )/2 
00503         }
00504 
00505         //-- X{i+1} = X{i} + {deltaL} * cos(theta{i}+{delta_theta}/2) 
00506         //faiDummy = Current.thetaOld + 0.5*dfai + 0.5*M_PI;  // TODO:[CONSIDER]  because [dfai] is angle from [Yaxis to Y'axis] ->  add 90[deg]  
00507         faiDummy = Current.thetaOld + 0.5*dfai;//dtの半分の時点での角度を採用?
00508 
00509         //--calc CURRENT POSITION ([forward]: (1)rho>0,dfai>0 --> dl>0 (2) rho<0,dfai<0 --> dl>0  /  [backward]: (1)rho>0,dfai<0 --> dl<0 (2) rho<0,dfai>0 --> dl<0 )
00510         Current.x = Current.xOld + dl * cos(faiDummy);
00511         Current.y = Current.yOld + dl * sin(faiDummy);
00512 
00513 //#if DEBUG                     
00514         std::cout << "[odometry] Current.x = " << Current.x << " Current.y = " << Current.y <<  " Current.theta = " << Current.theta << " deltaL = " << dl << std::endl;        
00515 //#endif
00516 
00517         return ;
00518 }
00519 
00520 
00521 /***************************************************************************************************/
00522 //-- set current data to previous
00523 /***************************************************************************************************/
00524 inline void Odometry::setCurrentToOld()
00525 {
00526 
00527         //-- set CURRENT data -> PREVIOUS data 
00528         Current.xOld = Current.x;
00529         Current.yOld = Current.y;
00530         Current.thetaOld = Current.theta;
00531 
00532         Current.BodyVelOld = Current.BodyVel;
00533         Current.BodyOmegaOld = Current.BodyOmega; 
00534         Current.RhoOld = Current.Rho;
00535 
00536         Current.AngOld[Body.leftID] = Current.Ang[Body.leftID];
00537         Current.AngVelOld[Body.leftID] = Current.AngVel[Body.leftID];
00538         Current.AngOld[Body.rightID] = Current.Ang[Body.rightID];
00539         Current.AngVelOld[Body.rightID] = Current.AngVel[Body.rightID];                 
00540 
00541         Current.secOld = Current.sec;
00542         Current.nsecOld = Current.nsec;
00543         Current.TimeOld = Current.Time;
00544                                 
00545         return;
00546 }
00547 
00548 
00549 /********************************************************************************************************/
00550 //-- set DATA and write to OUTPORT
00551 /*********************************************************************************************************/
00552 inline void Odometry::outputData()
00553 {
00554 
00555         //-- set current position data for OUTPORT to LocalizationRTC
00556         /*
00557         m_OdometryPosition.x = Current.x;
00558         m_OdometryPosition.y = Current.y;
00559         m_OdometryPosition.theta = Current.theta;
00560         m_OdometryPosition.tm.sec = Current.sec;
00561         m_OdometryPosition.tm.nsec = Current.nsec;
00562         */
00563         m_OdometryPosition.data.position.x = Current.x;
00564         m_OdometryPosition.data.position.y = Current.y;
00565         m_OdometryPosition.data.heading = Current.theta;
00566         m_OdometryPosition.tm.sec = Current.sec;
00567         m_OdometryPosition.tm.nsec = Current.nsec;
00568 
00569 #if DEBUG       
00570         std::cout << "     [output]  currWheelAng[L]: " << Current.Ang[Body.leftID] << ",  currWheelAng[R]:" << Current.Ang[Body.rightID] << "  TIME1= " << Current.sec << " TIME2=" << Current.nsec << std::endl;
00571 #endif
00572 
00573         //--  write to OutPort
00574         m_OdometryPositionOut.write();
00575 
00576 #if DEBUG       
00577   //-- TODO:[someday REMOVE]  [DEBUG] output current position & posture angle data to file 
00578         ofs << Current.x  << "  " << Current.y << "     "  << Current.theta << "        "  << 180.0*Current.theta/M_PI << std::endl;
00579 #endif
00580 
00581 #if LOG
00582         std::cout <<  "[Odometry Position] Time = " << Current.Time << "[s]  (X[m],Y[m],Theta[deg]/[rad]) =  (" << Current.x  << " , " << Current.y << " , "  << 180.0*Current.theta/M_PI << "/"  << Current.theta << ") "  << std::endl;
00583 #endif
00584 
00585         return;
00586 }
00587 
00588 
00589 
00590 /*
00591 RTC::ReturnCode_t Odometry::onAborting(RTC::UniqueId ec_id)
00592 {
00593   return RTC::RTC_OK;
00594 }
00595 */
00596 
00597 /*
00598 RTC::ReturnCode_t Odometry::onError(RTC::UniqueId ec_id)
00599 {
00600   return RTC::RTC_OK;
00601 }
00602 */
00603 
00604 /*
00605 RTC::ReturnCode_t Odometry::onReset(RTC::UniqueId ec_id)
00606 {
00607   return RTC::RTC_OK;
00608 }
00609 */
00610 
00611 /*
00612 RTC::ReturnCode_t Odometry::onStateUpdate(RTC::UniqueId ec_id)
00613 {
00614   return RTC::RTC_OK;
00615 }
00616 */
00617 
00618 /*
00619 RTC::ReturnCode_t Odometry::onRateChanged(RTC::UniqueId ec_id)
00620 {
00621   return RTC::RTC_OK;
00622 }
00623 */
00624 
00625 
00626 
00627 extern "C"
00628 {
00629  
00630   void OdometryInit(RTC::Manager* manager)
00631   {
00632     coil::Properties profile(odometry_spec);
00633     manager->registerFactory(profile,
00634                              RTC::Create<Odometry>,
00635                              RTC::Delete<Odometry>);
00636   }
00637   
00638 };
00639 
00640 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


RS003
Author(s):
autogenerated on Thu Jun 27 2013 14:58:49