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