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
00027 virtual ~LoadPostureControl() {
00028 erouter->removeListener(this);
00029 motman->removeMotion(ledid);
00030 }
00031
00032
00033 virtual void processEvent(const EventBase& ) {
00034 erouter->removeListener(this);
00035 runFile();
00036 motman->removeMotion(ledid);
00037 ledid=MotionManager::invalid_MC_ID;
00038 }
00039
00040 protected:
00041
00042 void runFile() {
00043
00044 SharedObject< PostureMC > s(file);
00045
00046 s->defaultMaxSpeed(.25);
00047 motman->addPrunableMotion(s);
00048 }
00049
00050
00051 virtual ControlBase* selectedFile(const std::string& f) {
00052 file=f;
00053 if(!MMAccessor<EmergencyStopMC>(estopid)->getStopped()) {
00054 runFile();
00055 } else {
00056
00057 sndman->playFile("donkey.wav");
00058 SharedObject<LedMC> led;
00059 led->cset(FaceLEDMask,0);
00060 led->cycle(BotLLEDMask,1000,3,0,0);
00061 led->cycle(BotRLEDMask,1000,3,0,500);
00062 ledid=motman->addPersistentMotion(led);
00063 erouter->addListener(this,EventBase::estopEGID,estopid,EventBase::deactivateETID);
00064 }
00065 return this;
00066 }
00067
00068 MotionManager::MC_ID estopid;
00069 MotionManager::MC_ID ledid;
00070 std::string file;
00071 };
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #endif