#include "Behaviors/StateMachine.h"
class BarkHowlBlinkBehavior : public StateNode {
public:
BarkHowlBlinkBehavior() : StateNode("BarkHowlBlinkBehavior") {}
virtual void setup() {
std::cout << getName() << " is setting up the state machine." << std::endl;
StateNode *launch = new StateNode("launch");
LedNode *noblink = new LedNode("noblink");
SoundNode *bark_node = new SoundNode("bark","barkmed.wav");
SoundNode *howl_node = new SoundNode("howl","howl.wav");
LedNode *blink_node = new LedNode("blink");
StateNode *wait_node = new StateNode("wait");
addNode(launch); addNode(noblink);
addNode(bark_node); addNode(howl_node); addNode(blink_node); addNode(wait_node);
NullTrans *ntrans = new NullTrans(bark_node);
ntrans->addDestination(noblink);
launch->addTransition(ntrans);
noblink->getMC()->set(RobotInfo::AllLEDMask, 0.0);
noblink->setPriority(MotionManager::kBackgroundPriority);
EventTrans *btrans = new EventTrans(wait_node,
EventBase::buttonEGID,
ChiaraInfo::GreenButOffset,
EventBase::activateETID);
btrans->setSound("ping.wav");
bark_node->addTransition(btrans);
blink_node->getMC()->cycle(RobotInfo::AllLEDMask, 1500, 1.0);
TimeOutTrans *htrans = new TimeOutTrans(howl_node,5000);
htrans->addDestination(blink_node);
bark_node->addTransition(htrans);
CompletionTrans *ctrans = new CompletionTrans(wait_node,1);
howl_node->addTransition(ctrans);
blink_node->addTransition(ctrans);
wait_node->addTransition(new TimeOutTrans(bark_node,15000));
startnode = launch;
}
virtual void doStart() {
std::cout << getName() << " is starting up." << std::endl;
}
virtual void doStop() {
std::cout << getName() << " is shutting down." << std::endl;
}
protected: // Dummy methods to satisfy the compiler
BarkHowlBlinkBehavior(const BarkHowlBlinkBehavior&);
BarkHowlBlinkBehavior& operator=(const BarkHowlBlinkBehavior&);
};
REGISTER_BEHAVIOR(BarkHowlBlinkBehavior);
|