Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LoadPostureControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LoadPostureControl_h_
00003 #define INCLUDED_LoadPostureControl_h_
00004 
00005 #include "FileBrowserControl.h"
00006 #include "Motion/PostureMC.h"
00007 #include "Motion/MMAccessor.h"
00008 #include "Motion/EmergencyStopMC.h"
00009 #include "Events/EventRouter.h"
00010 #include "Motion/LedMC.h"
00011 #include "Sound/SoundManager.h"
00012 #include <string>
00013 
00014 //! Upon activation, loads a position from a file name read from cin (stored in ms/data/motion...)
00015 /*! Should switch this to use a MotionSequence so it can move more leisurely and not "snap" to position */
00016 class LoadPostureControl : public FileBrowserControl, public EventListener {
00017  public:
00018   //! Constructor
00019   LoadPostureControl(const std::string& n, MotionManager::MC_ID estop_id)
00020     : FileBrowserControl(n,"Loads a posture from user-selected file",config->portPath(config->motion.root)),
00021       estopid(estop_id), ledid(MotionManager::invalid_MC_ID), file()
00022   {
00023     setFilter("*.pos");
00024   }
00025   
00026   //! destructor
00027   virtual ~LoadPostureControl() {
00028     erouter->removeListener(this);
00029     motman->removeMotion(ledid);
00030   }
00031 
00032   //! only called when e-stop has been turned off and we're waiting to load a file
00033   virtual void processEvent(const EventBase& /*event*/) {
00034     erouter->removeListener(this);
00035     runFile();
00036     motman->removeMotion(ledid);
00037     ledid=MotionManager::invalid_MC_ID;
00038   }
00039 
00040 protected:
00041   //! loads the motion sequence and runs it
00042   void runFile() {
00043     //TimeET timer;
00044     SharedObject< PostureMC > s(file);
00045     //cout << "Load Time: " << timer.Age() << endl;
00046     s->defaultMaxSpeed(.25); //no need to rush this, run at quarter of max speed
00047     motman->addPrunableMotion(s);
00048   }
00049 
00050   //!does the actual loading of the MotionSequence
00051   virtual ControlBase* selectedFile(const std::string& f) {
00052     file=f;
00053     if(!MMAccessor<EmergencyStopMC>(estopid)->getStopped()) {
00054       runFile();
00055     } else {
00056       //we have to wait for the estop to be turned off
00057       sndman->playFile("donkey.wav");
00058       SharedObject<LedMC> led;
00059       led->cset(FaceLEDMask,0);
00060       led->cycle(BotLLEDMask,1000,3,0,0);
00061       led->cycle(BotRLEDMask,1000,3,0,500);
00062       ledid=motman->addPersistentMotion(led);
00063       erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00064     }
00065     return this;
00066   }
00067 
00068   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)
00069   MotionManager::MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00070   std::string file;             //!< last posture file loaded
00071 };
00072 
00073 /*! @file
00074  * @brief Defines LoadPostureControl, which presents a file selection submenu, and then loads the specified posture.
00075  * @author ejt (Creator)
00076  *
00077  * $Author: ejt $
00078  * $Name: tekkotsu-3_0 $
00079  * $Revision: 1.18 $
00080  * $State: Exp $
00081  * $Date: 2006/09/18 18:07:54 $
00082  */
00083 
00084 #endif

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