Beobot.C
Go to the documentation of this file.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
00038 #include "Beobot/Beobot.H"
00039
00040
00041 Beobot::Beobot(const char *slaves, const int imgw, const int imgh,
00042 const int lev_min, const int lev_max,
00043 const int delta_min, const int delta_max,
00044 const int smlev, const int nborient, const MaxNormType normtype,
00045 const int jlev, const int jdepth, const int nbneig,
00046 const in_addr_t ip, const short int port)
00047 {
00048 if (slaves)
00049 {
00050
00051 LINFO("Initializing Beowulf as master");
00052
00053 LFATAL("THIS CODE IS TEMPORARILY BROKEN");
00054
00055 visualCortex.init(imgw, imgh, lev_min, lev_max, delta_min, delta_max,
00056 smlev, nborient, normtype, jlev, jdepth, nbneig, beo);
00057 }
00058 else
00059
00060 visualCortex.init(imgw, imgh, lev_min, lev_max, delta_min, delta_max,
00061 smlev, nborient, normtype, jlev, jdepth, nbneig,
00062 nub::soft_ref<Beowulf>());
00063 }
00064
00065
00066 void Beobot::newVisualInput(Image< PixRGB<byte> >& scene)
00067 { visualCortex.newVisualInput(scene); }
00068
00069
00070 Image< PixRGB<byte> >* Beobot::getRetinaPtr()
00071 { return visualCortex.getScenePtr(); }
00072
00073
00074 void Beobot::lowLevel(const int frame)
00075 { visualCortex.process(frame); }
00076
00077
00078 void Beobot::lowLevelStart(const int frame)
00079 { visualCortex.processStart(frame); }
00080
00081
00082 void Beobot::lowLevelEnd(const int frame)
00083 { visualCortex.processEnd(frame); }
00084
00085
00086 void Beobot::getWinner(Point2D<int>& win) const
00087 { visualCortex.getWinner(win); }
00088
00089
00090 void Beobot::intermediateLevel(bool initMasses)
00091 {
00092 visualCortex.initSprings(initMasses);
00093
00094 const float dt = 0.1;
00095
00096 int nbIter = 3; if (initMasses) nbIter=15;
00097
00098 for (int t = 0; t < nbIter; t ++) visualCortex.iterateSprings(dt);
00099
00100 Image< PixRGB<byte> > clusteredImage;
00101 Point2D<int> supposedTrackCentroid;
00102 Point2D<int> previousTrackCentroid;
00103
00104 BeobotSensation sensa;
00105
00106
00107
00108
00109
00110
00111 int nbMemories = 0;
00112
00113 while (memory.passedSensation(nbMemories, sensa))
00114 {
00115 Point2D<int> pt;
00116 sensa.getCentroid(pt);
00117
00118 previousTrackCentroid += pt;
00119 nbMemories ++;
00120
00121 if (nbMemories >= BeobotMemory::memoryLength) break;
00122 }
00123
00124 if (nbMemories > 0)
00125
00126 previousTrackCentroid /= nbMemories;
00127 else
00128 {
00129
00130
00131 visualCortex.getInputSize(previousTrackCentroid);
00132
00133 previousTrackCentroid.i /= 2;
00134
00135 previousTrackCentroid.j *= 7; previousTrackCentroid.j /= 8;
00136 }
00137
00138 visualCortex.getClusteredImage(clusteredImage, supposedTrackCentroid,
00139 previousTrackCentroid);
00140
00141 BeobotSensation sensation(clusteredImage, supposedTrackCentroid);
00142
00143 memory.presentSensation(sensation);
00144 }
00145
00146
00147 void Beobot::DEBUGgetClustered(Image< PixRGB<byte> >& im)
00148 {
00149 BeobotSensation sensa;
00150 memory.passedSensation(0, sensa);
00151
00152 sensa.getQuickLayout(im);
00153 }
00154
00155
00156 void Beobot::highLevel( void )
00157 {
00158 BeobotSensation s;
00159
00160 memory.passedSensation(0, s);
00161 Image< PixRGB<byte> > ql;
00162
00163 s.getQuickLayout(ql);
00164
00165
00166 int w = ql.getWidth();
00167 int h = ql.getWidth();
00168
00169
00170 int pointX = w / 2;
00171 int pointY = h * 7 / 8;
00172
00173 Point2D<int> centroid;
00174 s.getCentroid(centroid);
00175
00176
00177 BeobotAction action;
00178
00179
00180 if (centroid.j > pointY)
00181
00182 action.setSpeed(0.1);
00183 else if( centroid.j < h/2 )
00184 action.setSpeed(1.0);
00185 else
00186
00187
00188 action.setSpeed( 1.0*( -(float)centroid.j+(float)h )/((float)h/2.0) );
00189
00190
00191
00192 action.setTurn( ((float)centroid.i-(float)pointX)/(float)pointX );
00193
00194
00195 action.setGear(1);
00196
00197
00198 memory.presentActionRecommendation( action );
00199 }
00200
00201
00202 void Beobot::decision( void )
00203 {
00204 memory.generatePresentAction(currentAction);
00205 }
00206
00207
00208 void Beobot::action( void )
00209 {
00210
00211
00212
00213 effectors->performAction(currentAction);
00214 }
00215
00216
00217
00218
00219
00220