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 #ifdef TGT_HAS_LEDS
00011 #  include "Motion/LedMC.h"
00012 #endif
00013 #include "Sound/SoundManager.h"
00014 #include <string>
00015 
00016 //! Upon activation, loads a position from a file name read from cin (stored in ms/data/motion...)
00017 /*! Should switch this to use a MotionSequence so it can move more leisurely and not "snap" to position */
00018 class LoadPostureControl : public FileBrowserControl, public EventListener {
00019  public:
00020   //! Constructor
00021   LoadPostureControl(const std::string& n, MotionManager::MC_ID estop_id)
00022     : FileBrowserControl(n,"Loads a posture from user-selected file",config->motion.root),
00023       estopid(estop_id), ledid(MotionManager::invalid_MC_ID), file()
00024   {
00025     setFilter("*.pos");
00026   }
00027   
00028   //! destructor
00029   virtual ~LoadPostureControl() {
00030     erouter->removeListener(this);
00031     motman->removeMotion(ledid);
00032     ledid=MotionManager::invalid_MC_ID;
00033   }
00034 
00035   //! only called when e-stop has been turned off and we're waiting to load a file
00036   virtual void processEvent(const EventBase& /*event*/) {
00037     erouter->removeListener(this);
00038     runFile();
00039     motman->removeMotion(ledid);
00040     ledid=MotionManager::invalid_MC_ID;
00041   }
00042 
00043 protected:
00044   //! loads the motion sequence and runs it
00045   void runFile() {
00046     //TimeET timer;
00047     SharedObject< PostureMC > s(file);
00048     //cout << "Load Time: " << timer.Age() << endl;
00049     s->defaultMaxSpeed(.25); //no need to rush this, run at quarter of max speed
00050     motman->addPrunableMotion(s);
00051   }
00052 
00053   //!does the actual loading of the MotionSequence
00054   virtual ControlBase* selectedFile(const std::string& f) {
00055     file=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 #ifdef TGT_HAS_LEDS
00062       SharedObject<LedMC> led;
00063       led->cset(FaceLEDMask,0);
00064       unsigned int botl = capabilities.findButtonOffset(ERS210Info::buttonNames[ERS210Info::BotLLEDOffset]);
00065       unsigned int botr = capabilities.findButtonOffset(ERS210Info::buttonNames[ERS210Info::BotRLEDOffset]);
00066       if(botl==-1U || botr==-1U) {
00067         botl=LEDOffset;
00068         botr=NumLEDs>1 ? botl+1 : botl;
00069       }
00070       led->cycle(1<<(botl-LEDOffset),1000,3,0,0);
00071       led->cycle(1<<(botr-LEDOffset),1000,3,0,500);
00072       ledid=motman->addPersistentMotion(led);
00073 #endif
00074       erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00075     }
00076     return this;
00077   }
00078 
00079   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)
00080   MotionManager::MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00081   std::string file;             //!< last posture file loaded
00082 };
00083 
00084 /*! @file
00085  * @brief Defines LoadPostureControl, which presents a file selection submenu, and then loads the specified posture.
00086  * @author ejt (Creator)
00087  *
00088  * $Author: ejt $
00089  * $Name: tekkotsu-4_0 $
00090  * $Revision: 1.21 $
00091  * $State: Exp $
00092  * $Date: 2007/08/05 16:16:04 $
00093  */
00094 
00095 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:53 2007 by Doxygen 1.5.4