Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Transfuser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
heming
Transfuser
Commits
f6993e8a
Unverified
Commit
f6993e8a
authored
4 years ago
by
Kashyap Chitta
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add PID controller
parent
8eecd8fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
leaderboard/team_code/pid_controller.py
+53
-0
53 additions, 0 deletions
leaderboard/team_code/pid_controller.py
with
53 additions
and
0 deletions
leaderboard/team_code/pid_controller.py
0 → 100644
+
53
−
0
View file @
f6993e8a
from
collections
import
deque
import
numpy
as
np
DEBUG
=
False
class
PIDController
(
object
):
def
__init__
(
self
,
K_P
=
1.0
,
K_I
=
0.0
,
K_D
=
0.0
,
n
=
20
):
self
.
_K_P
=
K_P
self
.
_K_I
=
K_I
self
.
_K_D
=
K_D
self
.
_window
=
deque
([
0
for
_
in
range
(
n
)],
maxlen
=
n
)
self
.
_max
=
0.0
self
.
_min
=
0.0
def
step
(
self
,
error
):
self
.
_window
.
append
(
error
)
self
.
_max
=
max
(
self
.
_max
,
abs
(
error
))
self
.
_min
=
-
abs
(
self
.
_max
)
if
len
(
self
.
_window
)
>=
2
:
integral
=
np
.
mean
(
self
.
_window
)
derivative
=
(
self
.
_window
[
-
1
]
-
self
.
_window
[
-
2
])
else
:
integral
=
0.0
derivative
=
0.0
if
DEBUG
:
import
cv2
canvas
=
np
.
ones
((
100
,
100
,
3
),
dtype
=
np
.
uint8
)
w
=
int
(
canvas
.
shape
[
1
]
/
len
(
self
.
_window
))
h
=
99
for
i
in
range
(
1
,
len
(
self
.
_window
)):
y1
=
(
self
.
_max
-
self
.
_window
[
i
-
1
])
/
(
self
.
_max
-
self
.
_min
+
1e-8
)
y2
=
(
self
.
_max
-
self
.
_window
[
i
])
/
(
self
.
_max
-
self
.
_min
+
1e-8
)
cv2
.
line
(
canvas
,
((
i
-
1
)
*
w
,
int
(
y1
*
h
)),
((
i
)
*
w
,
int
(
y2
*
h
)),
(
255
,
255
,
255
),
2
)
canvas
=
np
.
pad
(
canvas
,
((
5
,
5
),
(
5
,
5
),
(
0
,
0
)))
cv2
.
imshow
(
'
%.3f %.3f %.3f
'
%
(
self
.
_K_P
,
self
.
_K_I
,
self
.
_K_D
),
canvas
)
cv2
.
waitKey
(
1
)
return
self
.
_K_P
*
error
+
self
.
_K_I
*
integral
+
self
.
_K_D
*
derivative
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