Go to the documentation of this file.00001
00010 #ifndef MOTOR_TORQUE_CONTROLLER_H
00011 #define MOTOR_TORQUE_CONTROLLER_H
00012
00013 #include <string>
00014 #include <boost/shared_ptr.hpp>
00015 #include "../Stabilizer/TwoDofController.h"
00016 #include "TwoDofControllerPDModel.h"
00017 #include "TwoDofControllerDynamicsModel.h"
00018
00019
00020
00021 class MotorTorqueController {
00022 public:
00023 enum motor_model_t {
00024 TWO_DOF_CONTROLLER,
00025 TWO_DOF_CONTROLLER_PD_MODEL,
00026 TWO_DOF_CONTROLLER_DYNAMICS_MODEL
00027 };
00028
00029 enum controller_state_t {
00030 INACTIVE,
00031 STOP,
00032 ACTIVE
00033 };
00034
00035 MotorTorqueController();
00036 ~MotorTorqueController(void);
00037
00038
00039 MotorTorqueController(std::string _jname, TwoDofController::TwoDofControllerParam &_param);
00040 void setupController(TwoDofController::TwoDofControllerParam &_param);
00041 bool getControllerParam(TwoDofController::TwoDofControllerParam &_param);
00042 bool updateControllerParam(TwoDofController::TwoDofControllerParam &_param);
00043
00044 MotorTorqueController(std::string _jname, TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00045 void setupController(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00046 bool getControllerParam(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00047 bool updateControllerParam(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00048
00049 MotorTorqueController(std::string _jname, TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00050 void setupController(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00051 bool getControllerParam(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00052 bool updateControllerParam(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00053
00054
00055 bool enable(void);
00056 bool disable(void);
00057
00058
00059 void setupMotorControllerControlMinMaxDq(double _min_dq, double _max_dq);
00060 void setupMotorControllerTransitionMinMaxDq(double _min_transition_dq, double _max_transition_dq);
00061 bool activate(void);
00062 bool deactivate(void);
00063 bool setReferenceTorque(double _tauRef);
00064
00065 double execute(double _tau, double _tauMax);
00066
00067
00068 motor_model_t getMotorModelType(void);
00069 std::string getJointName(void);
00070 controller_state_t getMotorControllerState(void);
00071 bool isEnabled(void);
00072
00073
00074 void setErrorPrefix(const std::string& _error_prefix);
00075 void printMotorControllerVariables(void);
00076
00077 private:
00078 class MotorController {
00079 public:
00080 MotorController();
00081 ~MotorController();
00082 boost::shared_ptr<TwoDofControllerInterface> controller;
00083 controller_state_t state;
00084 double dq;
00085 double transition_dq;
00086 double recovery_dq;
00087 double min_dq;
00088 double max_dq;
00089 double min_transition_dq;
00090 double max_transition_dq;
00091
00092
00093 void setupTwoDofController(TwoDofController::TwoDofControllerParam &_param);
00094 bool getTwoDofControllerParam(TwoDofController::TwoDofControllerParam &_param);
00095 bool updateTwoDofControllerParam(TwoDofController::TwoDofControllerParam &_param);
00096
00097 void setupTwoDofControllerPDModel(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00098 bool getTwoDofControllerPDModelParam(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00099 bool updateTwoDofControllerPDModelParam(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param);
00100
00101 void setupTwoDofControllerDynamicsModel(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00102 bool getTwoDofControllerDynamiccsModelParam(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00103 bool updateTwoDofControllerDynamiccsModelParam(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param);
00104 double getMotorControllerDq(void);
00105 void setErrorPrefix(const std::string& _error_prefix);
00106 private:
00107 bool updateParam(double &_param, const double &_new_value);
00108 std::string error_prefix;
00109 };
00110
00111
00112 void setupControllerCommon(std::string _jname, double _dt);
00113 void resetMotorControllerVariables(MotorController& _mc);
00114 void prepareStop(MotorController &_mc);
00115 void updateController(double _tau, double _tauRef, MotorController& _mc);
00116
00117 std::string m_joint_name;
00118 motor_model_t m_motor_model_type;
00119 int m_transition_count;
00120 double m_dt;
00121 double m_current_tau;
00122 double m_command_tauRef;
00123 double m_actual_tauRef;
00124 MotorController m_normalController;
00125 MotorController m_emergencyController;
00126 std::string m_error_prefix;
00127 bool m_enable_flag;
00128 };
00129
00130
00131 #endif // MOTOR_TORQUE_CONTROLLER_H