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 "Motion/LedMC.h"
00009 #include "Sound/SoundManager.h"
00010 #include "Motion/MMAccessor.h"
00011 #include "Shared/TimeET.h"
00012 #include "Shared/Config.h"
00013 #include <string>
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 template<unsigned int SequenceSize>
00027 class RunSequenceControl : public FileBrowserControl, public EventListener {
00028 public:
00029
00030 RunSequenceControl(const std::string& n, MotionManager::MC_ID estop_id)
00031 : FileBrowserControl(n,"Runs a motion sequence from a user-specified file",config->portPath(config->motion.root)),
00032 estopid(estop_id), ledid(MotionManager::invalid_MC_ID), waitingFile()
00033 {
00034 setFilter("*.mot");
00035 }
00036
00037 virtual ~RunSequenceControl() {
00038 erouter->removeListener(this);
00039 motman->removeMotion(ledid);
00040 }
00041
00042
00043 virtual void processEvent(const EventBase& ) {
00044 erouter->removeListener(this);
00045 runFile();
00046 motman->removeMotion(ledid);
00047 }
00048
00049 protected:
00050
00051 void runFile() {
00052
00053 SharedObject< MotionSequenceMC<SequenceSize> > s(waitingFile);
00054
00055 motman->addPrunableMotion(s);
00056 waitingFile="";
00057 }
00058
00059
00060 virtual ControlBase* selectedFile(const std::string& f) {
00061 waitingFile=f;
00062 if(!MMAccessor<EmergencyStopMC>(estopid)->getStopped()) {
00063 runFile();
00064 } else {
00065
00066 sndman->PlayFile("donkey.wav");
00067 SharedObject<LedMC> led;
00068 led->cset(FaceLEDMask,0);
00069 led->cycle(BotLLEDMask,1000,3,0,0);
00070 led->cycle(BotRLEDMask,1000,3,0,500);
00071 ledid=motman->addPersistentMotion(led);
00072 erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00073 }
00074 return this;
00075 }
00076
00077 MotionManager::MC_ID estopid;
00078 MotionManager::MC_ID ledid;
00079 std::string waitingFile;
00080 };
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #endif