Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PaceTargetsMachine.cc

Go to the documentation of this file.
00001 #include "PaceTargetsMachine.h"
00002 #include "Behaviors/Transition.h"
00003 #include "Behaviors/Nodes/WalkToTargetNode.h"
00004 #include "Behaviors/Nodes/WalkNode.h"
00005 #include "ExploreMachine.h"
00006 #include "Behaviors/Transitions/TimeOutTrans.h"
00007 #include "Behaviors/Transitions/VisualTargetTrans.h"
00008 #include "Behaviors/Nodes/OutputNode.h"
00009 #include "Behaviors/Nodes/MotionSequenceNode.h"
00010 #include "Behaviors/Nodes/GroupNode.h"
00011 #include "Sound/SoundManager.h"
00012 
00013 void PaceTargetsMachine::setup() {
00014   StateNode::setup();
00015 
00016   const float turnAroundSpeed=1; //1 rad/sec
00017   //explore and chase have their own built-in speeds
00018 
00019   //*****  NODE SETUP *****//
00020 
00021   //turns in place
00022   WalkNode * turnAround = new WalkNode(0,0,turnAroundSpeed);
00023   turnAround->setName(getName()+"::TurnAround");
00024   addNode(turnAround);
00025 
00026   //two nodes running together -- explore will wander around, panhead will look around
00027   GroupNode * explGrp = new GroupNode(getName()+"::ExplGroup");
00028   addNode(explGrp);
00029   {
00030     ExploreMachine * explore = new ExploreMachine(explGrp->getName()+"::Explore");
00031     explGrp->addNode(explore);
00032     SmallMotionSequenceNode * panhead = new SmallMotionSequenceNode(explGrp->getName()+"::PanHead","pan_head.mot",true);
00033     explGrp->addNode(panhead);
00034   }
00035 
00036   //follow the ball
00037   WalkToTargetNode * chase = new WalkToTargetNode(ProjectInterface::visPinkBallSID);
00038   chase->setName(getName()+"::Chase");
00039   addNode(chase);
00040 
00041 
00042   //*****  TRANSITION SETUP *****//
00043 
00044   Transition * tmptrans=NULL;
00045 
00046   //if it sees pink, chase it
00047   explGrp->addTransition(tmptrans=new VisualTargetTrans(chase,ProjectInterface::visPinkBallSID));
00048   tmptrans->setSound("cutey.wav");
00049 
00050   //if you lose it, explore some more
00051   chase->addTransition(tmptrans=chase->newDefaultLostTrans(explGrp));
00052   tmptrans->setSound("whimper.wav");
00053   
00054   //if you get there, turn around
00055   chase->addTransition(tmptrans=chase->newDefaultCloseTrans(turnAround));
00056   tmptrans->setSound("fart.wav");
00057   
00058   //once you've turned around, explore
00059   turnAround->addTransition(tmptrans=new TimeOutTrans(explGrp,(unsigned int)(M_PI/turnAroundSpeed*1000))); //turn 180 degrees (aka PI radians)
00060   tmptrans->setSound("barkmed.wav");
00061   
00062   //preload the sounds so we don't pause on tranisitions
00063   sndman->LoadFile("cutey.wav");
00064   sndman->LoadFile("barkmed.wav");
00065   sndman->LoadFile("whimper.wav");
00066   sndman->LoadFile("fart.wav");
00067 
00068   //starts out exploring
00069   start=explGrp;
00070 }
00071 
00072 void PaceTargetsMachine::DoStart() {
00073   StateNode::DoStart();
00074   start->DoStart();
00075 }
00076 
00077 void PaceTargetsMachine::teardown() {
00078   //release the sounds
00079   sndman->ReleaseFile("cutey.wav");
00080   sndman->ReleaseFile("barkmed.wav");
00081   sndman->ReleaseFile("whimper.wav");
00082   sndman->ReleaseFile("fart.wav");
00083   StateNode::teardown();
00084 }
00085 
00086 /*! @file
00087  * @brief Implements PaceTargetsMachine, a StateMachine for walking back and forth between two visual targets
00088  * @author ejt (Creator)
00089  *
00090  * $Author: ejt $
00091  * $Name: tekkotsu-2_4_1 $
00092  * $Revision: 1.18 $
00093  * $State: Exp $
00094  * $Date: 2005/08/03 19:11:58 $
00095  */
00096 

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:48 2005 by Doxygen 1.4.4