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/EmergencyStopMC.h"
00008 #include "Events/EventRouter.h"
00009 #ifdef TGT_HAS_LEDS
00010 #  include "Motion/LedMC.h"
00011 #endif
00012 #include "Sound/SoundManager.h"
00013 #include "Shared/ProjectInterface.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)
00022     : FileBrowserControl(n,"Loads a posture from user-selected file",config->motion.root),
00023       ledid(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=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=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(.25f); //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(!ProjectInterface::estop->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.findOutputOffset(ERS210Info::outputNames[ERS210Info::BotLLEDOffset]);
00065       unsigned int botr = capabilities.findOutputOffset(ERS210Info::outputNames[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,ProjectInterface::estop.getID(),EventBase::deactivateETID);
00075     }
00076     return this;
00077   }
00078 
00079   MC_ID ledid; //!< MC_ID of the led we use to signal there's a MotionSequence lined up
00080   std::string file;             //!< last posture file loaded
00081 };
00082 
00083 /*! @file
00084  * @brief Defines LoadPostureControl, which presents a file selection submenu, and then loads the specified posture.
00085  * @author ejt (Creator)
00086  */
00087 
00088 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3