15-494: Cognitive Robotics, Spring 2009
Richard Ha
How to use
Tekkotsu uses the idiom that every behavior is a state-machine so the code was written such that all one needs to do is declare an instance of a ScytheNode class and instruct it to perform pre-defined actions by calls to a function called addAction.
ScytheNode::addAction(ScytheAction_t action, Point *p, int freq = 1); ScytheNode::addActions(vector |
addAction takes in three arguments, one of which are optional: A ScytheAction_t, a Point *, and an int. The ScytheAction_t is an enum type that describes a pre-defined action, the Point * indicates upon where the action is supposed to take place and the optional int is the number of times (frequency) the action is executed (default value 1). addActions is a wrapper function that just iteratively calls addAction for each element in the supplied vectors.
enum ScytheAction_t {
tapGroundOffset = 0,
pokeOffset,
flickOffset,
swipeOffset,
grabOffset
};
|
The following example is a sample behavior that uses the addAction function to get the Chiara to tap certain points on the ground.
#ifndef GROUNDTAPBEHAVIOR_H
#define GROUNDTAPBEHAVIOR_H
#include "Behaviors/StateMachine.h"
#include "../ScytheNode.h"
class GroundTapBehavior : public StateNode
{
public:
GroundTapBehavior() : StateNode("GroundTapBehavior")
{
}
virtual void setup()
{
startnode = new StateNode("startnode");
addNode(startnode);
ScytheNode *scytheNode = new ScytheNode("Testnode");
addNode(scytheNode);
//We supply the Point values to the ScytheNode for it to operate on later.
Point *tempPoint = new Point (200.0, -150.0, 0.0);
scytheNode->addAction(ScytheNode::tapGroundOffset, tempPoint, 3);
Point *tempPoint2 = new Point (280.0, -150.0, 170.0);
scytheNode->addAction(ScytheNode::pokeOffset, tempPoint2, 7);
//If we change the value of tempPoint2 here, you can change
//where the Chiara will poke when the node is actually activated
//tempPoint2->setCoords(250.0, -130.0, 50.0);
NullTrans *nulltrans1 = new NullTrans("nulltrans1", scytheNode);
startnode->addTransition(nulltrans1);
} // end of setup()
};
#endif
|