Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RunSequenceControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_RunSequenceControl_h_
00003 #define INCLUDED_RunSequenceControl_h_
00004 
00005 #include "FileBrowserControl.h"
00006 #include "Motion/MotionSequenceMC.h"
00007 #include "Motion/EmergencyStopMC.h"
00008 #include "Shared/RobotInfo.h"
00009 #ifdef TGT_HAS_LEDS
00010 #  include "Shared/ERS210Info.h"
00011 #  include "Motion/LedMC.h"
00012 #endif
00013 #include "Events/EventRouter.h"
00014 #include "Sound/SoundManager.h"
00015 #include "Shared/TimeET.h"
00016 #include "Shared/Config.h"
00017 #include "Shared/ProjectInterface.h"
00018 #include <string>
00019 
00020 //! Upon activation, loads a position from a file name read from cin (stored in ms/data/motion...)
00021 /*! The template parameter is passed to MotionSequenceMC's template
00022  *  parameter in order to specify the number of keyframes to reserve -
00023  *  larger values use more memory, but will allow you to load more
00024  *  complicated sequences.
00025  *
00026  *  The motion sequence doesn't actually start playing until the
00027  *  emergency stop is deactivated.  This avoids either cutting off the
00028  *  beginning of the sequence while still in estop, or having to
00029  *  override the estop, which may be unexpected.
00030  */
00031 template<unsigned int SequenceSize>
00032 class RunSequenceControl : public FileBrowserControl, public EventListener {
00033 public:
00034   //! Constructor, sets filter to *.mot
00035   RunSequenceControl(const std::string& n)
00036     : FileBrowserControl(n,"Runs a motion sequence from a user-specified file",config->motion.root),
00037       ledid(invalid_MC_ID), waitingFile()
00038   {
00039     setFilter("*.mot");
00040   }
00041 
00042   //! destructor
00043   virtual ~RunSequenceControl() {
00044     erouter->removeListener(this);
00045     motman->removeMotion(ledid);
00046     ledid=invalid_MC_ID;
00047   }
00048 
00049   //! only called when e-stop has been turned off and we're waiting to load a file
00050   virtual void processEvent(const EventBase& /*event*/) {
00051     erouter->removeListener(this);
00052     runFile();
00053     motman->removeMotion(ledid);
00054     ledid=invalid_MC_ID;
00055   }
00056   
00057 protected:
00058   //! loads the motion sequence and runs it
00059   void runFile() {
00060     //TimeET timer;
00061     SharedObject< MotionSequenceMC<SequenceSize> > s(waitingFile);
00062     //cout << "Load Time: " << timer.Age() << endl;
00063     motman->addPrunableMotion(s);
00064     waitingFile="";
00065   }
00066 
00067   //!does the actual loading of the MotionSequence
00068   virtual ControlBase* selectedFile(const std::string& f) {
00069     waitingFile=f;
00070     if(!ProjectInterface::estop->getStopped()) {
00071       runFile();
00072     } else {
00073       //we have to wait for the estop to be turned off
00074       sndman->playFile("donkey.wav");
00075 #ifdef TGT_HAS_LEDS
00076       SharedObject<LedMC> led;
00077       led->cset(FaceLEDMask,0);
00078       unsigned int botl = capabilities.findOutputOffset(ERS210Info::outputNames[ERS210Info::BotLLEDOffset]);
00079       unsigned int botr = capabilities.findOutputOffset(ERS210Info::outputNames[ERS210Info::BotRLEDOffset]);
00080       if(botl==-1U || botr==-1U) {
00081         botl=LEDOffset;
00082         botr=NumLEDs>1 ? botl+1 : botl;
00083       }
00084       led->cycle(1<<(botl-LEDOffset),1000,3,0,0);
00085       led->cycle(1<<(botr-LEDOffset),1000,3,0,500);
00086       ledid=motman->addPersistentMotion(led);
00087 #endif
00088       erouter->addListener(this,EventBase::estopEGID,ProjectInterface::estop.getID(),EventBase::deactivateETID);
00089     }
00090     return this;
00091   }
00092 
00093   MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00094   std::string waitingFile; //!< filename of the motion sequence waiting to load
00095 };
00096 
00097 /*! @file
00098  * @brief Defines RunSequenceControl, which when activated, loads and runs a motion sequence from a file name read from cin (stored in ms/data/motion)
00099  * @author ejt (Creator)
00100  */
00101 
00102 #endif

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