Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
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
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   virtual void DoStart() {
00024     MotionCommand::DoStart();
00025     dirty=true;
00026   }
00027 
00028   //! updates the cmds from LedEngine::updateLEDs()
00029   virtual int updateOutputs() {
00030     updateLEDFrames(cmds);
00031 #ifdef TGT_HAS_LEDS
00032     for(unsigned int i=0; i<NumLEDs; i++)
00033       if(cmds[i][0].weight!=0)
00034         motman->setOutput(this,i+LEDOffset,cmds[i]);
00035 #endif
00036     if (nextFlashEnd < (unsigned int)-1)  // do we have a flash in progress?
00037       notified=false;
00038     else if (notified == false) {  // flash has ended (nextFlashEnd == -1), but notice not yet sent
00039       postEvent(EventBase(EventBase::motmanEGID,getID(),EventBase::statusETID));
00040       notified=true;
00041     };
00042     return NumLEDs;
00043   }
00044 
00045   virtual int isDirty() { return LedEngine::isDirty(); }
00046 
00047   virtual int isAlive() { return LedEngine::isDirty() || nextFlashEnd < (unsigned int)-1; }
00048 
00049   //! Sets the JointCmd::weight of the LEDs specified by @a leds to @a weight
00050   void setWeights(LEDBitMask_t leds, float weight) {
00051 #ifndef TGT_HAS_LEDS
00052     (void)leds; (void)weight; // avoid unused argument warnings
00053 #else
00054     for(unsigned int i=0; i<NumLEDs; i++)
00055       if((leds>>i)&1)
00056   for(unsigned int f=0; f<NumFrames; f++)
00057     cmds[i][f].weight=weight;
00058 #endif
00059   }
00060 
00061 protected:
00062   OutputCmd cmds[NumLEDs][NumFrames]; //!< needed to store weight values of LEDs (useful to mark LEDs as unused)
00063   bool notified; //!< set to true when we've posted a status event for completion of a flash/cflash
00064 };
00065 
00066 /*!@file
00067  * @brief Defines LedMC, which provides a basic MotionCommand wrapper to LedEngine
00068  * @author ejt (Creator)
00069  *
00070  * $Author: ejt $
00071  * $Name: tekkotsu-4_0 $
00072  * $Revision: 1.10 $
00073  * $State: Exp $
00074  * $Date: 2007/11/18 06:47:03 $
00075  */
00076 
00077 #endif
00078 
00079 // Another way of doing things (this style for everyone else, look at EmergencyStopMC for instance
00080 // But for the main LedMC, this gets out of sync when i change the engine, so i just use inheritance
00081 /* 
00082 class LedMC : public MotionCommand, public LedEngine {
00083  public:
00084   LedMC() : MotionCommand() {MCInit(); setPriority(kLowPriority); setWeight(~0,1); }
00085   virtual int updateJointCmds() { return engine.updateLEDs(cmds); }
00086   virtual inline const JointCmd& getJointCmd(unsigned int i) { return (i>=LEDOffset && i<LEDOffset+NumLEDs)?cmds[i-LEDOffset]:unusedJoint; }
00087   virtual int isDirty() { return engine.isDirty(); }
00088   virtual int isAlive() { return true; }
00089 
00090   void invert(LEDBitMask_t leds) { engine.invert(leds); }
00091   void cset(LEDBitMask_t leds, float value) { engine.cset(leds,value); }
00092   void set(LEDBitMask_t leds, float value) { engine.set(leds,value); }
00093   void cflash(LEDBitMask_t leds, unsigned int ms=500) { engine.cflash(leds,ms); }
00094   void flash(LEDBitMask_t leds, unsigned int ms=500) { engine.flash(leds,ms); }
00095   void ccycle(LEDBitMask_t leds, unsigned int period, float amp, int offset=0) { engine.ccycle(leds,period,amp,offset); }
00096   void cycle(LEDBitMask_t leds, unsigned int period, float amp, int offset=0) { engine.cycle(leds,period,amp,offset); }
00097   void clear() { engine.clear(); }
00098   void setWeight(LEDBitMask_t leds, float weight) {
00099     for(unsigned int i=0; i<NumLEDs; i++)
00100       if((leds>>i)&1)
00101         cmds[i].weight=weight;
00102   }
00103   
00104   float getSetting(LEDOffset_t led_id) { return engine.getSetting(led_id); }
00105   float getValue(LEDOffset_t led_id) { return engine.getValue(led_id); }
00106 
00107  protected:
00108   static unsigned int crID;
00109   virtual void setClassRegistrationID(unsigned int id) { crID=id; }
00110   virtual unsigned int getClassRegistrationID() const { return crID; }
00111 
00112   LedEngine engine;
00113 
00114   JointCmd cmds[NumLEDs];
00115 };
00116 */

Tekkotsu v4.0
Generated Thu Nov 22 00:54:53 2007 by Doxygen 1.5.4