LoadPostureControl.h
Go to the documentation of this file.00001 
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 
00017 
00018 class LoadPostureControl : public FileBrowserControl, public EventListener {
00019  public:
00020 
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 
00029   virtual ~LoadPostureControl() {
00030     erouter->removeListener(this);
00031     motman->removeMotion(ledid);
00032     ledid=invalid_MC_ID;
00033   }
00034 
00035 
00036   virtual void processEvent(const EventBase& ) {
00037     erouter->removeListener(this);
00038     runFile();
00039     motman->removeMotion(ledid);
00040     ledid=invalid_MC_ID;
00041   }
00042 
00043 protected:
00044 
00045   void runFile() {
00046     
00047     SharedObject< PostureMC > s(file);
00048     
00049     s->defaultMaxSpeed(.25f); 
00050     motman->addPrunableMotion(s);
00051   }
00052 
00053 
00054   virtual ControlBase* selectedFile(const std::string& f) {
00055     file=f;
00056     if(!ProjectInterface::estop->getStopped()) {
00057       runFile();
00058     } else {
00059       
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; 
00080   std::string file;             
00081 };
00082 
00083 
00084 
00085 
00086 
00087 
00088 #endif