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 "Motion/LedMC.h"
00009 #include "Sound/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->portPath(config->motion.root)),
00032       estopid(estop_id), ledid(MotionManager::invalid_MC_ID), waitingFile()
00033   {
00034     setFilter("*.mot");
00035   }
00036 
00037   //! destructor
00038   virtual ~RunSequenceControl() {
00039     erouter->removeListener(this);
00040     motman->removeMotion(ledid);
00041   }
00042 
00043   //! only called when e-stop has been turned off and we're waiting to load a file
00044   virtual void processEvent(const EventBase& /*event*/) {
00045     erouter->removeListener(this);
00046     runFile();
00047     motman->removeMotion(ledid);
00048   }
00049   
00050 protected:
00051   //! loads the motion sequence and runs it
00052   void runFile() {
00053     //TimeET timer;
00054     SharedObject< MotionSequenceMC<SequenceSize> > s(waitingFile);
00055     //cout << "Load Time: " << timer.Age() << endl;
00056     motman->addPrunableMotion(s);
00057     waitingFile="";
00058   }
00059 
00060   //!does the actual loading of the MotionSequence
00061   virtual ControlBase* selectedFile(const std::string& f) {
00062     waitingFile=f;
00063     if(!MMAccessor<EmergencyStopMC>(estopid)->getStopped()) {
00064       runFile();
00065     } else {
00066       //we have to wait for the estop to be turned off
00067       sndman->playFile("donkey.wav");
00068       SharedObject<LedMC> led;
00069       led->cset(FaceLEDMask,0);
00070       led->cycle(BotLLEDMask,1000,3,0,0);
00071       led->cycle(BotRLEDMask,1000,3,0,500);
00072       ledid=motman->addPersistentMotion(led);
00073       erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00074     }
00075     return this;
00076   }
00077 
00078   MotionManager::MC_ID estopid; //!< MC_ID of the emergency stop (so we can tell if it's active and wait until it's turned off)
00079   MotionManager::MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00080   std::string waitingFile; //!< filename of the motion sequence waiting to load
00081 };
00082 
00083 /*! @file
00084  * @brief Defines RunSequenceControl, which when activated, loads and runs a motion sequence from a file name read from cin (stored in ms/data/motion)
00085  * @author ejt (Creator)
00086  *
00087  * $Author: ejt $
00088  * $Name: tekkotsu-3_0 $
00089  * $Revision: 1.19 $
00090  * $State: Exp $
00091  * $Date: 2006/09/18 18:07:54 $
00092  */
00093 
00094 #endif

Tekkotsu v3.0
Generated Wed Oct 4 00:03:46 2006 by Doxygen 1.4.7