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

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3