Go to the documentation of this file.00001
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
00028 #include "intellirobotStub.h"
00029 #include "intellirobotSkel.h"
00030 #include "intellirobot.hh"
00031
00032
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
00046 class Debug
00047 : public RTC::OnWriteConvert<RTC::TimedDoubleSeq>
00048 {
00049
00050 public:
00051 Debug(void) {
00052
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
00061 #endif
00062 return ret;
00063 };
00064
00065 };
00066
00067 #endif
00068 using namespace std;
00069
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
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00150
00151
00152
00157 virtual void getLocalizedPosition();
00158
00163 virtual bool getWheelAngleData();
00164
00169 virtual void calcOdometry();
00174 virtual void setCurrentToOld();
00175
00180 virtual void outputData();
00181
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
00233
00234
00235
00236 TimedDoubleSeq m_CurrentWheelAngle;
00246 InPort<TimedDoubleSeq> m_CurrentWheelAngleIn;
00247 IIS::TimedPose2D m_LocalizedPosition;
00248
00260 InPort<IIS::TimedPose2D> m_LocalizedPositionIn;
00261
00262
00263
00264
00265
00266
00267 IIS::TimedPose2D m_OdometryPosition;
00279 OutPort<IIS::TimedPose2D> m_OdometryPositionOut;
00280
00281 private:
00282
00283
00284
00285 const static int Dof = 2;
00286
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
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
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
00332 double timeStep;
00333 bool InitialPositionFlag;
00334 bool InitialAngleFlag;
00335
00336 #if DEBUG
00337
00338 ofstream ofs;
00339 #endif
00340
00341 #if CALLBACK
00342
00343 Debug m_debug;
00344 #endif
00345
00346 #if DEBUG2
00347 long counter;
00348 ofstream ofs2;
00349 ofstream ofs3;
00350
00351 struct timeval TotalTime;
00352 struct timeval GetTime;
00353 struct timeval SetTime;
00354 #endif
00355
00356
00357
00358 };
00359
00360
00361 extern "C"
00362 {
00363 DLL_EXPORT void OdometryInit(RTC::Manager* manager);
00364 };
00365
00366 #endif // ODOMETRY_H