RG_Lane.H
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "Component/ModelComponent.H"
00038 #include "Component/ModelParam.H"
00039
00040 #include "Robots/RobotBrain/RobotBrainComponent.H"
00041 #include "Util/Timer.H"
00042
00043 #include "Ice/RobotBrainObjects.ice.H"
00044 #include "Ice/RobotSimEvents.ice.H"
00045 #include <IceUtil/Thread.h>
00046
00047 #include "Robots/Beobot2/BeoCommon.H"
00048
00049 #include "Media/FrameSeries.H"
00050
00051 #include "Image/Image.H"
00052 #include "Image/Point3D.H"
00053 #include "Raster/Raster.H"
00054
00055 #include <vector>
00056 #include "Transport/FrameInfo.H"
00057
00058 #ifndef RG_LANE
00059 #define RG_LANE
00060
00061 typedef struct _RegionInformation
00062 {
00063 uint start;
00064 uint end;
00065
00066 float minDistance;
00067 uint minIndex;
00068 }
00069 RegionInformation;
00070
00071 class imageDB
00072 {
00073 std::string path;
00074 int start;
00075 int end;
00076 int current;
00077 public:
00078 imageDB(){}
00079
00080 imageDB(std::string p,int s,int e){
00081 start = s;
00082 end = e;
00083 path = p;
00084 current = s;
00085 }
00086 Image<PixRGB<byte> > nextImg(){
00087 std::string imgpath = sformat("%s%05d.ppm",path.c_str(),current);
00088 LDEBUG("Image path is %s",imgpath.c_str());
00089 if(current++ > end)
00090 current = start;
00091 return Raster::ReadRGB(imgpath.c_str());
00092 }
00093 ~imageDB(){}
00094 };
00095 class kalman_filter
00096 {
00097 float est_var,sensor_var;
00098 float k;
00099 float est_x;
00100 public:
00101 kalman_filter(float ini_ev,float ini_sv){
00102 est_var = ini_ev;
00103 sensor_var = ini_sv;
00104 k = est_var/(est_var + sensor_var);
00105 est_x = 0;
00106 }
00107 float update(float measure){
00108 if(est_x == 0){
00109 est_x = measure;
00110 return est_x;
00111 }
00112 est_x = est_x + 10*k*(measure - est_x);
00113 est_var = est_var*sensor_var/(est_var+sensor_var);
00114 k = est_var/(est_var+sensor_var);
00115 return est_x;
00116 }
00117
00118 };
00119
00120 class RG_Lane: public RobotBrainComponent
00121 {
00122 public:
00123
00124 RG_Lane(OptionManager& mgr,
00125 const std::string& descrName = "RG_Lane",
00126 const std::string& tagName = "RG_Lane");
00127
00128 ~RG_Lane();
00129
00130 virtual void evolve();
00131
00132
00133 virtual void updateMessage (const RobotSimEvents::EventMessagePtr& eMsg, const Ice::Current&);
00134
00135 virtual void registerTopics();
00136
00137 void start1();
00138
00139 private:
00140
00141 void openDB(const std::string& path);
00142 void loadFrame();
00143
00144 void loadDB(const std::string& path);
00145 void drawState();
00146 Image<PixRGB<byte> > itsCurrImg;
00147 Image<PixRGB<byte> > itsProcImg;
00148 nub::soft_ref<OutputFrameSeries> itsOfs;
00149 imageDB itsImageDB;
00150 kalman_filter itsKf;
00151 int itsKfx;
00152
00153 Image<PixRGB<byte> > itsDispImg;
00154
00155
00156 Timer itsTimer;
00157 };
00158 #endif
00159
00160
00161
00162
00163
00164