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 #ifdef TGT_HAS_LEDS
00011 # include "Motion/LedMC.h"
00012 #endif
00013 #include "Sound/SoundManager.h"
00014 #include <string>
00015
00016
00017
00018 class LoadPostureControl : public FileBrowserControl, public EventListener {
00019 public:
00020
00021 LoadPostureControl(const std::string& n, MotionManager::MC_ID estop_id)
00022 : FileBrowserControl(n,"Loads a posture from user-selected file",config->motion.root),
00023 estopid(estop_id), ledid(MotionManager::invalid_MC_ID), file()
00024 {
00025 setFilter("*.pos");
00026 }
00027
00028
00029 virtual ~LoadPostureControl() {
00030 erouter->removeListener(this);
00031 motman->removeMotion(ledid);
00032 ledid=MotionManager::invalid_MC_ID;
00033 }
00034
00035
00036 virtual void processEvent(const EventBase& ) {
00037 erouter->removeListener(this);
00038 runFile();
00039 motman->removeMotion(ledid);
00040 ledid=MotionManager::invalid_MC_ID;
00041 }
00042
00043 protected:
00044
00045 void runFile() {
00046
00047 SharedObject< PostureMC > s(file);
00048
00049 s->defaultMaxSpeed(.25);
00050 motman->addPrunableMotion(s);
00051 }
00052
00053
00054 virtual ControlBase* selectedFile(const std::string& f) {
00055 file=f;
00056 if(!MMAccessor<EmergencyStopMC>(estopid)->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.findButtonOffset(ERS210Info::buttonNames[ERS210Info::BotLLEDOffset]);
00065 unsigned int botr = capabilities.findButtonOffset(ERS210Info::buttonNames[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,estopid,EventBase::deactivateETID);
00075 }
00076 return this;
00077 }
00078
00079 MotionManager::MC_ID estopid;
00080 MotionManager::MC_ID ledid;
00081 std::string file;
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #endif