Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

TorqueCalibrate.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_TorqueCalibrate_h
00003 #define INCLUDED_TorqueCalibrate_h
00004 
00005 #include "Behaviors/Controls/ControlBase.h"
00006 #include "Behaviors/Controls/FileInputControl.h"
00007 #include "Motion/MotionManager.h"
00008 #include "Events/EventListener.h"
00009 
00010 //! Provides an interface for making measurements to correlate PID duty cycle and actual force output for each of the motors
00011 class TorqueCalibrate : public ControlBase {
00012 
00013   // **************************** //
00014   // ******* CONSTRUCTORS ******* //
00015   // **************************** //
00016   // Not all of these necessarily make sense to implement... feel free
00017   // to remove those which don't -- none are required.
00018 
00019 public:
00020   //! default constructor
00021   TorqueCalibrate()
00022     : ControlBase("TorqueCalibrate","Provides an interface for making measurements to correlate PID duty cycle and actual force output for each of the motors"),
00023     filename(config->portPath("data/torque.dat")), filenameInput(NULL)
00024   {init();}
00025   //! constructor which allows a custom name
00026   TorqueCalibrate(const std::string& n)
00027     : ControlBase(n,"Provides an interface for making measurements to correlate PID duty cycle and actual force output for each of the motors"),
00028     filename(config->portPath("data/torque.dat")), filenameInput(NULL)
00029   {init();}
00030   //! constructor which allows a custom name and tooltip
00031   TorqueCalibrate(const std::string& n, const std::string& d)
00032     : ControlBase(n,d),
00033     filename(config->portPath("data/torque.dat")), filenameInput(NULL)
00034   {init();}
00035 
00036   //! destructor
00037   virtual ~TorqueCalibrate() {}
00038 
00039 protected:
00040   class TakeMeasurementControl : public ControlBase, public EventListener  {
00041   public:
00042     TakeMeasurementControl(const TorqueCalibrate& tcParent, unsigned int jointToMeasure)
00043       : ControlBase(outputNames[jointToMeasure]), parent(tcParent), joint(jointToMeasure),
00044       basePosition(state->outputs[jointToMeasure]), maxDuty(0), sensorDist(0), cstate(ZERO_JOINT),
00045       pidID(MotionManager::invalid_MC_ID), pulseID(MotionManager::invalid_MC_ID)
00046     {}
00047     virtual ControlBase * activate(MotionManager::MC_ID disp_id, Socket * gui);
00048     virtual void processEvent(const EventBase& event);
00049     virtual void refresh();
00050     virtual ControlBase * takeInput(const std::string& msg);
00051     virtual void deactivate();
00052   protected:
00053     //! the states the TakeMeasurementControl goes through when recording measurements
00054     enum State_t {
00055       ZERO_JOINT,  //!< turn off PID of joints, allow user to reposition them to the force sensor
00056       RECORD_POSITION, //!< record the length of the lever arm (distance from point of rotation to force sensor)
00057       INPUT_PULSE, //!< wait for user to specify size of pulse to perform
00058       DO_PULSE, //!< make the joint do the pulse
00059       RECORD_FORCE //!< wait for user to report the recorded force applied
00060     };
00061     
00062     //! requests a transition to another state
00063     void transition(State_t newstate);
00064     
00065     const TorqueCalibrate& parent;
00066     unsigned int joint;
00067     float basePosition;
00068     float maxDuty;
00069     float sensorDist;
00070     State_t cstate;
00071     MotionManager::MC_ID pidID;
00072     MotionManager::MC_ID pulseID;
00073   };
00074   
00075   //! initialization
00076   virtual void init() {
00077     pushSlot(filenameInput=new FileInputControl("Storage: ","Location where data will be appended to any previous contents",""));
00078     pushSlot(NULL);
00079     for(unsigned int i=PIDJointOffset; i<PIDJointOffset+NumPIDJoints; i++)
00080       pushSlot(new TakeMeasurementControl(*this,i));
00081     
00082     filenameInput->setAcceptNonExistant(true);
00083     filenameInput->takeInput(filename);
00084     filename=""; //force refresh
00085   }
00086 
00087 
00088   // **************************** //
00089   // ********* METHODS ********** //
00090   // **************************** //
00091 public:
00092   void record(unsigned int joint, float sensorDist, float maxDuty, float maxForce) const;
00093   virtual void refresh();
00094   
00095 
00096   // **************************** //
00097   // ********* MEMBERS ********** //
00098   // **************************** //
00099 protected:
00100   std::string filename;
00101   FileInputControl * filenameInput;
00102 
00103 
00104   // **************************** //
00105   // ********** OTHER *********** //
00106   // **************************** //
00107 private:
00108   TorqueCalibrate(const TorqueCalibrate&); //!< you can override, but don't call this...
00109   TorqueCalibrate& operator=(const TorqueCalibrate&); //!< you can override, but don't call this...
00110 };
00111 
00112 /*! @file
00113  * @brief Defines TorqueCalibrate, which provides an interface for making measurements to correlate PID duty cycle and actual force output for each of the motors
00114  * @author Ethan Tira-Thompson (ejt) (Creator)
00115  *
00116  * $Author: ejt $
00117  * $Name: tekkotsu-4_0 $
00118  * $Revision: 1.1 $
00119  * $State: Exp $
00120  * $Date: 2007/04/05 06:24:09 $
00121  */
00122 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:56 2007 by Doxygen 1.5.4