ExploreMachine.ccGo 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
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
00039 }
00040
00041 void ExploreMachine::DoStart() {
00042 StateNode::DoStart();
00043 start->DoStart();
00044
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
00055 motman->removeMotion(walkid);
00056 StateNode::teardown();
00057
00058 }
00059
00060 void ExploreMachine::processEvent(const EventBase& ) {
00061
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
00071
00072
00073
00074
00075
00076
00077
00078
00079
|