-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
camilo
committed
Feb 15, 2024
1 parent
01b9286
commit de107f4
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <qlibs.h> | ||
|
||
continuousTF<1> processTransferFunction= { | ||
{ 0.0f, 1.5f, }, | ||
{ 2.0f, 1.0f, }, | ||
}; | ||
|
||
constexpr real_t dt = 0.05f; /*Time step*/ | ||
real_t yt = 0.0f; /*Process output*/ | ||
real_t ut = 0.0f; /*Controller output*/ | ||
real_t wt = 0.0f; /*Set-Point*/ | ||
continuousSystem process( processTransferFunction, dt ); | ||
pidController controller; | ||
int inputPin = A0; // select the input pin for the potentiometer that will drive the setPoint | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
controller.setup( 5.0f, 10.0f ,0.01f ,dt ); | ||
controller.setSaturation( 0.0f, 100.0f ); | ||
} | ||
|
||
void loop() { | ||
/*Set-Point is driven from a potentiometer connected to analog input*/ | ||
wt = map( analogRead( inputPin ), 0, 1023, 0.0f, 100.0f ); | ||
ut = controller.control( wt, yt ); | ||
yt = process.excite( ut ); | ||
|
||
Serial.print( ut ); | ||
Serial.print( "," ); | ||
Serial.print( wt ); | ||
Serial.print( "," ); | ||
Serial.println( yt ); | ||
delay( dt*1000 ); | ||
} |