Homepage Demos Overview Downloads Tutorials Reference
Credits

LedMC.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LedMC_h
00003 #define INCLUDED_LedMC_h
00004 
00005 #include "Events/EventBase.h"
00006 #include "Events/EventRouter.h"
00007 #include "MotionCommand.h"
00008 #include "LedEngine.h"
00009 #include "OutputCmd.h"
00010 #include "MotionManager.h"
00011 
00012 //! This is just a simple wrapper - you probably want to be looking at LedEngine.h
00013 /*! This is handy if all you want to do is control the LED's, but since other
00014  *  MotionCommands will probably also want to make use of the LEDs, they can
00015  *  just use the engine component to do all the work. */
00016 class LedMC : public MotionCommand, public LedEngine {
00017  public:
00018   //! constructor
00019   LedMC() : MotionCommand(), LedEngine(), notified(true) { setWeights(AllLEDMask,1); }
00020   //! destructor
00021   virtual ~LedMC() {}
00022   
00023   //! updates the cmds from LedEngine::updateLEDs()
00024   virtual int updateOutputs() {
00025     updateLEDFrames(cmds);
00026     for(unsigned int i=0; i<NumLEDs; i++)
00027       if(cmds[i][0].weight!=0)
00028   motman->setOutput(this,i+LEDOffset,cmds[i]);
00029     if (nextFlashEnd < (unsigned int)-1)  // do we have a flash in progress?
00030       notified=false;
00031     else if (notified == false) {  // flash has ended (nextFlashEnd == -1), but notice not yet sent
00032       postEvent(EventBase(EventBase::motmanEGID,getID(),EventBase::statusETID));
00033       notified=true;
00034     };
00035     return NumLEDs;
00036   }
00037 
00038   virtual int isDirty() { return LedEngine::isDirty(); }
00039 
00040   virtual int isAlive() { return LedEngine::isDirty() || nextFlashEnd < (unsigned int)-1; }
00041 
00042   //! Sets the JointCmd::weight of the LEDs specified by @a leds to @a weight
00043   void setWeights(LEDBitMask_t leds, float weight) {
00044     for(unsigned int i=0; i<NumLEDs; i++)
00045       if((leds>>i)&1)
00046   for(unsigned int f=0; f<NumFrames; f++)
00047     cmds[i][f].weight=weight;
00048   }
00049 
00050 protected:
00051   OutputCmd cmds[NumLEDs][NumFrames]; //!< needed to store weight values of LEDs (useful to mark LEDs as unused)
00052   bool notified; //!< set to true when we've posted a status event for completion of a flash/cflash
00053 };
00054 
00055 /*!@file
00056  * @brief Defines LedMC, which provides a basic MotionCommand wrapper to LedEngine
00057  * @author ejt (Creator)
00058  *
00059  * $Author: dst $
00060  * $Name: tekkotsu-2_2_1 $
00061  * $Revision: 1.7 $
00062  * $State: Exp $
00063  * $Date: 2004/09/10 22:25:15 $
00064  */
00065 
00066 #endif
00067 
00068 // Another way of doing things (this style for everyone else, look at EmergencyStopMC for instance
00069 // But for the main LedMC, this gets out of sync when i change the engine, so i just use inheritance
00070 /* 
00071 class LedMC : public MotionCommand, public LedEngine {
00072  public:
00073   LedMC() : MotionCommand() {MCInit(); setPriority(kLowPriority); setWeight(~0,1); }
00074   virtual int updateJointCmds() { return engine.updateLEDs(cmds); }
00075   virtual inline const JointCmd& getJointCmd(unsigned int i) { return (i>=LEDOffset && i<LEDOffset+NumLEDs)?cmds[i-LEDOffset]:unusedJoint; }
00076   virtual int isDirty() { return engine.isDirty(); }
00077   virtual int isAlive() { return true; }
00078 
00079   void invert(LEDBitMask_t leds) { engine.invert(leds); }
00080   void cset(LEDBitMask_t leds, float value) { engine.cset(leds,value); }
00081   void set(LEDBitMask_t leds, float value) { engine.set(leds,value); }
00082   void cflash(LEDBitMask_t leds, unsigned int ms=500) { engine.cflash(leds,ms); }
00083   void flash(LEDBitMask_t leds, unsigned int ms=500) { engine.flash(leds,ms); }
00084   void ccycle(LEDBitMask_t leds, unsigned int period, float amp, int offset=0) { engine.ccycle(leds,period,amp,offset); }
00085   void cycle(LEDBitMask_t leds, unsigned int period, float amp, int offset=0) { engine.cycle(leds,period,amp,offset); }
00086   void clear() { engine.clear(); }
00087   void setWeight(LEDBitMask_t leds, float weight) {
00088     for(unsigned int i=0; i<NumLEDs; i++)
00089       if((leds>>i)&1)
00090         cmds[i].weight=weight;
00091   }
00092   
00093   float getSetting(LEDOffset_t led_id) { return engine.getSetting(led_id); }
00094   float getValue(LEDOffset_t led_id) { return engine.getValue(led_id); }
00095 
00096  protected:
00097   static unsigned int crID;
00098   virtual void setClassRegistrationID(unsigned int id) { crID=id; }
00099   virtual unsigned int getClassRegistrationID() const { return crID; }
00100 
00101   LedEngine engine;
00102 
00103   JointCmd cmds[NumLEDs];
00104 };
00105 */

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:38 2004 by Doxygen 1.3.9.1