RunSequenceControl.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_RunSequenceControl_h_
00003 #define INCLUDED_RunSequenceControl_h_
00004
00005 #include "FileBrowserControl.h"
00006 #include "Motion/MotionSequenceMC.h"
00007 #include "Motion/EmergencyStopMC.h"
00008 #include "Shared/RobotInfo.h"
00009 #ifdef TGT_HAS_LEDS
00010 # include "Shared/ERS210Info.h"
00011 # include "Motion/LedMC.h"
00012 #endif
00013 #include "Events/EventRouter.h"
00014 #include "Sound/SoundManager.h"
00015 #include "Shared/TimeET.h"
00016 #include "Shared/Config.h"
00017 #include "Shared/ProjectInterface.h"
00018 #include <string>
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 template<unsigned int SequenceSize>
00032 class RunSequenceControl : public FileBrowserControl, public EventListener {
00033 public:
00034
00035 RunSequenceControl(const std::string& n)
00036 : FileBrowserControl(n,"Runs a motion sequence from a user-specified file",config->motion.root),
00037 ledid(invalid_MC_ID), waitingFile()
00038 {
00039 setFilter("*.mot");
00040 }
00041
00042
00043 virtual ~RunSequenceControl() {
00044 erouter->removeListener(this);
00045 motman->removeMotion(ledid);
00046 ledid=invalid_MC_ID;
00047 }
00048
00049
00050 virtual void processEvent(const EventBase& ) {
00051 erouter->removeListener(this);
00052 runFile();
00053 motman->removeMotion(ledid);
00054 ledid=invalid_MC_ID;
00055 }
00056
00057 protected:
00058
00059 void runFile() {
00060
00061 SharedObject< MotionSequenceMC<SequenceSize> > s(waitingFile);
00062
00063 motman->addPrunableMotion(s);
00064 waitingFile="";
00065 }
00066
00067
00068 virtual ControlBase* selectedFile(const std::string& f) {
00069 waitingFile=f;
00070 if(!ProjectInterface::estop->getStopped()) {
00071 runFile();
00072 } else {
00073
00074 sndman->playFile("donkey.wav");
00075 #ifdef TGT_HAS_LEDS
00076 SharedObject<LedMC> led;
00077 led->cset(FaceLEDMask,0);
00078 unsigned int botl = capabilities.findOutputOffset(ERS210Info::outputNames[ERS210Info::BotLLEDOffset]);
00079 unsigned int botr = capabilities.findOutputOffset(ERS210Info::outputNames[ERS210Info::BotRLEDOffset]);
00080 if(botl==-1U || botr==-1U) {
00081 botl=LEDOffset;
00082 botr=NumLEDs>1 ? botl+1 : botl;
00083 }
00084 led->cycle(1<<(botl-LEDOffset),1000,3,0,0);
00085 led->cycle(1<<(botr-LEDOffset),1000,3,0,500);
00086 ledid=motman->addPersistentMotion(led);
00087 #endif
00088 erouter->addListener(this,EventBase::estopEGID,ProjectInterface::estop.getID(),EventBase::deactivateETID);
00089 }
00090 return this;
00091 }
00092
00093 MC_ID ledid;
00094 std::string waitingFile;
00095 };
00096
00097
00098
00099
00100
00101
00102 #endif