PrefrontalCortexI.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
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;
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
00154 if(eMsg->ice_isA("::RobotSimEvents::GoalProgressMessage"))
00155 {
00156 RobotSimEvents::GoalProgressMessagePtr gpMsg = RobotSimEvents::GoalProgressMessagePtr::dynamicCast(eMsg);
00157 itsGoalProgress->err = gpMsg->err;
00158 }
00159 }
00160