Homepage Demos Overview Downloads Tutorials Reference
Credits

ExploreMachine.cc

Go to the documentation of this file.
00001 #include "ExploreMachine.h"
00002 #include "Behaviors/Nodes/WalkNode.h"
00003 #include "Behaviors/Transitions/SmoothCompareTrans.h"
00004 #include "Behaviors/Transitions/TimeOutTrans.h"
00005 #include "Shared/ERS210Info.h"
00006 #include "Shared/ERS220Info.h"
00007 #include "Shared/ERS7Info.h"
00008 #include "Wireless/Socket.h"
00009 #include "Shared/WorldState.h"
00010 
00011 void ExploreMachine::setup() {
00012   //cout << "Explore SETUP " << issetup << "...";
00013   unsigned int IRDistOffset;
00014   if(state->robotDesign&WorldState::ERS210Mask)
00015     IRDistOffset=ERS210Info::IRDistOffset;
00016   else if(state->robotDesign&WorldState::ERS220Mask)
00017     IRDistOffset=ERS220Info::IRDistOffset;
00018   else if(state->robotDesign&WorldState::ERS7Mask)
00019     IRDistOffset=ERS7Info::NearIRDistOffset;
00020   else {
00021     serr->printf("ExploreMachine: Unsupported model!\n");
00022     return;
00023   }
00024 
00025   SharedObject<WalkMC> walk;
00026   walkid=motman->addPersistentMotion(walk);
00027 
00028   WalkNode * move=NULL;
00029   addNode(move=new WalkNode(getName()+"::move",150,0,0));
00030   move->setWalkID(walkid);
00031   start=addNode(turn=new WalkNode(getName()+"::turn",0,0,0.5f));
00032   turn->setWalkID(walkid);
00033 
00034   move->addTransition(new SmoothCompareTrans<float>(turn,&state->sensors[IRDistOffset],CompareTrans<float>::LT,350,EventBase(EventBase::sensorEGID,SensorSourceID::UpdatedSID,EventBase::statusETID),.7));
00035   turn->addTransition(new TimeOutTrans(move,2000));
00036 
00037   StateNode::setup();
00038   //cout << issetup << endl;
00039 }
00040 
00041 void ExploreMachine::DoStart() {
00042   StateNode::DoStart();
00043   start->DoStart();
00044   //erouter->addListener(this,EventBase::sensorEGID,SensorSourceID::UpdatedSID);
00045   erouter->addListener(this,EventBase::stateMachineEGID,(unsigned int)turn,EventBase::activateETID);
00046 }
00047 
00048 void ExploreMachine::DoStop() {
00049   erouter->removeListener(this);
00050   StateNode::DoStop();
00051 }
00052 
00053 void ExploreMachine::teardown() {
00054   //cout << "Explore TEARDOWN " << issetup << "...";
00055   motman->removeMotion(walkid);
00056   StateNode::teardown();
00057   //cout << issetup << endl;
00058 }
00059 
00060 void ExploreMachine::processEvent(const EventBase& /*e*/) {
00061   //sout->printf("IR: %g\n",state->sensors[IRDistOffset]);
00062   float vel=rand()/(float)RAND_MAX*2.0f-1;
00063   if(vel<0)
00064     vel-=.25;
00065   if(vel>0)
00066     vel+=.25;
00067   turn->setAVelocity(vel);
00068 }
00069 
00070 /*! @file
00071  * @brief Describes ExploreMachine, a state machine for exploring an environment (or searching for an object)
00072  * @author ejt (Creator)
00073  *
00074  * $Author: ejt $
00075  * $Name: tekkotsu-2_2_2 $
00076  * $Revision: 1.1 $
00077  * $State: Exp $
00078  * $Date: 2004/12/04 00:10:38 $
00079  */

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:13 2005 by Doxygen 1.4.0