PrimarySomatosensoryCortexI.C

00001 /*!@file PrimarySomatosensoryCortex.C drive the actual robot */
00002 
00003 //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary <lelazary@yahoo.com>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/RobotBrain/PrimarySomatosensoryCortexI.C $
00035 // $Id: PrimarySomatosensoryCortexI.C 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Component/ModelComponent.H"
00040 #include "Component/ModelParam.H"
00041 #include "Component/ModelOptionDef.H"
00042 #include "Media/FrameSeries.H"
00043 #include "Transport/FrameInfo.H"
00044 #include "Raster/GenericFrame.H"
00045 #include "Image/Image.H"
00046 #include "GUI/ImageDisplayStream.H"
00047 #include "Robots/RobotBrain/PrimarySomatosensoryCortexI.H"
00048 #include "Robots/RobotBrain/RobotCommon.H"
00049 
00050 #include "Ice/IceImageUtils.H"
00051 
00052 // ######################################################################
00053 PrimarySomatosensoryCortexI::PrimarySomatosensoryCortexI(OptionManager& mgr,
00054     const std::string& descrName, const std::string& tagName) :
00055   ModelComponent(mgr, descrName, tagName)
00056 {
00057 }
00058 
00059 // ######################################################################
00060 void PrimarySomatosensoryCortexI::init(Ice::CommunicatorPtr ic, Ice::ObjectAdapterPtr adapter)
00061 {
00062   Ice::ObjectPtr pscPtr = this;
00063   itsObjectPrx = adapter->add(pscPtr,
00064       ic->stringToIdentity("PrimarySomatosensoryCortex"));
00065 
00066   itsGPSPublisher = RobotSimEvents::EventsPrx::uncheckedCast(
00067         SimEventsUtils::getPublisher(ic, "GPSMessageTopic")
00068         );
00069   itsMotionPublisher = RobotSimEvents::EventsPrx::uncheckedCast(
00070         SimEventsUtils::getPublisher(ic, "MotionMessageTopic")
00071         );
00072 
00073   Ice::ObjectPrx base = ic->stringToProxy(
00074       "IRobotService:default -p 10000 -h " ROBOT_IP);
00075   itsRobot = Robots::IRobotPrx::checkedCast(base);
00076 
00077   if(!itsRobot) LFATAL("Invalid Robot Proxy");
00078 
00079   IceUtil::ThreadPtr thread = this;
00080   thread->start();
00081 
00082   usleep(10000);
00083 }
00084 
00085 // ######################################################################
00086 PrimarySomatosensoryCortexI::~PrimarySomatosensoryCortexI()
00087 {
00088   //SimEventsUtils::unsubscribeSimEvents(itsTopicsSubscriptions, itsObjectPrx);
00089 }
00090 
00091 // ######################################################################
00092 void PrimarySomatosensoryCortexI::run() {
00093 
00094   while(1) {
00095     //Get the GPS data from our robot implementation
00096     float xPos; float yPos; float orientation;
00097     if (itsRobot->getSensors(xPos,yPos,orientation))
00098     {
00099       //Pack that data up and publish it
00100       RobotSimEvents::GPSMessagePtr gpsMessage =
00101         new RobotSimEvents::GPSMessage;
00102 
00103       gpsMessage->xPos = xPos;
00104       gpsMessage->yPos = yPos;
00105       gpsMessage->orientation = orientation;
00106 
00107       itsGPSPublisher->updateMessage(gpsMessage);
00108     }
00109 
00110     //Get an odometry sensor
00111     float dist; float ang;
00112     if (itsRobot->getDistanceAngle(dist, ang))
00113     {
00114       RobotSimEvents::MotionMessagePtr motionMessage =
00115         new RobotSimEvents::MotionMessage;
00116 
00117       motionMessage->distance = dist;
00118       motionMessage->angle = ang;
00119 
00120       itsMotionPublisher->updateMessage(motionMessage);
00121     }
00122 
00123     usleep(10000);
00124   }
00125 }
00126 
00127 // ######################################################################
00128 void PrimarySomatosensoryCortexI::updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00129     const Ice::Current&)
00130 {
00131 }
Generated on Sun May 8 08:41:32 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3