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