PrimarySomatosensoryCortexI.C
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 "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
00089 }
00090
00091
00092 void PrimarySomatosensoryCortexI::run() {
00093
00094 while(1) {
00095
00096 float xPos; float yPos; float orientation;
00097 if (itsRobot->getSensors(xPos,yPos,orientation))
00098 {
00099
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
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 }