Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LedNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LedNode_h_
00003 #define INCLUDED_LedNode_h_
00004 
00005 #include "MCNode.h"
00006 #include "Motion/LedMC.h"
00007 
00008 //! StateNode that executes a LedMC motion command and posts a status event upon completion
00009 /*! Extends MCNode slightly so that each time the LedMC is accessed, any flash commands are reset.
00010  *  This allows a flash to be triggered each time the node starts */
00011 class LedNode : public MCNode<LedMC> {
00012 public:
00013   //! default constructor, use type name as instance name
00014   LedNode() : MCNode<LedMC>(), lastAccess(0) {}
00015   
00016   //! constructor, take an instance name
00017   LedNode(const std::string& nm) : MCNode<LedMC>(nm), lastAccess(0) {}
00018   
00019   static std::string getClassDescription() { return "Displays a pattern on the LEDs for as long as the state is active"; }
00020   virtual std::string getDescription() const { return getClassDescription(); }
00021   
00022 protected:
00023   //! extends MCNode implementation so that each time the LedMC is accessed, any flash commands are reset.
00024   virtual SharedObject<LedMC>& getPrivateMC() {
00025     unsigned int curtime=get_time();
00026     bool isFirstCreation=(mc==NULL);
00027     SharedObject<LedMC>& lobj=MCNode<LedMC>::getPrivateMC();
00028     if(!isFirstCreation)
00029       lobj->extendFlash(curtime-lastAccess);
00030     lastAccess=curtime;
00031     return lobj;
00032   }
00033   
00034   unsigned int lastAccess; //!< stores time of last call to getPrivateMC() for resetting flash commands
00035 };
00036 
00037 //! Simpler version of LedNode that turns on the specified LEDs on entry and explicitly turns them off again on exit.
00038 class LedActivate : public LedNode {
00039 public:
00040   //! constructor
00041   LedActivate(const std::string &nm, LEDBitMask_t mask) : LedNode(nm), theMask(mask) {
00042     SharedObject<LedMC>& lobj=getPrivateMC();
00043     lobj->setWeights(AllLEDMask,0);
00044     lobj->setWeights(theMask, 1);
00045     lobj->set(theMask, 1);
00046 }
00047 
00048   virtual void stop() { // explicitly turn off the LEDs we turned on before
00049     LedNode::stop();
00050     SharedObject<LedMC> douser;
00051     douser->setWeights(AllLEDMask,0);
00052     douser->setWeights(theMask, 1);
00053     douser->set(theMask, 0);
00054     motman->addPrunableMotion(douser);
00055   }
00056 
00057 protected:
00058   LEDBitMask_t theMask;
00059 };
00060 
00061 
00062 
00063 /*! @file
00064  * @brief Defines LedNode and LedActivate, StateNodes that run a LedMC motion command and post a status event upon completion
00065  * @author dst (Creator)
00066  */
00067 
00068 #endif

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