AgentManager.H
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 #ifndef __SEABEE_AGENT_MANAGER_H__
00039 #define __SEABEE_AGENT_MANAGER_H__
00040
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 #include "Component/ModelManager.H"
00044
00045 #include "Raster/Raster.H"
00046 #include "Image/Image.H"
00047 #include "Image/Pixels.H"
00048 #include "Image/CutPaste.H"
00049
00050 #include "Neuro/EnvVisualCortex.H"
00051
00052 #include "GUI/XWinManaged.H"
00053
00054 #include "Globals.H"
00055 #include "AgentManagerCommand.H"
00056
00057 #include "ForwardVision.H"
00058
00059
00060 #include "SubController.H"
00061 #include "SensorResult.H"
00062
00063
00064
00065 #include "GUI/DebugWin.H"
00066
00067 #include "Util/Timer.H"
00068 #include <pthread.h>
00069
00070
00071
00072 class ForwardVisionAgent;
00073
00074
00075
00076 class AgentManager : public ModelComponent
00077 {
00078 public:
00079
00080
00081
00082
00083
00084
00085 AgentManager(nub::soft_ref<SubController> subController,
00086 nub::soft_ref<EnvVisualCortex> evc,
00087 ModelManager& mgr,
00088 const std::string& descrName = "Agent Manager",
00089 const std::string& tagName = "Agent Manager");
00090
00091
00092 virtual ~AgentManager();
00093
00094
00095
00096
00097
00098
00099
00100
00101 void setCurrentForwardImage(Image<PixRGB<byte> > image, uint fNum);
00102
00103 void setCurrentDownwardImage(Image<PixRGB<byte> > image, uint fNum);
00104
00105
00106 inline void setSubController(nub::soft_ref<SubController> subController);
00107
00108 inline void setForwardWindow(rutz::shared_ptr<XWinManaged> win);
00109
00110 inline void setDownwardWindow(rutz::shared_ptr<XWinManaged> win);
00111
00112
00113 void pushCommand(CommandType cmdType,
00114 rutz::shared_ptr<Mission> mission);
00115
00116
00117 inline Image<PixRGB<byte> > getCurrentForwardImage();
00118 inline Image<PixRGB<byte> > getCurrentDownwardImage();
00119
00120
00121 inline uint getCurrentFrameNumber();
00122
00123 inline void setWindow(rutz::shared_ptr<XWinManaged> win);
00124
00125 inline void setVisualCortex(nub::ref<EnvVisualCortex> evc);
00126
00127 inline void drawForwardImage(rutz::shared_ptr< Image<PixRGB<byte> > > ima);
00128 inline void drawDownwardImage(rutz::shared_ptr< Image<PixRGB<byte> > > ima);
00129
00130
00131 void initSensorResults();
00132
00133
00134 bool updateSensorResult(rutz::shared_ptr<SensorResult> sensorResult);
00135
00136
00137 void updateAgentsMission(Mission theMission);
00138
00139
00140
00141
00142
00143 rutz::shared_ptr<ForwardVisionAgent> getForwardVisionAgent();
00144
00145
00146
00147
00148
00149 uint getNumCommands();
00150
00151 rutz::shared_ptr<SensorResult> getSensorResult(SensorResult::SensorResultType type);
00152
00153 rutz::shared_ptr<AgentManagerCommand> popCommand();
00154
00155 void startRun();
00156
00157 int itsMissionGateForwardTime;
00158 int itsMissionGateDepth;
00159
00160 const Image<PixRGB<byte> >* getForwardDebugImagePtr();
00161
00162
00163
00164 private:
00165
00166 Image<PixRGB<byte> > itsForwardDebugImage;
00167
00168
00169 rutz::shared_ptr<XWinManaged> itsForwardWindow;
00170 rutz::shared_ptr<XWinManaged> itsDownwardWindow;
00171 Image<PixRGB<byte> > itsDisplayImage;
00172 pthread_mutex_t itsForwardDisplayLock;
00173 pthread_mutex_t itsDownwardDisplayLock;
00174
00175
00176 Image<PixRGB<byte> > itsCurrentForwardImage;
00177 Image<PixRGB<byte> > itsCurrentDownwardImage;
00178 uint itsFrameNumber;
00179 rutz::shared_ptr<Timer> itsTimer;
00180 std::vector<uint64> itsFrameDuration;
00181 pthread_mutex_t itsCurrentForwardImageLock;
00182 pthread_mutex_t itsCurrentDownwardImageLock;
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 rutz::shared_ptr<ForwardVisionAgent> itsForwardVisionAgent;
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 nub::soft_ref<SubController> itsSubController;
00209 pthread_mutex_t itsSubControllerLock;
00210
00211
00212 std::vector<rutz::shared_ptr<SensorResult> > itsSensorResults;
00213 std::vector<rutz::shared_ptr<SensorResult> >::iterator itsSensorResultsItr;
00214
00215 pthread_mutex_t itsSensorResultsLock;
00216
00217
00218 std::list<rutz::shared_ptr<AgentManagerCommand> > itsCommands;
00219 pthread_mutex_t itsCommandsLock;
00220
00221 nub::soft_ref<EnvVisualCortex> itsEVC;
00222
00223 };
00224
00225
00226 inline void AgentManager::setSubController(nub::soft_ref<SubController> subController)
00227 {
00228 pthread_mutex_lock(&itsSubControllerLock);
00229 itsSubController = subController;
00230 pthread_mutex_unlock(&itsSubControllerLock);
00231 }
00232
00233
00234 inline void AgentManager::setForwardWindow(rutz::shared_ptr<XWinManaged> win)
00235 {
00236 itsForwardWindow = win;
00237
00238 }
00239
00240
00241 inline void AgentManager::setDownwardWindow(rutz::shared_ptr<XWinManaged> win)
00242 {
00243 itsDownwardWindow = win;
00244
00245 }
00246
00247
00248 inline void AgentManager::setVisualCortex
00249 (nub::ref<EnvVisualCortex> evc)
00250 {
00251 itsEVC = evc;
00252 }
00253
00254
00255 inline Image<PixRGB<byte> > AgentManager::getCurrentForwardImage()
00256 {
00257 Image<PixRGB<byte> > image;
00258 pthread_mutex_lock(&itsCurrentForwardImageLock);
00259 image = itsCurrentForwardImage;
00260 pthread_mutex_unlock(&itsCurrentForwardImageLock);
00261 return image;
00262 }
00263
00264
00265 inline Image<PixRGB<byte> > AgentManager::getCurrentDownwardImage()
00266 {
00267 Image<PixRGB<byte> > image;
00268 pthread_mutex_lock(&itsCurrentDownwardImageLock);
00269 image = itsCurrentDownwardImage;
00270 pthread_mutex_unlock(&itsCurrentDownwardImageLock);
00271 return image;
00272 }
00273
00274
00275 inline uint AgentManager::getCurrentFrameNumber()
00276 {
00277 uint fNum;
00278 pthread_mutex_lock(&itsCurrentForwardImageLock);
00279 fNum = itsFrameNumber;
00280 pthread_mutex_unlock(&itsCurrentForwardImageLock);
00281 return fNum;
00282 }
00283
00284
00285 inline void AgentManager::drawForwardImage(rutz::shared_ptr<Image<PixRGB<byte> > > ima)
00286 {
00287 pthread_mutex_lock(&itsForwardDisplayLock);
00288 itsForwardWindow->drawImage(*ima, 0, 0);
00289 pthread_mutex_unlock(&itsForwardDisplayLock);
00290
00291 }
00292
00293
00294 inline void AgentManager::drawDownwardImage(rutz::shared_ptr<Image<PixRGB<byte> > > ima)
00295 {
00296 pthread_mutex_lock(&itsDownwardDisplayLock);
00297 itsDownwardWindow->drawImage(*ima, 0, 0);
00298 pthread_mutex_unlock(&itsDownwardDisplayLock);
00299
00300 }
00301 #endif
00302
00303
00304
00305
00306
00307