Homepage Demos Overview Downloads Tutorials 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 "Motion/LedMC.h"
00009 #include "SoundPlay/SoundManager.h"
00010 #include "Motion/MMAccessor.h"
00011 #include "Shared/TimeET.h"
00012 #include "Shared/Config.h"
00013 #include <string>
00014 
00015 //! Upon activation, loads a position from a file name read from cin (stored in ms/data/motion...)
00016 /*! The template parameter is passed to MotionSequenceMC's template
00017  *  parameter in order to specify the number of keyframes to reserve -
00018  *  larger values use more memory, but will allow you to load more
00019  *  complicated sequences.
00020  *
00021  *  The motion sequence doesn't actually start playing until the
00022  *  emergency stop is deactivated.  This avoids either cutting off the
00023  *  beginning of the sequence while still in estop, or having to
00024  *  override the estop, which may be unexpected.
00025  */
00026 template<unsigned int SequenceSize>
00027 class RunSequenceControl : public FileBrowserControl, public EventListener {
00028 public:
00029   //! Constructor, sets filter to *.mot
00030   RunSequenceControl(const std::string& n, MotionManager::MC_ID estop_id)
00031     : FileBrowserControl(n,"Runs a motion sequence from a user-specified file",config->motion.root), estopid(estop_id), ledid(MotionManager::invalid_MC_ID), waitingFile()
00032   {
00033     setFilter("*.mot");
00034   }
00035 
00036   //! this is to help reduce the twitch at the end (estop tries to go back to its position when this is removed)
00037   virtual void processEvent(const EventBase& event) {
00038     erouter->removeListener(this,event);
00039     runFile();
00040     motman->removeMotion(ledid);
00041   }
00042 
00043 protected:
00044   //! loads the motion sequence and runs it
00045   void runFile() {
00046     //TimeET timer;
00047     SharedObject< MotionSequenceMC<SequenceSize> > s(waitingFile.c_str());
00048     //cout << "Load Time: " << timer.Age() << endl;
00049     motman->addPrunableMotion(s,MotionManager::kEmergencyPriority+1);
00050     waitingFile="";
00051   }
00052 
00053   //!does the actual loading of the MotionSequence
00054   virtual ControlBase* selectedFile(const std::string& f) {
00055     waitingFile=f;
00056     if(!MMAccessor<EmergencyStopMC>(estopid)->getStopped()) {
00057       runFile();
00058     } else {
00059       //we have to wait for the estop to be turned off
00060       sndman->PlayFile("donkey.wav");
00061       SharedObject<LedMC> led;
00062       led->cycle(BotLLEDMask,1000,3,0,0);
00063       led->cycle(BotRLEDMask,1000,3,0,500);
00064       ledid=motman->addPersistentMotion(led);
00065       erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00066     }
00067     return this;
00068   }
00069 
00070   MotionManager::MC_ID estopid; //!< MC_ID of the emergency stop (so we can reset it to the end frame)
00071   MotionManager::MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00072   std::string waitingFile; //!< filename of the motion sequence waiting to load
00073 };
00074 
00075 /*! @file
00076  * @brief Defines RunSequenceControl, which when activated, loads and runs a motion sequence from a file name read from cin (stored in ms/data/motion)
00077  * @author ejt (Creator)
00078  *
00079  * $Author: ejt $
00080  * $Name: tekkotsu-2_2_2 $
00081  * $Revision: 1.14 $
00082  * $State: Exp $
00083  * $Date: 2004/10/18 17:01:38 $
00084  */
00085 
00086 #endif

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0