6 #define ABS(x) (((x) < 0) ? (-(x)) : (x)) 8 int main (
int argc,
char* argv[]) {
9 double ke = 2.0, kd = 20.0, tc = 0.05, dt = 0.005;
10 const int test_num = 2;
13 tdc_param.
ke = ke; tdc_param.
tc = tc; tdc_param.
dt = dt;
16 tdc_pdmodel_param.
ke = ke; tdc_pdmodel_param.
kd = kd; tdc_pdmodel_param.
tc = tc; tdc_pdmodel_param.
dt = dt;
18 double q[test_num], dq[test_num], q_ref[test_num], tau[test_num], dqref[test_num], ddqref[test_num];
19 double tau_d = 10.0, limit = 90.0, pgain = 1.0, dgain = 0.01;
20 bool activate_flag[test_num], stop_flag[test_num];
23 for (
int i = 0;
i < test_num;
i++){
24 q[
i] = dq[
i] = q_ref[
i] = tau[
i] = dqref[
i] = ddqref[
i] = 0;
25 activate_flag[
i] = stop_flag[
i] =
false;
30 for (
int i = 0;
i < test_num;
i++) {
33 if (time > 5.0 && activate_flag[
i] ==
false) {
35 std::cerr <<
"#activated[" <<
i <<
"]" << std::endl;
36 activate_flag[
i] =
true;
40 tau[
i] = -ke * q[
i] + kd * (ddqref[
i] / dt);
41 dqref[
i] = controller[
i]->
execute(tau[
i], limit);
42 ddqref[i] = dqref[i] - q[i];
47 if (activate_flag[i] ==
true) {
48 if (time > 20 && stop_flag[i] !=
true) {
51 }
else if (time > 10) {
59 std::cout << time <<
" " << q[0] <<
" " << dqref[0] <<
" " << tau[0] <<
" " << q[1] <<
" " << dqref[1] <<
" " << tau[1] <<
" " << tau_d << std::endl;
double execute(double _tau, double _tauMax)
bool setReferenceTorque(double _tauRef)
int main(int argc, char *argv[])
torque controller for single motor