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