testMotorTorqueController.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <stdlib.h>
5 
6 #define ABS(x) (((x) < 0) ? (-(x)) : (x))
7 
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;
11  MotorTorqueController *controller[test_num];
13  tdc_param.ke = ke; tdc_param.tc = tc; tdc_param.dt = dt;
14  controller[0] = new MotorTorqueController("hoge", tdc_param);
16  tdc_pdmodel_param.ke = ke; tdc_pdmodel_param.kd = kd; tdc_pdmodel_param.tc = tc; tdc_pdmodel_param.dt = dt;
17  controller[1] = new MotorTorqueController("hoge", tdc_pdmodel_param);
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];
21 
22  // initialize
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;
26  }
27 
28  double time = 0;
29  while ( true ) {
30  for (int i = 0; i < test_num; i++) {
31  controller[i]->setReferenceTorque(tau_d);
32 
33  if (time > 5.0 && activate_flag[i] == false) {
34  controller[i]->activate();
35  std::cerr << "#activated[" << i << "]" << std::endl;
36  activate_flag[i] = true;
37  }
38 
39  // execute controller
40  tau[i] = -ke * q[i] + kd * (ddqref[i] / dt);
41  dqref[i] = controller[i]->execute(tau[i], limit); // execute returns dqRef = sum(dq)
42  ddqref[i] = dqref[i] - q[i];
43 
44  // joint simulation
45  q[i] = dqref[i];
46 
47  if (activate_flag[i] == true) {
48  if (time > 20 && stop_flag[i] != true) {
49  controller[i]->deactivate();
50  stop_flag[i] = true;
51  } else if (time > 10) {
52  tau_d = 5.0;
53  }
54  }
55  if (time > 30) {
56  return 0;
57  }
58  }
59  std::cout << time << " " << q[0] << " " << dqref[0] << " " << tau[0] << " " << q[1] << " " << dqref[1] << " " << tau[1] << " " << tau_d << std::endl;
60  time += dt;
61  }
62  return 0;
63 }
double execute(double _tau, double _tauMax)
png_uint_32 i
bool setReferenceTorque(double _tauRef)
int main(int argc, char *argv[])
torque controller for single motor


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