Homepage Demos Overview Downloads Tutorials Reference
Credits

LoadPostureControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
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 <string>
00011 
00012 //! Upon activation, loads a position from a file name read from cin (stored in ms/data/motion...)
00013 /*! Should switch this to use a MotionSequence so it can move more leisurely and not "snap" to position */
00014 class LoadPostureControl : public FileBrowserControl, public EventListener {
00015  public:
00016   //! Constructor
00017   LoadPostureControl(const std::string& n, MotionManager::MC_ID estop_id)
00018     : FileBrowserControl(n,"Loads a posture from user-selected file",config->motion.root), estopid(estop_id), file()
00019   {
00020     setFilter("*.pos");
00021   }
00022   //! Destructor
00023   virtual ~LoadPostureControl() {}
00024   
00025   //! this is to help reduce the twitch at the end (estop tries to go back to its position when this is removed)
00026   virtual void processEvent(const EventBase& event) {
00027     // it still twitches some because there's a bit of lag before we get the
00028     // event, and estop is already trying to move it back
00029     erouter->removeListener(this,event);
00030     MMAccessor<EmergencyStopMC> estop(estopid);
00031     // why don't we just tell estop to load the file in the first place?
00032     // estop senses forces on the joints - the force of snapping the joint
00033     // into position will cause it to reset and not make it into position
00034     estop->LoadFile(file.c_str());
00035     estop->setActive(true);
00036   }
00037   
00038   virtual void deactivate() {
00039     erouter->removeListener(this);
00040   }
00041 
00042 protected:
00043   //!does the actual loading of the MotionSequence
00044   virtual ControlBase* selectedFile(const std::string& f) {
00045     file=f;
00046     SharedObject<PostureMC> post;
00047     post->LoadFile(file.c_str());
00048     MMAccessor<EmergencyStopMC>(estopid)->setActive(false);
00049     MotionManager::MC_ID id=motman->addPrunableMotion(post,MotionManager::kEmergencyPriority+1);
00050     erouter->addListener(this,EventBase::motmanEGID,id,EventBase::deactivateETID);
00051     return this;
00052   }
00053 
00054   MotionManager::MC_ID estopid; //!< MC_ID of the e-stop
00055   std::string file;             //!< last posture file loaded
00056 };
00057 
00058 /*! @file
00059  * @brief Defines LoadPostureControl, which when activated, loads a position from a file name read from cin (stored in ms/data/motion...)
00060  * @author ejt (Creator)
00061  *
00062  * $Author: ejt $
00063  * $Name: tekkotsu-2_2 $
00064  * $Revision: 1.13 $
00065  * $State: Exp $
00066  * $Date: 2004/10/17 01:16:10 $
00067  */
00068 
00069 #endif

Tekkotsu v2.2
Generated Tue Oct 19 14:19:14 2004 by Doxygen 1.3.9.1