rtc
TorqueController
TwoDofControllerPDModel.cpp
Go to the documentation of this file.
1
// -*- C++ -*-
2
11
#include "
TwoDofControllerPDModel.h
"
12
#include <iostream>
13
#include <cmath>
14
15
#define NUM_CONVOLUTION_TERM 3
16
17
TwoDofControllerPDModel::TwoDofControllerPDModel
() {
18
param
=
TwoDofControllerPDModel::TwoDofControllerPDModelParam
();
// use default constructor
19
current_time
= 0;
20
convolutions
.clear();
21
for
(
int
i
= 0;
i
<
NUM_CONVOLUTION_TERM
;
i
++) {
22
convolutions
.push_back(
Convolution
(0.0, 0.0));
23
}
24
error_prefix
=
""
;
// inheritted from TwoDofControllerInterface
25
}
26
27
TwoDofControllerPDModel::TwoDofControllerPDModel
(
TwoDofControllerPDModel::TwoDofControllerPDModelParam
&_param,
unsigned
int
_range) {
28
param
.
ke
= _param.
ke
;
param
.
kd
= _param.
kd
;
param
.
tc
= _param.
tc
;
param
.
dt
= _param.
dt
;
29
current_time
= 0;
30
convolutions
.clear();
31
for
(
int
i
= 0;
i
<
NUM_CONVOLUTION_TERM
;
i
++) {
32
convolutions
.push_back(
Convolution
(_param.
dt
, _range));
33
}
34
error_prefix
=
""
;
// inheritted from TwoDofControllerInterface
35
}
36
37
TwoDofControllerPDModel::~TwoDofControllerPDModel
() {
38
}
39
40
void
TwoDofControllerPDModel::setup
() {
41
param
.
ke
= 0;
param
.
kd
= 0;
param
.
tc
= 0;
param
.
dt
= 0;
42
convolutions
.clear();
43
reset
();
44
}
45
46
void
TwoDofControllerPDModel::setup
(
TwoDofControllerPDModel::TwoDofControllerPDModelParam
&_param,
unsigned
int
_range) {
47
param
.
ke
= _param.
ke
;
param
.
kd
= _param.
kd
;
param
.
tc
= _param.
tc
;
param
.
dt
= _param.
dt
;
48
convolutions
.clear();
49
for
(
int
i
= 0;
i
<
NUM_CONVOLUTION_TERM
;
i
++) {
50
convolutions
.push_back(
Convolution
(_param.
dt
, _range));
51
}
52
reset
();
53
}
54
55
bool
TwoDofControllerPDModel::getParameter
() {
56
return
false
;
57
}
58
59
bool
TwoDofControllerPDModel::getParameter
(
TwoDofControllerPDModel::TwoDofControllerPDModelParam
&_p) {
60
_p.
ke
=
param
.
ke
;
61
_p.
kd
=
param
.
kd
;
62
_p.
tc
=
param
.
tc
;
63
_p.
dt
=
param
.
dt
;
64
return
true
;
65
}
66
67
void
TwoDofControllerPDModel::reset
() {
68
current_time
= 0;
69
for
(std::vector<Convolution>::iterator itr =
convolutions
.begin(); itr !=
convolutions
.end(); ++itr) {
70
(*itr).reset();
71
}
72
}
73
74
double
TwoDofControllerPDModel::update
(
double
_x,
double
_xd) {
75
// motor model: P = -ke / s + kd
76
77
double
velocity;
// velocity calcurated by 2 dof controller
78
79
// check parameters
80
if
(!
param
.
ke
|| !
param
.
kd
|| !
param
.
tc
|| !
param
.
dt
) {
81
std::cerr <<
"["
<<
error_prefix
<<
"]"
<<
"TwoDofControllerPDModel parameters are not set."
<< std::endl;
82
std::cerr <<
"["
<<
error_prefix
<<
"]"
<<
"ke: "
<<
param
.
ke
<<
", kd: "
<<
param
.
kd
<<
", tc: "
<<
param
.
tc
<<
", dt: "
<<
param
.
dt
<< std::endl;
83
return
0;
84
}
85
86
// update convolution
87
convolutions
[0].update(std::exp((
param
.
ke
/
param
.
kd
) *
current_time
), _x);
88
convolutions
[1].update(std::exp((
param
.
ke
/
param
.
kd
) *
current_time
), _xd - _x);
89
convolutions
[2].update(1 - std::exp((
param
.
ke
/
param
.
kd
) *
current_time
), _xd - _x);
90
91
// 2 dof controller
92
velocity = (1 / (
param
.
tc
*
param
.
kd
)) * (-
convolutions
[0].calculate() +
convolutions
[1].calculate())
93
- (1 / (
param
.
tc
*
param
.
tc
*
param
.
ke
)) *
convolutions
[2].calculate();
94
95
current_time
+=
param
.
dt
;
96
97
return
velocity *
param
.
dt
;
98
99
}
TwoDofControllerPDModel::TwoDofControllerPDModel
TwoDofControllerPDModel()
Definition:
TwoDofControllerPDModel.cpp:17
TwoDofControllerPDModel::TwoDofControllerPDModelParam::ke
double ke
Definition:
TwoDofControllerPDModel.h:31
TwoDofControllerPDModel::setup
void setup()
Definition:
TwoDofControllerPDModel.cpp:40
TwoDofControllerPDModel::~TwoDofControllerPDModel
~TwoDofControllerPDModel()
Definition:
TwoDofControllerPDModel.cpp:37
TwoDofControllerPDModel::TwoDofControllerPDModelParam::dt
double dt
Definition:
TwoDofControllerPDModel.h:34
TwoDofControllerPDModel::current_time
double current_time
Definition:
TwoDofControllerPDModel.h:47
i
png_uint_32 i
TwoDofControllerPDModel::reset
void reset()
Definition:
TwoDofControllerPDModel.cpp:67
TwoDofControllerPDModel::convolutions
std::vector< Convolution > convolutions
Definition:
TwoDofControllerPDModel.h:48
TwoDofControllerPDModel::param
TwoDofControllerPDModelParam param
Definition:
TwoDofControllerPDModel.h:46
TwoDofControllerPDModel::getParameter
bool getParameter()
Definition:
TwoDofControllerPDModel.cpp:55
TwoDofControllerPDModel::update
double update(double _x, double _xd)
Definition:
TwoDofControllerPDModel.cpp:74
TwoDofControllerPDModel::TwoDofControllerPDModelParam::tc
double tc
Definition:
TwoDofControllerPDModel.h:33
TwoDofControllerPDModel::TwoDofControllerPDModelParam::kd
double kd
Definition:
TwoDofControllerPDModel.h:32
TwoDofControllerPDModel::TwoDofControllerPDModelParam
Definition:
TwoDofControllerPDModel.h:21
TwoDofControllerPDModel.h
Feedback and Feedforward Controller which use PDModel as motor model.
Convolution
Definition:
Convolution.h:17
TwoDofControllerInterface::error_prefix
std::string error_prefix
Definition:
TwoDofController.h:28
NUM_CONVOLUTION_TERM
#define NUM_CONVOLUTION_TERM
Definition:
TwoDofControllerPDModel.cpp:15
hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Sat Dec 17 2022 03:52:21