Odometry.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00017 #ifndef ODOMETRY_H
00018 #define ODOMETRY_H
00019 
00020 #include <rtm/Manager.h>
00021 #include <rtm/DataFlowComponentBase.h>
00022 #include <rtm/CorbaPort.h>
00023 #include <rtm/DataInPort.h>
00024 #include <rtm/DataOutPort.h>
00025 #include <rtm/idl/BasicDataTypeSkel.h>
00026 
00027 //---[add]--------------------------------
00028 #include "intellirobotStub.h"
00029 #include "intellirobotSkel.h"
00030 #include "intellirobot.hh"
00031 
00032 //#include <rtm/RingBuffer.h>
00033 #include <stdio.h>
00034 #include <iostream>
00035 #include <fstream>
00036 #include <math.h>
00037 #define LOG 0
00038 #define DEBUG 0
00039 #define DEBUG2 0
00040 #define CALLBACK 0
00041 #define CALLBACK_DEBUG 0
00042 
00043 #if CALLBACK            
00044 #include <rtm/RingBuffer.h>
00045 //-CallBackObject--
00046 class Debug
00047         : public RTC::OnWriteConvert<RTC::TimedDoubleSeq>
00048 {
00049         //ofstream ofsCallBack;
00050         public:
00051                 Debug(void) {   
00052                   //ofsCallBack.open("data/callback.dat");  
00053                 };
00054                 RTC::TimedDoubleSeq operator()(const RTC::TimedDoubleSeq& value)
00055                 {
00056                         RTC::TimedDoubleSeq ret(value);
00057 #if CALLBACK_DEBUG
00058                         double dummy_sec = value.tm.sec + 1.0e-9*value.tm.nsec;
00059                         printf("--[CallBack_TIME(WheelAngle)]: %lf\t[L]=%lf\t[R]=%lf\n",dummy_sec, value.data[0], value.data[1]);
00060                         //printf("--[CallBack_TIME(LocalizedPosition)]: %lf\tx=%lf\ty=%lf\ttheta=%lf\n",dummy_sec, value.data[0], value.data[1], value.data[2]);
00061 #endif
00062                         return ret;
00063                 };
00064 
00065 };
00066 //--
00067 #endif
00068 using namespace std;
00069 //---[add]--------------------------------
00070 
00071 using namespace RTC;
00072 using namespace IIS;
00073 
00090 class Odometry
00091   : public RTC::DataFlowComponentBase
00092 {
00093  public:
00094   Odometry(RTC::Manager* manager);
00095   ~Odometry();
00096 
00097    virtual RTC::ReturnCode_t onInitialize();
00098   /***
00099    * (1) update INPORT's data
00100    * (2) open files for debugging
00101    * (3) initialize
00102    *
00103    * The activated action (Active state entry action)
00104    * former rtc_active_entry()
00105    *
00106    * @param ec_id target ExecutionContext Id
00107    *
00108    * @return RTC::ReturnCode_t
00109    * 
00110    * @pre none
00111    * @post none
00112    * 
00113    */
00114    virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00115 
00116   /***
00117    * (1)close files for debugging
00118    *
00119    * The deactivated action (Active state exit action)
00120    * former rtc_active_exit()
00121    *
00122    * @param ec_id target ExecutionContext Id
00123    *
00124    * @return RTC::ReturnCode_t
00125    * 
00126    * @pre none
00127    * @post none
00128    * 
00129    */
00130    virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00131 
00132   /***
00133    * (1)get current Wheel Angle data from MotorControlRTC
00134    * (2)get current Robot's position data from LocalizationRTC
00135    * (3)calculate current position by Odometry
00136    * (4)send current odometry position data to LocalizationRTC
00137    *
00138    * The execution action that is invoked periodically
00139    * former rtc_active_do()
00140    *
00141    * @param ec_id target ExecutionContext Id
00142    *
00143    * @return RTC::ReturnCode_t
00144    * 
00145    * @pre none
00146    * @post none
00147    * 
00148    */
00149    virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00150 
00151 
00152 //---[add]--------------------------------
00157         virtual void getLocalizedPosition();
00158 
00163         virtual bool getWheelAngleData();
00164 
00169         virtual void calcOdometry();
00174         virtual void setCurrentToOld();
00175 
00180         virtual void outputData();
00181 //---[add]--------------------------------
00182 
00183 
00184  protected:
00192   int m_leftWheelID;
00200   int m_rightWheelID;
00208   double m_radiusOfLeftWheel;
00216   double m_radiusOfRightWheel;
00224   double m_lengthOfAxle;
00231   double m_radiusOfBodyArea;
00232   // </rtc-template>
00233 
00234   // DataInPort declaration
00235   // <rtc-template block="inport_declare">
00236   TimedDoubleSeq m_CurrentWheelAngle;
00246   InPort<TimedDoubleSeq> m_CurrentWheelAngleIn;
00247   IIS::TimedPose2D m_LocalizedPosition;
00248 
00260   InPort<IIS::TimedPose2D> m_LocalizedPositionIn;
00261   
00262   // </rtc-template>
00263 
00264 
00265   // DataOutPort declaration
00266   // <rtc-template block="outport_declare">
00267   IIS::TimedPose2D m_OdometryPosition;
00279   OutPort<IIS::TimedPose2D> m_OdometryPositionOut;  
00280 
00281  private:
00282 
00283 //---[add]----------------------------------------
00284         //--static PARAMETER
00285         const static int Dof = 2;              
00286         //double Pi;        //!< the ratio of the circumference of a circle to its diameter
00287         double RotationAngleBorder; 
00288         double RhoBorder;   
00289 
00291         struct BODY {
00292                 int leftID;    
00293                 int rightID;   
00294                 double length;      
00295                 double wheelRadiusLeft;   
00296                 double wheelRadiusRight;   
00297                 double bodyRadius;   
00298         }Body;
00299 
00301         struct CURRENT {
00302                 double BodyVel;   
00303                 double RightVel;  
00304                 double LeftVel;   
00305                 double BodyAccel; 
00306                 double BodyOmega; 
00307                 double Rho;      
00308 //              double sumLength;  //!< the sum of distance which robot moved
00309                 double BodyVelOld;   
00310                 double BodyOmegaOld; 
00311                 double RhoOld;       
00312                 double Ang[Dof];     
00313                 double AngVel[Dof];  
00314                 double AngOld[Dof];  
00315                 double AngVelOld[Dof]; 
00316                 double x;    
00317                 double y;    
00318                 double theta;    
00319                 double xOld;    
00320                 double yOld;    
00321                 double thetaOld;   
00322 //              double distanceToGoal;  //! the distance from current position to GOAL
00323                 unsigned long sec;  
00324                 unsigned long nsec;  
00325                 unsigned long secOld;  
00326                 unsigned long nsecOld;  
00327                 double Time;          
00328                 double TimeOld;       
00329         }Current;
00330 
00331         //--others
00332         double timeStep;   
00333         bool InitialPositionFlag; 
00334         bool InitialAngleFlag; 
00335 
00336 #if DEBUG               
00337         //-- output file pointer for debugging
00338         ofstream ofs;   
00339 #endif
00340 
00341 #if CALLBACK
00342         //-- callback object
00343         Debug m_debug;  
00344 #endif
00345 
00346 #if DEBUG2
00347         long counter;
00348         ofstream ofs2;   
00349         ofstream ofs3;   
00350         //--for TimeDebug
00351         struct timeval TotalTime;  
00352         struct timeval GetTime;                 
00353         struct timeval SetTime;                 
00354 #endif
00355 
00356 //---[add]----------------------------------------
00357 
00358 };
00359 
00360 
00361 extern "C"
00362 {
00363   DLL_EXPORT void OdometryInit(RTC::Manager* manager);
00364 };
00365 
00366 #endif // ODOMETRY_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


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