TorqueCalibrate.h
Go to the documentation of this file.00001
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
00018 class TorqueCalibrate : public ControlBase {
00019
00020
00021
00022
00023
00024
00025
00026 public:
00027
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
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
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
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
00061 enum State_t {
00062 ZERO_JOINT,
00063 RECORD_POSITION,
00064 INPUT_PULSE,
00065 DO_PULSE,
00066 RECORD_FORCE
00067 };
00068
00069
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
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="";
00092 }
00093
00094
00095
00096
00097
00098 public:
00099 void record(unsigned int joint, float sensorDist, float maxDuty, float maxForce) const;
00100 virtual void refresh();
00101
00102
00103
00104
00105
00106 protected:
00107 std::string filename;
00108 FileInputControl * filenameInput;
00109
00110
00111
00112
00113
00114 private:
00115 TorqueCalibrate(const TorqueCalibrate&);
00116 TorqueCalibrate& operator=(const TorqueCalibrate&);
00117 };
00118
00119
00120
00121
00122
00123 #endif