TwoDofControllerDynamicsModel.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
12 #include <iostream>
13 #include <cmath>
14 
15 #define NUM_CONVOLUTION_TERM 3
16 
19  current_time = 0;
20  convolutions.clear();
21  exp_sinh.clear();
22  for (int i = 0; i < NUM_CONVOLUTION_TERM; i++) {
23  convolutions.push_back(Convolution(0.0, 0.0));
24  }
26  error_prefix = ""; // inheritted from TwoDofControllerInterface
27 }
28 
30  param.alpha = _param.alpha; param.beta = _param.beta; param.ki = _param.ki; param.tc = _param.tc; param.dt = _param.dt;
31  current_time = 0;
32  convolutions.clear();
33  exp_sinh.clear();
34  for (int i = 0; i < NUM_CONVOLUTION_TERM; i++) {
35  convolutions.push_back(Convolution(_param.dt, _range));
36  }
37  integrate_exp_sinh_current.setup(_param.dt, _range);
38  error_prefix = ""; // inheritted from TwoDofControllerInterface
39 }
40 
42 }
43 
45  param.alpha = 0; param.beta = 0; param.ki = 0; param.tc = 0; param.dt = 0;
46  convolutions.clear();
47  exp_sinh.clear();
49  reset();
50 }
51 
53  param.alpha = _param.alpha; param.beta = _param.beta; param.ki = _param.ki; param.tc = _param.tc; param.dt = _param.dt;
54  convolutions.clear();
55  for (int i = 0; i < NUM_CONVOLUTION_TERM; i++) {
56  convolutions.push_back(Convolution(_param.dt, _range));
57  }
58  integrate_exp_sinh_current.setup(_param.dt, _range);
59  reset();
60 }
61 
63  current_time = 0;
64  exp_sinh.clear();
65  for (std::vector<Convolution>::iterator itr = convolutions.begin(); itr != convolutions.end(); ++itr) {
66  (*itr).reset();
67  }
69 }
70 
72  return false;
73 }
74 
76  _p.alpha = param.alpha;
77  _p.beta = param.beta;
78  _p.ki = param.ki;
79  _p.tc = param.tc;
80  _p.dt = param.dt;
81  return true;
82 }
83 
84 double TwoDofControllerDynamicsModel::update (double _x, double _xd) {
85  // motor model: P = -ke / s + kd + ki * s
86  // completing the square: s^2 + (kd/ki)*s - (ke/ki) = (s+alpha)^2-beta^2
87 
88  double velocity; // velocity calcurated by 2 dof controller
89 
90  // check parameters
91  if (!param.alpha || !param.beta || !param.tc || !param.dt) {
92  std::cerr << "[" << error_prefix << "]" << "TwoDofControllerDynamicsModel parameters are not set." << std::endl;
93  std::cerr << "[" << error_prefix << "]" << "alpha: " << param.alpha << ", beta: " << param.beta << ", tc: " << param.tc << ", dt: " << param.dt << std::endl;
94  return 0;
95  }
96 
97  // update exp(-a*t)*sinh(b*t) buffer
98  double exp_sinh_current = std::exp(-param.alpha * current_time) * std::sinh(param.beta * current_time);
99  exp_sinh.push_back(exp_sinh_current);
100  integrate_exp_sinh_current.update(exp_sinh_current);
101 
102  // update convolution
103  convolutions[0].update(exp_sinh_current, _x);
104  convolutions[1].update(exp_sinh_current, _xd - _x);
105  convolutions[2].update(integrate_exp_sinh_current.calculate(), _xd - _x);
106 
107  // 2 dof controller
108  velocity = (1 / (param.tc * param.ki * param.beta)) * (-convolutions[0].calculate() + convolutions[1].calculate())
109  + (1 / (param.tc * param.tc * param.ki * param.beta)) * convolutions[2].calculate();
110 
111  current_time += param.dt;
112 
113  return velocity * param.dt;
114 
115 }
double calculate(void)
Definition: Integrator.cpp:65
Feedback and Feedforward Controller which use PDModel as motor model.
TwoDofControllerDynamicsModelParam param
png_uint_32 i
#define NUM_CONVOLUTION_TERM
void setup(double _dt, unsigned int _range)
Definition: Integrator.cpp:32
void update(double _x)
Definition: Integrator.cpp:39
void reset(void)
Definition: Integrator.cpp:23


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51