Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
thk_pid_controller
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thk_libs
microcontrollers
thk_pid_controller
Commits
8a975a02
Commit
8a975a02
authored
May 11, 2022
by
Orhan-Timo Altan
Browse files
Options
Downloads
Patches
Plain Diff
init
parent
57a0f070
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
examples/example.ino
+44
-0
44 additions, 0 deletions
examples/example.ino
pid_controller.cpp
+25
-0
25 additions, 0 deletions
pid_controller.cpp
pid_controller.h
+21
-0
21 additions, 0 deletions
pid_controller.h
with
92 additions
and
0 deletions
.gitignore
0 → 100644
+
2
−
0
View file @
8a975a02
.vscode
build
\ No newline at end of file
This diff is collapsed.
Click to expand it.
examples/example.ino
0 → 100644
+
44
−
0
View file @
8a975a02
#include
<pid_controller.h>
double
prop_gain
=
0.1
;
double
int_gain
=
0.1
;
double
diff_gain
=
0.01
;
double
input_value
=
0
;
uint8_t
step
=
0
;
uint8_t
setpoint
=
50
;
PIDController
pid
(
prop_gain
,
int_gain
,
diff_gain
,
0
);
void
setup
(){
Serial
.
begin
(
115200
);
pid
.
set_setpoint
(
setpoint
);
}
void
loop
(){
step
++
;
// if (input_value < 70)
// {
// pid.set_setpoint(100);
// }
input_value
=
pid
.
compute
(
input_value
);
if
(
setpoint
-
input_value
<
0.01
)
{
Serial
.
print
(
"Reached setpoint after "
);
Serial
.
print
(
step
);
Serial
.
print
(
" steps"
);
exit
(
0
);
}
else
{
Serial
.
print
(
step
);
Serial
.
print
(
": "
);
Serial
.
print
(
input_value
);
Serial
.
print
(
"
\n
"
);
}
delay
(
100
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pid_controller.cpp
+
25
−
0
View file @
8a975a02
#include
<pid_controller.h>
PIDController
::
PIDController
(
double
Kp
,
double
Ki
,
double
Kd
,
double
setpoint
)
:
Kp
(
Kp
),
Ki
(
Ki
),
Kd
(
Kd
),
setpoint
(
setpoint
)
{}
void
PIDController
::
set_setpoint
(
double
setpoint
)
{
this
->
setpoint
=
setpoint
;
}
double
PIDController
::
compute
(
double
input_value
)
{
double
error_value
=
setpoint
-
input_value
;
out_p
=
Kp
*
error_value
;
// P-Anteil
out_i
+=
Ki
*
error_value
;
// I-Anteil
out_d
-=
Kd
*
error_value
;
// D-Anteil
return
out_p
+
out_i
+
out_d
;
}
void
PIDController
::
reset
()
{
out_i
=
0
;
out_d
=
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pid_controller.h
+
21
−
0
View file @
8a975a02
#ifndef PID_CONTROLLER_H
#define PID_CONTROLLER_H
#include
"Arduino.h"
class
PIDController
{
public:
PIDController
(
double
Kp
,
double
Ki
,
double
Kd
,
double
setpoint
);
double
compute
(
double
input_value
);
void
set_setpoint
(
double
setpoint
);
void
reset
();
private:
double
Kp
,
Ki
,
Kd
;
double
setpoint
;
double
out_p
,
out_i
,
out_d
;
};
#endif
\ No newline at end of file
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