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
5d494b2e
Commit
5d494b2e
authored
9 years ago
by
Mirko Waechter
Browse files
Options
Downloads
Patches
Plain Diff
multidim pid controller
parent
8de46f98
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
+65
-1
65 additions, 1 deletion
source/RobotAPI/libraries/core/PIDController.cpp
source/RobotAPI/libraries/core/PIDController.h
+27
-2
27 additions, 2 deletions
source/RobotAPI/libraries/core/PIDController.h
with
92 additions
and
3 deletions
source/RobotAPI/libraries/core/PIDController.cpp
+
65
−
1
View file @
5d494b2e
...
...
@@ -87,8 +87,72 @@ void PIDController::update(double deltaSec, double measuredValue, double targetV
}
double
PIDController
::
getControlValue
()
double
PIDController
::
getControlValue
()
const
{
ScopedRecursiveLock
lock
(
mutex
);
return
controlValue
;
}
MultiDimPIDController
::
MultiDimPIDController
(
float
Kp
,
float
Ki
,
float
Kd
)
:
Kp
(
Kp
),
Ki
(
Ki
),
Kd
(
Kd
),
integral
(
0
),
derivative
(
0
),
previousError
(
0
)
{
reset
();
}
void
MultiDimPIDController
::
update
(
const
double
deltaSec
,
const
Eigen
::
VectorXf
&
measuredValue
,
const
Eigen
::
VectorXf
&
targetValue
)
{
ScopedRecursiveLock
lock
(
mutex
);
processValue
=
measuredValue
;
target
=
targetValue
;
double
error
=
(
target
-
processValue
).
norm
();
//double dt = (now - lastUpdateTime).toSecondsDouble();
// ARMARX_INFO << deactivateSpam() << VAROUT(dt);
if
(
!
firstRun
)
{
integral
+=
error
*
deltaSec
;
derivative
=
(
error
-
previousError
)
/
deltaSec
;
}
firstRun
=
false
;
Eigen
::
VectorXf
direction
=
(
target
-
processValue
).
normalized
();
controlValue
=
direction
*
(
Kp
*
error
+
Ki
*
integral
+
Kd
*
derivative
);
if
(
error
>
0.04
)
ARMARX_INFO
<<
deactivateSpam
(
0.5
)
<<
" error: "
<<
error
<<
" cV: "
<<
(
controlValue
)
<<
" i: "
<<
(
Ki
*
integral
)
<<
" d: "
<<
(
Kd
*
derivative
)
<<
" dt: "
<<
deltaSec
;
previousError
=
error
;
lastUpdateTime
+=
IceUtil
::
Time
::
seconds
(
deltaSec
);
}
void
MultiDimPIDController
::
update
(
const
Eigen
::
VectorXf
&
measuredValue
,
const
Eigen
::
VectorXf
&
targetValue
)
{
ScopedRecursiveLock
lock
(
mutex
);
IceUtil
::
Time
now
=
IceUtil
::
Time
::
now
();
if
(
firstRun
)
{
lastUpdateTime
=
IceUtil
::
Time
::
now
();
}
double
dt
=
(
now
-
lastUpdateTime
).
toSecondsDouble
();
update
(
dt
,
measuredValue
,
targetValue
);
lastUpdateTime
=
now
;
}
const
Eigen
::
VectorXf
&
MultiDimPIDController
::
getControlValue
()
const
{
return
controlValue
;
}
void
MultiDimPIDController
::
reset
()
{
ScopedRecursiveLock
lock
(
mutex
);
firstRun
=
true
;
previousError
=
0
;
integral
=
0
;
lastUpdateTime
=
IceUtil
::
Time
::
now
();
}
This diff is collapsed.
Click to expand it.
source/RobotAPI/libraries/core/PIDController.h
+
27
−
2
View file @
5d494b2e
...
...
@@ -25,6 +25,7 @@
#define _ARMARX_COMPONENT_RobotAPI_PIDController_H
#include
<Core/core/logging/Logging.h>
#include
<Eigen/Core>
namespace
armarx
{
...
...
@@ -36,7 +37,7 @@ namespace armarx
PIDController
(
float
Kp
,
float
Ki
,
float
Kd
);
void
update
(
double
deltaSec
,
double
measuredValue
,
double
targetValue
);
void
update
(
double
measuredValue
,
double
targetValue
);
double
getControlValue
();
double
getControlValue
()
const
;
void
reset
();
// protected:
...
...
@@ -49,7 +50,31 @@ namespace armarx
IceUtil
::
Time
lastUpdateTime
;
double
controlValue
;
bool
firstRun
;
RecursiveMutex
mutex
;
mutable
RecursiveMutex
mutex
;
};
typedef
boost
::
shared_ptr
<
PIDController
>
PIDControllerPtr
;
class
MultiDimPIDController
:
public
Logging
{
public:
MultiDimPIDController
(
float
Kp
,
float
Ki
,
float
Kd
);
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
;
void
reset
();
// protected:
float
Kp
,
Ki
,
Kd
;
double
integral
;
double
derivative
;
double
previousError
;
Eigen
::
VectorXf
processValue
;
Eigen
::
VectorXf
target
;
IceUtil
::
Time
lastUpdateTime
;
Eigen
::
VectorXf
controlValue
;
bool
firstRun
;
mutable
RecursiveMutex
mutex
;
};
typedef
boost
::
shared_ptr
<
PIDController
>
PIDControllerPtr
;
}
...
...
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