Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WalkNode.cc

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #include "Motion/WalkMC.h"
00003 #ifdef TGT_HAS_WALK
00004 
00005 #include "Behaviors/Nodes/WalkNode.h"
00006 #include "Shared/MarkScope.h"
00007 
00008 bool WalkRequest::operator==(const WalkRequest& other) const {
00009   return ( x == other.x && y == other.y && a == other.a
00010       && time == other.time && velocityMode == other.velocityMode
00011       && filename == other.filename);
00012 }
00013 
00014 std::ostream& operator<<(std::ostream &os, const WalkRequest &req) {
00015   os << "WalkRequest[x=" << req.x << ", y=" << req.y << ", a=" << req.a
00016      << ", time=" << req.time 
00017      << ", velocityMode=" << (req.velocityMode ? "true" : "false") 
00018      << ", storedVelocities=" << (req.storedVelocities ? "true" : "false") 
00019      << "]" << std::endl;
00020   return os;
00021 }
00022 
00023 void WalkNode::preStart() {
00024   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>::preStart();
00025   if ( const DataEvent<WalkRequest> *ev = dynamic_cast<const DataEvent<WalkRequest>*>(event) )
00026     req = ev->getData();
00027   if ( !req.filename.empty() )
00028     getMC()->loadFile(req.filename.c_str());
00029   // Must call the parent start() method first, because that
00030   // will call our doStart(), which may lead to user code
00031   // changing the displacement or velocity values; we'll check
00032   // for those changes afterwards.
00033 }
00034 
00035 void WalkNode::postStart() {
00036   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>::postStart();
00037   // std::cout << "req = " << req << std::endl;
00038   if ( req.storedVelocities ) {
00039     if ( !req.velocityMode ) {
00040       getMC()->setTargetDisplacement(req.x, req.y, req.a, req.time);
00041     } else if ( req.time<0 ) {
00042       getMC()->setTargetVelocity(req.x, req.y, req.a);
00043     } else {
00044       getMC()->setTargetVelocity(req.x, req.y, req.a, req.time);
00045     }
00046   }
00047 }
00048 
00049 void WalkNode::stop() {
00050   getMC()->zeroVelocities();
00051   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>::stop();
00052 }
00053 
00054 void WalkNode::setDisplacement(float xdist, float ydist, float adist, float time/*=0*/) {
00055   req = WalkRequest(xdist,ydist,adist,time,false,req.filename);
00056   if(isActive())
00057     getMC()->setTargetDisplacement(req.x, req.y, req.a, req.time);
00058 }
00059 
00060 void WalkNode::setVelocity(float xvel, float yvel, float avel) {
00061   req = WalkRequest(xvel,yvel,avel,req.filename);
00062   if(isActive())
00063     getMC()->setTargetVelocity(req.x, req.y, req.a);
00064 }
00065 
00066 void WalkNode::setVelocity(float xvel, float yvel, float avel, float time) {
00067   req = WalkRequest(xvel,yvel,avel,time,true,req.filename);
00068   if(isActive())
00069     getMC()->setTargetVelocity(req.x, req.y, req.a, req.time);
00070 }
00071 
00072 #endif

Tekkotsu v5.1CVS
Generated Fri Mar 16 05:26:54 2012 by Doxygen 1.6.3