Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

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

Tekkotsu v1.4
Generated Sat Jul 19 00:06:30 2003 by Doxygen 1.3.2