Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RobotAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lennard Hofmann
RobotAPI
Commits
c6a2afe4
Commit
c6a2afe4
authored
8 years ago
by
Mirko Wächter
Browse files
Options
Downloads
Patches
Plain Diff
refactoring in PIDController
parent
368186eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/RobotAPI/libraries/core/PIDController.cpp
+12
-10
12 additions, 10 deletions
source/RobotAPI/libraries/core/PIDController.cpp
source/RobotAPI/libraries/core/PIDController.h
+5
-4
5 additions, 4 deletions
source/RobotAPI/libraries/core/PIDController.h
with
17 additions
and
14 deletions
source/RobotAPI/libraries/core/PIDController.cpp
+
12
−
10
View file @
c6a2afe4
...
...
@@ -29,7 +29,7 @@
using
namespace
armarx
;
PIDController
::
PIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
,
double
max
Acceler
ation
)
:
PIDController
::
PIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
,
double
max
Deriv
ation
)
:
Kp
(
Kp
),
Ki
(
Ki
),
Kd
(
Kd
),
...
...
@@ -40,7 +40,8 @@ PIDController::PIDController(float Kp, float Ki, float Kd, double maxControlValu
target
(
0
),
controlValue
(
0
),
maxControlValue
(
maxControlValue
),
maxAcceleration
(
maxAcceleration
)
maxDerivation
(
maxDerivation
),
controlValueDerivation
(
0
)
{
reset
();
}
...
...
@@ -113,10 +114,11 @@ void PIDController::update(double deltaSec, double measuredValue, double targetV
controlValue
=
Kp
*
error
+
Ki
*
integral
+
Kd
*
derivative
;
if
(
deltaSec
>
0.0
)
{
double
acc
=
(
controlValue
-
oldControlValue
)
/
deltaSec
;
if
(
fabs
(
acc
)
>
max
Acceler
ation
)
double
deriv
=
(
controlValue
-
oldControlValue
)
/
deltaSec
;
if
(
fabs
(
deriv
)
>
max
Deriv
ation
)
{
controlValue
=
oldControlValue
+
maxAcceleration
*
deltaSec
*
math
::
MathUtils
::
Sign
(
acc
);
controlValueDerivation
=
maxDerivation
*
deltaSec
*
math
::
MathUtils
::
Sign
(
deriv
);
controlValue
=
oldControlValue
+
controlValueDerivation
;
}
}
controlValue
=
std
::
min
(
fabs
(
controlValue
),
maxControlValue
)
*
math
::
MathUtils
::
Sign
(
controlValue
);
...
...
@@ -134,7 +136,7 @@ double PIDController::getControlValue() const
}
MultiDimPIDController
::
MultiDimPIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
,
double
max
Acceler
ation
)
:
MultiDimPIDController
::
MultiDimPIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
,
double
max
Deriv
ation
)
:
Kp
(
Kp
),
Ki
(
Ki
),
Kd
(
Kd
),
...
...
@@ -142,7 +144,7 @@ MultiDimPIDController::MultiDimPIDController(float Kp, float Ki, float Kd, doubl
derivative
(
0
),
previousError
(
0
),
maxControlValue
(
maxControlValue
),
max
Acceler
ation
(
max
Acceler
ation
)
max
Deriv
ation
(
max
Deriv
ation
)
{
reset
();
}
...
...
@@ -195,10 +197,10 @@ void MultiDimPIDController::update(const double deltaSec, const Eigen::VectorXf&
float
maxNewJointAcc
=
accVec
.
maxCoeff
();
float
minNewJointAcc
=
accVec
.
minCoeff
();
maxNewJointAcc
=
std
::
max
<
float
>
(
fabs
(
minNewJointAcc
),
fabs
(
maxNewJointAcc
));
if
(
maxNewJointAcc
>
max
Acceler
ation
)
if
(
maxNewJointAcc
>
max
Deriv
ation
)
{
auto
newValue
=
oldControlValue
+
accVec
*
max
Acceler
ation
/
maxNewJointAcc
*
deltaSec
;
ARMARX_DEBUG
<<
deactivateSpam
(
0.5
)
<<
VAROUT
(
max
Acceler
ation
)
<<
VAROUT
(
maxNewJointAcc
)
<<
VAROUT
(
controlValue
)
<<
VAROUT
(
oldControlValue
)
<<
VAROUT
(
newValue
);
auto
newValue
=
oldControlValue
+
accVec
*
max
Deriv
ation
/
maxNewJointAcc
*
deltaSec
;
ARMARX_DEBUG
<<
deactivateSpam
(
0.5
)
<<
VAROUT
(
max
Deriv
ation
)
<<
VAROUT
(
maxNewJointAcc
)
<<
VAROUT
(
controlValue
)
<<
VAROUT
(
oldControlValue
)
<<
VAROUT
(
newValue
);
controlValue
=
newValue
;
}
}
...
...
This diff is collapsed.
Click to expand it.
source/RobotAPI/libraries/core/PIDController.h
+
5
−
4
View file @
c6a2afe4
...
...
@@ -35,7 +35,7 @@ namespace armarx
public
Logging
{
public:
PIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
=
std
::
numeric_limits
<
double
>::
max
(),
double
max
Acceler
ation
=
std
::
numeric_limits
<
double
>::
max
());
PIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
=
std
::
numeric_limits
<
double
>::
max
(),
double
max
Deriv
ation
=
std
::
numeric_limits
<
double
>::
max
());
void
update
(
double
deltaSec
,
double
measuredValue
,
double
targetValue
);
void
update
(
double
measuredValue
,
double
targetValue
);
void
update
(
double
measuredValue
);
...
...
@@ -53,8 +53,9 @@ namespace armarx
double
target
;
IceUtil
::
Time
lastUpdateTime
;
double
controlValue
;
double
controlValueDerivation
;
double
maxControlValue
;
double
max
Acceler
ation
;
double
max
Deriv
ation
;
bool
firstRun
;
mutable
RecursiveMutex
mutex
;
};
...
...
@@ -64,7 +65,7 @@ namespace armarx
public
Logging
{
public:
MultiDimPIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
=
std
::
numeric_limits
<
double
>::
max
(),
double
max
Acceler
ation
=
std
::
numeric_limits
<
double
>::
max
());
MultiDimPIDController
(
float
Kp
,
float
Ki
,
float
Kd
,
double
maxControlValue
=
std
::
numeric_limits
<
double
>::
max
(),
double
max
Deriv
ation
=
std
::
numeric_limits
<
double
>::
max
());
void
update
(
const
double
deltaSec
,
const
Eigen
::
VectorXf
&
measuredValue
,
const
Eigen
::
VectorXf
&
targetValue
);
void
update
(
const
Eigen
::
VectorXf
&
measuredValue
,
const
Eigen
::
VectorXf
&
targetValue
);
const
Eigen
::
VectorXf
&
getControlValue
()
const
;
...
...
@@ -81,7 +82,7 @@ namespace armarx
IceUtil
::
Time
lastUpdateTime
;
Eigen
::
VectorXf
controlValue
;
double
maxControlValue
;
double
max
Acceler
ation
;
double
max
Deriv
ation
;
bool
firstRun
;
mutable
RecursiveMutex
mutex
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment