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

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