PrefrontalCortexI.C

00001 /*!@file Hippocampus.C maintains the current thought location of the robot */
00002 //This modules invovles in the perception
00003 
00004 //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Lior Elazary <lelazary@yahoo.com>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/RobotBrain/PrefrontalCortexI.C $
00036 // $Id: PrefrontalCortexI.C 10794 2009-02-08 06:21:09Z itti $
00037 //
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Media/FrameSeries.H"
00041 #include "Transport/FrameInfo.H"
00042 #include "Raster/GenericFrame.H"
00043 #include "Image/Image.H"
00044 #include "GUI/ImageDisplayStream.H"
00045 #include "Robots/RobotBrain/PrefrontalCortexI.H"
00046 
00047 
00048 // ######################################################################
00049 PrefrontalCortexI::PrefrontalCortexI(OptionManager& mgr,
00050     const std::string& descrName, const std::string& tagName) :
00051   ModelComponent(mgr, descrName, tagName),
00052   itsGoalState(new RobotSimEvents::GoalStateMessage),
00053   itsGoalProgress(new RobotSimEvents::GoalProgressMessage),
00054   itsCurrentWaypointId(0)
00055 {
00056   itsGoalState->xPos = 0;
00057   itsGoalState->yPos = 0;
00058   itsGoalState->orientation = 0;
00059 
00060   itsGoalProgress->err = -1.0f;
00061 }
00062 
00063 // ######################################################################
00064 PrefrontalCortexI::~PrefrontalCortexI()
00065 {
00066   SimEventsUtils::unsubscribeSimEvents(itsTopicsSubscriptions, itsObjectPrx);
00067 }
00068 
00069 
00070 // ######################################################################
00071 void PrefrontalCortexI::init(Ice::CommunicatorPtr ic, Ice::ObjectAdapterPtr adapter)
00072 {
00073         Ice::ObjectPtr objPtr = this;
00074   itsObjectPrx = adapter->add(objPtr,
00075       ic->stringToIdentity("PreforntalCortex"));
00076 
00077 
00078   IceStorm::TopicPrx topicPrx;
00079 
00080   itsTopicsSubscriptions.push_back(SimEventsUtils::TopicInfo("GoalProgressMessageTopic", topicPrx));
00081 
00082   SimEventsUtils::initSimEvents(ic, itsObjectPrx, itsTopicsSubscriptions);
00083 
00084   itsEventsPub = RobotSimEvents::EventsPrx::uncheckedCast(
00085       SimEventsUtils::getPublisher(ic, "GoalStateMessageTopic")
00086       );
00087 
00088   IceUtil::ThreadPtr thread = this;
00089   thread->start();
00090 
00091   usleep(10000);
00092 }
00093 
00094 
00095 // ######################################################################
00096 void PrefrontalCortexI::run()
00097 {
00098 
00099   while(1)
00100   {
00101     evolve();
00102     usleep(10000);
00103   }
00104 
00105 }
00106 
00107 // ######################################################################
00108 void PrefrontalCortexI::evolve()
00109 {
00110   return; //Dont drive the robot
00111 
00112   if (itsGoalProgress->err == -1)
00113   {
00114     switch(itsCurrentWaypointId)
00115     {
00116       case 0:
00117         itsGoalState->xPos = -18;
00118         itsGoalState->yPos = -1.2;
00119         itsGoalState->orientation = 0;
00120         break;
00121       case 1:
00122         itsGoalState->xPos = -18;
00123         itsGoalState->yPos = 20;
00124         itsGoalState->orientation = 0;
00125         break;
00126       case 2:
00127         itsGoalState->xPos = 0;
00128         itsGoalState->yPos = 18;
00129         itsGoalState->orientation = 0;
00130         break;
00131       case 3:
00132         itsGoalState->xPos = 0;
00133         itsGoalState->yPos = 0;
00134         itsGoalState->orientation = 0;
00135         break;
00136     }
00137     itsCurrentWaypointId++;
00138     itsCurrentWaypointId = itsCurrentWaypointId%4;
00139 
00140     itsEventsPub->updateMessage(itsGoalState);
00141   }
00142 
00143   LDEBUG("Got goal progress Waypoint:%i err:%f",
00144       itsCurrentWaypointId,
00145       itsGoalProgress->err);
00146 
00147 }
00148 
00149 // ######################################################################
00150 void PrefrontalCortexI::updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00151     const Ice::Current&)
00152 {
00153   //Get a gps message
00154   if(eMsg->ice_isA("::RobotSimEvents::GoalProgressMessage"))
00155   {
00156     RobotSimEvents::GoalProgressMessagePtr gpMsg = RobotSimEvents::GoalProgressMessagePtr::dynamicCast(eMsg);
00157     itsGoalProgress->err = gpMsg->err;
00158   }
00159 }
00160 
Generated on Sun May 8 08:41:32 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3