DOC PREVIEW
CMU 15494 Cognitive Robotics - State Machines

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

10/29/08 15-494 Cognitive Robotics 1State Machines15-494 Cognitive RoboticsDavid S. Touretzky &Ethan Tira-ThompsonCarnegie MellonSpring 200810/29/08 15-494 Cognitive Robotics 2Robot Control Architectures●State machines are the simplest and most widely used robot control architecture.●Easy to implement; easy to understand.●Not very powerful:–Action sequences must be laid out in advance, as a series of state nodes.–No dynamic planning.–Failure handling must be programmed explicitly.●But a good place to start.10/29/08 15-494 Cognitive Robotics 3Basic Idea●Robot moves from state to state.●Each state has an associated action: speak, move, etc.●Transitions triggered by sensory events or timers.10/29/08 15-494 Cognitive Robotics 4Extensions●For convenience, we can extend the basic state machine idea to make programming easier.●Extension 1: multi-states.–Several states can be active at once. –Provides for parallel processing.●Extension 2: hierarchical structure.–State machines can nest inside other state machines.–Invocation sort of like a subroutine call.10/29/08 15-494 Cognitive Robotics 5Tekkotsu State Nodes●In Tekkotsu, state machine nodes are behaviors.●StateNode is a child of BehaviorBase.●To enter a state, call its DoStart() method.●To leave a state, call its DoStop() method.●StateNodes can listen for and process events just like any other behavior.10/29/08 15-494 Cognitive Robotics 6Types of State NodesBehaviorBaseStateNodeMCNode<T>MotionSequenceNodeWalkToTargetNodeSoundNodeLedNode WalkEngineNodeTailWagNode10/29/08 15-494 Cognitive Robotics 7Transitions●Transitions in Tekkotsu are also behaviors.–Transition and StateNode are both subclasses of BehaviorBase.●A transition's DoStart() is called whenever its source state node becomes active.●Transitions listen for sensor, timer, or other events, and when their conditions are met, they fire.●When a transition fires, it deactivates its source node(s) and activates its target note(s).10/29/08 15-494 Cognitive Robotics 8Transition TypesRandomTransLostTargetTransSmoothCompareTrans<T>10/29/08 15-494 Cognitive Robotics 9Programs As State MachinesYour program is the parent StateNode:#include “Behaviors/StateNode.h”#include “Behaviors/Nodes/SoundNode.h”#include “Behaviors/Transitions/CompletionTrans.h”#include “Behaviors/Transitions/EventTrans.h”#include “Behaviors/Transitions/TimeOutTrans.h”class DstBehavior : public StateNode {public: DstBehavior() : StateNode("DstBehavior") {}10/29/08 15-494 Cognitive Robotics 10Setup and Teardown●Programs must include a setup() function to construct the state machine as a child of the parent state node.●setup() is called automatically the first time the parent's DoStart() is called.●Each node created by setup() must be registered with the parent using the addNode() method.●Transitions are registered with their source nodes.●A teardown() function is automatically provided to destroy the state machine. Called by ~StateNode().10/29/08 15-494 Cognitive Robotics 11Setup Examplevirtual void setup() { StateNode::setup(); cout << getName() << " setting up the state machine." << endl; SoundNode *bark_node = new SoundNode("bark","barkmed.wav"); SoundNode *howl_node = new SoundNode("howl","howl.wav"); StateNode *wait_node = new StateNode("wait"); addNode(bark_node); addNode(howl_node); addNode(wait_node); EventTrans *btrans = new EventTrans(wait_node, EventBase::buttonEGID, RobotInfo::HeadFrButOffset, EventBase::activateETID); btrans->setSound("ping.wav"); bark_node->addTransition(btrans); bark_node->addTransition(new TimeOutTrans(howl_node,5000)); howl_node->addTransition(new CompletionTrans(wait_node)); wait_node->addTransition(new TimeOutTrans(bark_node,15000)); startnode = bark_node; }10/29/08 15-494 Cognitive Robotics 12Parent's DoStart and DoStop virtual void DoStart() { cout << getName() << " is starting up." << endl; StateNode::DoStart(); } virtual void DoStop() { StateNode::DoStop(); cout << getName() << " is shutting down." << endl; }private: // Dummy functions to satisfy the compiler DstBehavior(const DstBehavior&); DstBehavior& operator=(const DstBehavior&);10/29/08 15-494 Cognitive Robotics 13State Machine Events●Entering or leaving a state generates a stateMachineEGID event.–activateETID for entering–deactivateETID for leaving●Firing of a transition generates a stateTransitionEGID event.●You can use the Tekkotsu Event Logger to monitor these events: Root Control > Status Reports > Event Logger10/29/08 15-494 Cognitive Robotics 14Multi-State Machines10/29/08 15-494 Cognitive Robotics 15Blink Using LedEngine::cycle()●The cycle() motion command never completes.●When the howl completes, we want to leave both the howl state and the blink state.●We can do this by telling CompletionTrans that only one of its source nodes needs to signal a completion in order for the transition to fire.●When it does fire, it will deactivate both source nodes.10/29/08 15-494 Cognitive Robotics 16Setting Up the Blink#include “Behaviors/Nodes/LedNode.h”LedNode *blink_node = new LedNode(“blink”);addNode(blink_node);blink_node->getMC()->cycle(RobotInfo::FaceLEDMask,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);htrans ctrans10/29/08 15-494 Cognitive Robotics 17Cleaning Up the Blink:Turn Face LEDs OffLedNode *noblink = new LedNode(“noblink”);noblink->getMC()->set(RobotInfo::FaceLEDMask, 0.0);noblink->setPriority(MotionManager::kBackgroundPriority);StateNode *launcher = new Statenode(“launcher”);NullTrans *ntrans = new NullTrans(bark_node);ntrans->addDestination(noblink);launcher->addTransition(ntrans);10/29/08 15-494 Cognitive Robotics 18Shorthand Notation●Node definition:nodename: NodeClass(constructor_args)[initializers]●Transition definition: source >==Transition==> targetsourcenode >== transname: TransitionClass(constructor_args)[initializers] ==> targetnode●Multiple sources/targets:source >==Transition==> {targ1name, targ2name, ...}●10/29/08 15-494 Cognitive Robotics 19$ and $$●Use $ to refer to the name of the current node or transition, e.g., these are equivalent:foo: Statenode --- foo: StateNode($) bar: SoundNode($,”howl.wav”)foo:


View Full Document

CMU 15494 Cognitive Robotics - State Machines

Download State Machines
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view State Machines and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view State Machines 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?