VisualOdometry.h
Go to the documentation of this file.00001 #ifndef VISUAL_ODOMETRY_H
00002 #define VISUAL_ODOMETRY_H
00003
00004 #include <math.h>
00005 #include <algorithm>
00006 #include <vector>
00007
00008 #include "IPC/SharedObject.h"
00009 #include "Motion/HeadPointerMC.h"
00010 #include "Motion/MMAccessor.h"
00011 #include "Shared/mathutils.h"
00012 #include "DualCoding/Sketch.h"
00013 #include "OpticalFlow.h"
00014
00015 namespace DualCoding {
00016
00017
00018 class VisualOdometry {
00019 public:
00020 VisualOdometry() : sleeping(true), lastAngle(0.0), lastTranslation(0) {};
00021
00022 virtual ~VisualOdometry() {}
00023
00024 virtual void update(bool overrideSleep=false) = 0;
00025 virtual float getAngle() { return lastAngle; }
00026 virtual int getTranslation() { return lastTranslation; }
00027 virtual float getIntegratedAngle() { return 0.0f; }
00028
00029
00030 virtual void setConversionParameters(float slope, float offset) = 0;
00031
00032
00033 virtual unsigned int suggestedFrameRate() const = 0;
00034
00035
00036
00037 static const float ANGULAR_RESOLUTION;
00038
00039 protected:
00040 bool sleeping;
00041 float lastAngle;
00042 int lastTranslation;
00043 };
00044
00045
00046
00047 class OpticalFlowOdometry : public OpticalFlow, public VisualOdometry {
00048 public:
00049 OpticalFlowOdometry(const std::string &dummyName="") :
00050 OpticalFlow(), VisualOdometry(), scalingFactor(ANGULAR_RESOLUTION) {};
00051
00052 virtual void update(bool overrideSleep=false);
00053
00054
00055 virtual void setConversionParameters(float slope, float offset);
00056
00057 virtual float getIntegratedAngle() { return integratedFlow / scalingFactor; }
00058
00059
00060 virtual unsigned int suggestedFrameRate() const { return 100; }
00061
00062 private:
00063 float scalingFactor;
00064 };
00065
00066
00067
00068
00069 class ImageProfileOdometry : public VisualOdometry {
00070 public:
00071 ImageProfileOdometry(const std::string &dummyName="") :
00072 VisualOdometry(), currImageProfile(&profile1),
00073 profile1(RobotInfo::CameraResolutionX), profile2(RobotInfo::CameraResolutionX),
00074 translationProfile(RobotInfo::CameraResolutionX),
00075 angularResolution(ANGULAR_RESOLUTION), slope(ANGULAR_RESOLUTION), offset(0.0f)
00076 {}
00077
00078 ImageProfileOdometry(const ImageProfileOdometry &other);
00079 virtual ~ImageProfileOdometry() {}
00080 virtual float getAngle();
00081 virtual int getTranslation();
00082 virtual void update(bool sleepOverride=false);
00083
00084
00085 virtual void setConversionParameters(float slope, float offset);
00086
00087
00088 virtual unsigned int suggestedFrameRate() const { return 4; }
00089
00090 float getSlope() { return slope; }
00091 float getOffset() { return offset; }
00092
00093 protected:
00094 std::vector<float> *currImageProfile;
00095 std::vector<float> profile1;
00096 std::vector<float> profile2;
00097 std::vector<float> translationProfile;
00098
00099 private:
00100 ImageProfileOdometry & operator=(const ImageProfileOdometry &rhs);
00101 float angularResolution;
00102 float slope;
00103 float offset;
00104
00105 float differenceMeasure(int s);
00106 int minTranslation();
00107
00108
00109 float translationToAngle(int trans);
00110
00111
00112
00113
00114
00115
00116
00117
00118 void buildImageProfile();
00119
00120 void displayImageProfile();
00121 void swapCurrentProfile();
00122 void buildTranslationProfile();
00123 void displayTranslationProfile();
00124 };
00125
00126 typedef OpticalFlowOdometry CurrVisualOdometry;
00127
00128 }
00129
00130 #endif