Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WalkToTargetNode.cc

Go to the documentation of this file.
00001 #include "Motion/WalkMC.h"
00002 #ifdef TGT_HAS_WALK
00003 
00004 #include "WalkToTargetNode.h"
00005 #include "Motion/HeadPointerMC.h"
00006 #include "Shared/RobotInfo.h"
00007 #include "IPC/SharedObject.h"
00008 #include "Motion/MMAccessor.h"
00009 #include "Events/VisionObjectEvent.h"
00010 #include "Shared/WorldState.h"
00011 #include "Behaviors/Transitions/TimeOutTrans.h"
00012 #include "Shared/ERS7Info.h"
00013 #ifdef TGT_HAS_IR_DISTANCE
00014 #  include "Behaviors/Transitions/VisualTargetCloseTrans.h"
00015 #endif
00016 
00017 #if defined(TGT_HAS_CAMERA) && ( defined(TGT_HAS_LEGS) || defined(TGT_HAS_WHEELS) )
00018 #include "Behaviors/Controls/BehaviorSwitchControl.h"
00019 #include "Shared/ProjectInterface.h"
00020 REGISTER_CONTROL_INSTANCE(WalkToTarget,new BehaviorSwitchControlBase(new WalkToTargetNode("Walk To Target (ball)",ProjectInterface::visPinkBallSID)),DEFAULT_TK_MENU"/State Machine Demos");
00021 #endif
00022 
00023 #include "DualCoding/VRmixin.h"
00024 
00025 
00026 void WalkToTargetNode::doStart() {
00027   headpointer_id = motman->addPersistentMotion(SharedObject<HeadPointerMC>());
00028   walker_id = motman->addPersistentMotion(SharedObject<WalkMC>());
00029 
00030   erouter->addListener(this,EventBase::visObjEGID,tracking);
00031   DualCoding::VRmixin::isWalkingFlag = true;
00032 }
00033 
00034 void WalkToTargetNode::doStop() {
00035   erouter->removeListener(this);
00036 
00037   motman->removeMotion(headpointer_id);
00038   headpointer_id=MotionManager::invalid_MC_ID;
00039   motman->removeMotion(walker_id);
00040   walker_id=MotionManager::invalid_MC_ID;
00041 
00042   DualCoding::VRmixin::isWalkingFlag = false;
00043 }
00044 
00045 //this could be cleaned up event-wise (only use a timer when out of view)
00046 void WalkToTargetNode::doEvent() {
00047   static float horiz=0,vert=0;
00048   const VisionObjectEvent *ve = dynamic_cast<const VisionObjectEvent*>(event);
00049   if(ve!=NULL && event->getTypeID()==EventBase::statusETID) {
00050     horiz=ve->getCenterX();
00051     vert=ve->getCenterY();
00052   } else
00053     return;
00054 
00055   // for portability, look to see if the host hardware has a head pan & tilt joints
00056   const unsigned int panIdx = capabilities.findOutputOffset(ERS7Info::outputNames[ERS7Info::HeadOffset+ERS7Info::PanOffset]);
00057   const unsigned int tiltIdx = capabilities.findOutputOffset(ERS7Info::outputNames[ERS7Info::HeadOffset+ERS7Info::TiltOffset]);
00058   if(panIdx==-1U || tiltIdx==-1U)
00059     return; // guess not...
00060   
00061   //cout << "Pos: " << horiz << ' ' << vert << endl;
00062 
00063   float tilt=state->outputs[tiltIdx]-vert*(float)M_PI/6;
00064   float pan=state->outputs[panIdx]-horiz*(float)M_PI/7.5f;
00065   if(tilt>outputRanges[tiltIdx][MaxRange])
00066     tilt=outputRanges[tiltIdx][MaxRange];
00067   if(tilt<outputRanges[tiltIdx][MinRange]*3/4)
00068     tilt=outputRanges[tiltIdx][MinRange]*3/4;
00069   if(pan>outputRanges[panIdx][MaxRange]*2/3)
00070     pan=outputRanges[panIdx][MaxRange]*2/3;
00071   if(pan<outputRanges[panIdx][MinRange]*2/3)
00072     pan=outputRanges[panIdx][MinRange]*2/3;
00073   MMAccessor<HeadPointerMC>(headpointer_id)->setJoints(tilt,pan,0); // note no variable name, one-line scope
00074   
00075   {
00076     MMAccessor<WalkMC> walker(walker_id);
00077     if(pan<-.05 || pan>.05)
00078       walker->setTargetVelocity(100,0,pan);
00079     else
00080       walker->setTargetVelocity(160,0,0);
00081   }
00082 }
00083 
00084 Transition* WalkToTargetNode::newDefaultLostTrans(StateNode* dest) {
00085   return new TimeOutTrans(dest,1500,EventBase::visObjEGID,tracking);
00086 }
00087 
00088 Transition* WalkToTargetNode::newDefaultCloseTrans(StateNode* dest) {
00089 #ifdef TGT_HAS_IR_DISTANCE
00090   return new VisualTargetCloseTrans(dest,tracking);
00091 #else
00092   (void)dest;
00093   return NULL;
00094 #endif
00095 }
00096 
00097 #endif
00098 
00099 /*! @file
00100  * @brief Implements WalkToTargetNode, a state node for walking towards a visual target
00101  * @author ejt (Creator)
00102  */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3