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   virtual ~LoadPostureControl() {
00027     erouter->removeListener(this);
00028     motman->removeMotion(ledid);
00029   }
00030 
00031   //! only called when e-stop has been turned off and we're waiting to load a file
00032   virtual void processEvent(const EventBase& /*event*/) {
00033     erouter->removeListener(this);
00034     runFile();
00035     motman->removeMotion(ledid);
00036     ledid=MotionManager::invalid_MC_ID;
00037   }
00038 
00039 protected:
00040   //! loads the motion sequence and runs it
00041   void runFile() {
00042     //TimeET timer;
00043     SharedObject< PostureMC > s(file);
00044     //cout << "Load Time: " << timer.Age() << endl;
00045     s->defaultMaxSpeed(.25); //no need to rush this, run at quarter of max speed
00046     motman->addPrunableMotion(s);
00047   }
00048 
00049   //!does the actual loading of the MotionSequence
00050   virtual ControlBase* selectedFile(const std::string& f) {
00051     file=f;
00052     if(!MMAccessor<EmergencyStopMC>(estopid)->getStopped()) {
00053       runFile();
00054     } else {
00055       //we have to wait for the estop to be turned off
00056       sndman->PlayFile("donkey.wav");
00057       SharedObject<LedMC> led;
00058       led->cset(FaceLEDMask,0);
00059       led->cycle(BotLLEDMask,1000,3,0,0);
00060       led->cycle(BotRLEDMask,1000,3,0,500);
00061       ledid=motman->addPersistentMotion(led);
00062       erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00063     }
00064     return this;
00065   }
00066 
00067   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)
00068   MotionManager::MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00069   std::string file;             //!< last posture file loaded
00070 };
00071 
00072 /*! @file
00073  * @brief Defines LoadPostureControl, which presents a file selection submenu, and then loads the specified posture.
00074  * @author ejt (Creator)
00075  *
00076  * $Author: ejt $
00077  * $Name: tekkotsu-2_4_1 $
00078  * $Revision: 1.16 $
00079  * $State: Exp $
00080  * $Date: 2005/06/06 23:05:51 $
00081  */
00082 
00083 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:47 2005 by Doxygen 1.4.4