Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ArduBlock2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
letsgoING
ArduBlock Source
ArduBlock2
Commits
c74480ec
Verified
Commit
c74480ec
authored
1 year ago
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
fixed errors on PID-Blocks
parent
8273f27e
No related branches found
No related tags found
1 merge request
!1
dev_prefereences to master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/ardublock/translator/block/operators/PidBlock.java
+23
-14
23 additions, 14 deletions
...va/com/ardublock/translator/block/operators/PidBlock.java
with
23 additions
and
14 deletions
src/main/java/com/ardublock/translator/block/operators/PidBlock.java
+
23
−
14
View file @
c74480ec
...
@@ -42,7 +42,7 @@ public class PidBlock extends TranslatorBlock
...
@@ -42,7 +42,7 @@ public class PidBlock extends TranslatorBlock
//TODO: TEST CONTROLLER FUNCTIONALITY!!!!!!!
//TODO: TEST CONTROLLER FUNCTIONALITY!!!!!!!
//FUNCTION CODE ASSEMBLY
//FUNCTION CODE ASSEMBLY
String
functionCode
=
"
int
computePID(
int
input,
int
setpoint, long interval,
int
kp"
;
String
functionCode
=
"
double
computePID(
double
input,
double
setpoint, long interval,
double
kp"
;
if
(
integrative
)
{
if
(
integrative
)
{
functionCode
+=
", double ki"
;
functionCode
+=
", double ki"
;
...
@@ -51,36 +51,45 @@ public class PidBlock extends TranslatorBlock
...
@@ -51,36 +51,45 @@ public class PidBlock extends TranslatorBlock
functionCode
+=
", double kd"
;
functionCode
+=
", double kd"
;
}
}
if
(
limited
)
{
if
(
limited
)
{
functionCode
+=
",
int
limitLow,
int
limitHigh"
;
functionCode
+=
",
double
limitLow,
double
limitHigh"
;
}
}
functionCode
+=
"){"
functionCode
+=
"){"
;
+
" static int lastError = 0;\n"
+
" static int out = 0;\n"
if
(
derivative
)
{
functionCode
+=
" static double lastError = 0;\n"
;
}
if
(
integrative
)
{
functionCode
+=
"static double cumError = 0; \n"
;
}
functionCode
+=
" static double out = 0;\n"
+
" static long lastTime = 0L;\n\n"
+
" static long lastTime = 0L;\n\n"
+
" double intervalSecond = interval / 1000.0;\n"
+
" long currentTime = millis();\t//get current time\n\n"
+
" long currentTime = millis();\t//get current time\n\n"
+
" if (currentTime
>=
lastTime
+
interval) {\n"
+
" if (currentTime
-
lastTime
>=
interval) {\n"
+
" long elapsedTime = (double)(currentTime - lastTime); //compute time elapsed from previous computation\n"
+
" long elapsedTime = (double)(currentTime - lastTime); //compute time elapsed from previous computation\n"
+
" \n"
+
" \n"
+
" long error = setpoint - input; // get error\n"
+
" long error = setpoint - input; // get error\n"
+
" out = kp * error; //P output\n\n"
;
+
" out = kp * error; //P output\n\n"
;
if
(
integrative
)
{
if
(
integrative
)
{
functionCode
+=
"
long
cumError
= cumError + error
* elapsedTime
; // compute integral\n"
;
functionCode
+=
" cumError = cumError + error; // compute integral\n"
;
if
(
limited
)
{
if
(
limited
)
{
functionCode
+=
" cumError = constrain(cumError, limitLow, limitHigh); //limit integral against windup"
;
functionCode
+=
" cumError = constrain(cumError, limitLow
* 100.0
, limitHigh
* 100.0
); //limit integral against windup
\n
"
;
}
}
functionCode
+=
" out = out + ki * cumError; //I output\n\n"
;
functionCode
+=
" out = out +
(
ki *
intervalSecond) *
cumError; //I output\n\n"
;
}
}
if
(
derivative
)
{
if
(
derivative
)
{
functionCode
+=
" long rateError =
(
error - lastError
) / elapsedTime
; // compute derivative\n"
functionCode
+=
" long rateError = error - lastError; // compute derivative\n"
+
" out = out
+ kd
* rateError; //D output\n\n"
;
+
" out = out
- (kd / intervalSecond)
* rateError; //D output\n\n"
;
}
}
if
(
limited
)
{
if
(
limited
)
{
functionCode
+=
" out = constrain(out, limitLow, limitHigh); //limit output\n\n"
;
functionCode
+=
" out = constrain(out, limitLow, limitHigh); //limit output\n\n"
;
}
}
if
(
derivative
)
{
functionCode
+=
" lastError = error; //remember current error\n"
functionCode
+=
" lastError = error; //remember current error\n"
;
+
" lastTime = currentTime; //remember current time\n"
}
functionCode
+=
" lastTime = currentTime; //remember current time\n"
+
" }\n"
+
" }\n"
+
" return out; //return the PID output\n"
+
" return out; //return the PID output\n"
+
"}"
;
+
"}"
;
...
...
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