15 #include <boost/version.hpp> 16 #if BOOST_VERSION >= 103500 17 #include <boost/math/special_functions/sign.hpp> 21 #define TRANSITION_TIME 2.0 // [sec] 22 #define MAX_TRANSITION_COUNT (TRANSITION_TIME/m_dt) 23 #define TORQUE_MARGIN 10.0 // [Nm] 24 #define DEFAULT_MIN_MAX_DQ 0.26 // default min/max is 15[deg] = 0.26[rad] 25 #define DEFAULT_MIN_MAX_TRANSITION_DQ (0.17 * m_dt) // default min/max is 10[deg/sec] = 0.17[rad/sec] 31 param.
ke = 0.0; param.
tc = 0.0; param.
dt = 0.0;
66 std::cerr <<
"motor model type is not TwoDofController" << std::endl;
79 std::cerr <<
"motor model type is not TwoDofController" << std::endl;
107 std::cerr <<
"[" <<
m_error_prefix <<
"]" <<
"motor model type is not TwoDofControllerPDModel" << std::endl;
120 std::cerr <<
"[" <<
m_error_prefix <<
"]" <<
"motor model type is not TwoDofControllerPDModel" << std::endl;
148 std::cerr <<
"[" <<
m_error_prefix <<
"]" <<
"motor model type is not TwoDofControllerDynamicsModel" << std::endl;
161 std::cerr <<
"[" <<
m_error_prefix <<
"]" <<
"motor model type is not TwoDofControllerDynamicsModel" << std::endl;
218 std::cerr <<
"[ERROR] Torque control in " <<
m_joint_name <<
" is already active" << std::endl;
238 double dq, limitedTauRef;
245 if (std::abs(_tau) > std::abs(_tauMax)) {
274 #if BOOST_VERSION >= 103500 275 limitedTauRef = boost::math::copysign(_tauMax, _tau);
277 limitedTauRef = std::fabs(_tauMax) * ((_tau < 0) ? -1 : 1);
326 std::cerr << prefix <<
"actual_tauRef:" <<
m_actual_tauRef << std::endl;
327 std::cerr << std::endl;
403 param.
ke = 0.0; param.
tc = 0.0; param.
dt = 0.0;
404 setupTwoDofController(param);
420 if (
typeid(*controller) !=
typeid(
TwoDofController) || boost::dynamic_pointer_cast<TwoDofController>(controller) == NULL) {
421 std::cerr <<
"[" << error_prefix <<
"]" <<
"incorrect controller type: TwoDofController" << std::endl;
425 (boost::dynamic_pointer_cast<
TwoDofController>(controller))->getParameter(param);
426 updateParam(_param.
ke, param.
ke);
427 updateParam(_param.
tc, param.
tc);
428 updateParam(_param.
dt, param.
dt);
434 if (
typeid(*controller) !=
typeid(
TwoDofController) || boost::dynamic_pointer_cast<TwoDofController>(controller) == NULL) {
435 std::cerr <<
"[" << error_prefix <<
"]" <<
"incorrect controller type: TwoDofController" << std::endl;
439 std::cerr <<
"[" << error_prefix <<
"]" <<
"controller is not inactive" << std::endl;
444 (boost::dynamic_pointer_cast<
TwoDofController>(controller))->getParameter(param);
445 updateParam(param.
ke, _param.
ke);
446 updateParam(param.
tc, _param.
tc);
447 updateParam(param.
dt, _param.
dt);
460 if (
typeid(*controller) !=
typeid(
TwoDofControllerPDModel) || boost::dynamic_pointer_cast<TwoDofControllerPDModel>(controller) == NULL) {
461 std::cerr <<
"[" << error_prefix <<
"]" <<
"incorrect controller type: TwoDofControllerPDModel" << std::endl;
467 updateParam(_param.
ke, param.
ke);
468 updateParam(_param.
kd, param.
kd);
469 updateParam(_param.
tc, param.
tc);
470 updateParam(_param.
dt, param.
dt);
476 if (
typeid(*controller) !=
typeid(
TwoDofControllerPDModel) || boost::dynamic_pointer_cast<TwoDofControllerPDModel>(controller) == NULL) {
477 std::cerr <<
"[" << error_prefix <<
"]" <<
"incorrect controller type: TwoDofControllerPDModel" << std::endl;
481 std::cerr <<
"[" << error_prefix <<
"]" <<
"controller is not inactive" << std::endl;
487 updateParam(param.
ke, _param.
ke);
488 updateParam(param.
kd, _param.
kd);
489 updateParam(param.
tc, _param.
tc);
490 updateParam(param.
dt, _param.
dt);
503 if (
typeid(*controller) !=
typeid(
TwoDofControllerDynamicsModel) || boost::dynamic_pointer_cast<TwoDofControllerDynamicsModel>(controller) == NULL) {
504 std::cerr <<
"[" << error_prefix <<
"]" <<
"incorrect controller type: TwoDofControllerDynamicsModel" << std::endl;
510 updateParam(_param.
beta, param.
beta);
511 updateParam(_param.
ki, param.
ki);
512 updateParam(_param.
tc, param.
tc);
513 updateParam(_param.
dt, param.
dt);
519 if (
typeid(*controller) !=
typeid(
TwoDofControllerDynamicsModel) || boost::dynamic_pointer_cast<TwoDofControllerDynamicsModel>(controller) == NULL) {
520 std::cerr <<
"[" << error_prefix <<
"]" <<
"incorrect controller type: TwoDofControllerDynamicsModel" << std::endl;
524 std::cerr <<
"[" << error_prefix <<
"]" <<
"controller is not inactive" << std::endl;
530 updateParam(param.
beta, _param.
beta);
531 updateParam(param.
ki, _param.
ki);
532 updateParam(param.
tc, _param.
tc);
533 updateParam(param.
dt, _param.
dt);
540 if (_new_value != 0) {
549 error_prefix = _error_prefix;
550 controller->setErrorPrefix(_error_prefix);
558 ret_dq = dq + transition_dq;
561 ret_dq = transition_dq;
void printMotorControllerVariables(void)
bool getTwoDofControllerPDModelParam(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param)
double execute(double _tau, double _tauMax)
void setupControllerCommon(std::string _jname, double _dt)
void prepareStop(MotorController &_mc)
bool updateControllerParam(TwoDofController::TwoDofControllerParam &_param)
void updateController(double _tau, double _tauRef, MotorController &_mc)
controller_state_t getMotorControllerState(void)
#define DEFAULT_MIN_MAX_DQ
bool setReferenceTorque(double _tauRef)
bool updateParam(double &_param, const double &_new_value)
#define DEFAULT_MIN_MAX_TRANSITION_DQ
void setErrorPrefix(const std::string &_error_prefix)
void setupTwoDofControllerPDModel(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param)
bool getTwoDofControllerDynamiccsModelParam(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param)
void setupMotorControllerTransitionMinMaxDq(double _min_transition_dq, double _max_transition_dq)
motor_model_t getMotorModelType(void)
bool updateTwoDofControllerDynamiccsModelParam(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param)
~MotorTorqueController(void)
bool getControllerParam(TwoDofController::TwoDofControllerParam &_param)
#define MAX_TRANSITION_COUNT
void setupMotorControllerControlMinMaxDq(double _min_dq, double _max_dq)
bool updateTwoDofControllerParam(TwoDofController::TwoDofControllerParam &_param)
bool updateTwoDofControllerPDModelParam(TwoDofControllerPDModel::TwoDofControllerPDModelParam &_param)
double getMotorControllerDq(void)
MotorController m_emergencyController
MotorController m_normalController
void setupTwoDofController(TwoDofController::TwoDofControllerParam &_param)
torque controller for single motor
void setErrorPrefix(const std::string &_error_prefix)
void resetMotorControllerVariables(MotorController &_mc)
std::string m_error_prefix
boost::shared_ptr< TwoDofControllerInterface > controller
void setupController(TwoDofController::TwoDofControllerParam &_param)
std::string getJointName(void)
void setupTwoDofControllerDynamicsModel(TwoDofControllerDynamicsModel::TwoDofControllerDynamicsModelParam &_param)
motor_model_t m_motor_model_type
bool getTwoDofControllerParam(TwoDofController::TwoDofControllerParam &_param)