Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
motors-control-card-driver
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
CdF
CdF 2020-2021
modules
motors-control-card
motors-control-card-driver
Commits
712c0b4d
Unverified
Commit
712c0b4d
authored
4 years ago
by
Charles Javerliat
Browse files
Options
Downloads
Patches
Plain Diff
chore: Remove reverse option for PID (useless?)
parent
311676e4
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Refactoring
Pipeline
#218
passed with stage
in 3 minutes and 44 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/regulator/PID.hpp
+0
-10
0 additions, 10 deletions
include/regulator/PID.hpp
src/regulator/PID.cpp
+4
-15
4 additions, 15 deletions
src/regulator/PID.cpp
src/regulator/SpeedRegulator.cpp
+2
-8
2 additions, 8 deletions
src/regulator/SpeedRegulator.cpp
with
6 additions
and
33 deletions
include/regulator/PID.hpp
+
0
−
10
View file @
712c0b4d
...
...
@@ -72,14 +72,6 @@ public:
*/
void
reset
();
/**
* The PID will either be connected to a DIRECT acting process (+Output leads
* to +Input) or a REVERSE acting process(+Output leads to -Input.) we need to
* know which one, because otherwise we may increase the output when we should
* be decreasing.
*/
void
setReverse
(
bool
reverse
);
private
:
const
PID
::
Gains
&
m_gains
;
...
...
@@ -90,8 +82,6 @@ private:
double
m_minOutput
;
double
m_maxOutput
;
bool
m_reverse
;
};
#endif
This diff is collapsed.
Click to expand it.
src/regulator/PID.cpp
+
4
−
15
View file @
712c0b4d
...
...
@@ -2,20 +2,14 @@
#include
"Math.hpp"
//TODO(cjaverliat): Check that errors is initialized with zeroes
PID
::
PID
(
const
PID
::
Gains
&
gains
,
double
minOutput
,
double
maxOutput
)
:
m_gains
(
gains
),
m_minOutput
(
minOutput
),
m_maxOutput
(
maxOutput
),
m_reverse
(
false
)
m_maxOutput
(
maxOutput
)
{
}
double
PID
::
compute
(
double
dt
)
{
double
kp
=
m_reverse
?
-
m_gains
.
Kp
:
m_gains
.
Kp
;
double
ki
=
m_reverse
?
-
m_gains
.
Ki
:
m_gains
.
Ki
;
double
kd
=
m_reverse
?
-
m_gains
.
Kd
:
m_gains
.
Kd
;
double
proportional
;
double
integral
;
double
derivative
;
...
...
@@ -28,11 +22,11 @@ double PID::compute(double dt)
m_errors
.
lastErrorSet
=
true
;
}
proportional
=
k
p
*
m_errors
.
error
;
proportional
=
m_gains
.
K
p
*
m_errors
.
error
;
// TODO(cjaverliat): Use trapezoidal integration instead
m_errors
.
accumulator
+=
m_errors
.
error
*
dt
;
integral
=
Math
::
clamp
(
k
i
*
m_errors
.
accumulator
,
m_minOutput
,
m_maxOutput
);
integral
=
Math
::
clamp
(
m_gains
.
K
i
*
m_errors
.
accumulator
,
m_minOutput
,
m_maxOutput
);
if
(
dt
==
0
)
{
...
...
@@ -40,7 +34,7 @@ double PID::compute(double dt)
}
else
{
derivative
=
k
d
*
(
m_errors
.
error
-
m_errors
.
lastError
)
/
dt
;
derivative
=
m_gains
.
K
d
*
(
m_errors
.
error
-
m_errors
.
lastError
)
/
dt
;
}
m_errors
.
lastError
=
m_errors
.
error
;
...
...
@@ -48,11 +42,6 @@ double PID::compute(double dt)
return
Math
::
clamp
(
proportional
+
integral
+
derivative
,
m_minOutput
,
m_maxOutput
);
}
void
PID
::
setReverse
(
bool
reverse
)
{
m_reverse
=
reverse
;
}
void
PID
::
setSetpoint
(
double
setpoint
)
{
m_setpoint
=
setpoint
;
}
double
PID
::
getSetpoint
()
{
return
m_setpoint
;
}
...
...
This diff is collapsed.
Click to expand it.
src/regulator/SpeedRegulator.cpp
+
2
−
8
View file @
712c0b4d
...
...
@@ -33,12 +33,6 @@ void SpeedRegulator::update(double dt)
void
SpeedRegulator
::
setSetpoint
(
double
linearSpeed
,
double
angularSpeed
)
{
double
leftSp
=
linearSpeed
-
angularSpeed
*
(
m_odometer
.
getGeometry
().
wheelbaseNominal
/
2.0
);
double
rightSp
=
linearSpeed
+
angularSpeed
*
(
m_odometer
.
getGeometry
().
wheelbaseNominal
/
2.0
);
m_leftMotorPid
.
setReverse
(
leftSp
<
0
);
m_rightMotorPid
.
setReverse
(
rightSp
<
0
);
m_leftMotorPid
.
setSetpoint
(
leftSp
);
m_rightMotorPid
.
setSetpoint
(
rightSp
);
m_leftMotorPid
.
setSetpoint
(
linearSpeed
-
angularSpeed
*
(
m_odometer
.
getGeometry
().
wheelbaseNominal
/
2.0
));
m_rightMotorPid
.
setSetpoint
(
linearSpeed
+
angularSpeed
*
(
m_odometer
.
getGeometry
().
wheelbaseNominal
/
2.0
));
}
This diff is collapsed.
Click to expand it.
Preview
0%
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