first commit, by Alekseev
This commit is contained in:
21
LICENSE
21
LICENSE
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020 Philip Salmony
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
65
PID_Test.c
65
PID_Test.c
@@ -1,65 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "PID.h"
|
|
||||||
|
|
||||||
/* Controller parameters */
|
|
||||||
#define PID_KP 2.0f
|
|
||||||
#define PID_KI 0.5f
|
|
||||||
#define PID_KD 0.25f
|
|
||||||
|
|
||||||
#define PID_TAU 0.02f
|
|
||||||
|
|
||||||
#define PID_LIM_MIN -10.0f
|
|
||||||
#define PID_LIM_MAX 10.0f
|
|
||||||
|
|
||||||
#define PID_LIM_MIN_INT -5.0f
|
|
||||||
#define PID_LIM_MAX_INT 5.0f
|
|
||||||
|
|
||||||
#define SAMPLE_TIME_S 0.01f
|
|
||||||
|
|
||||||
/* Maximum run-time of simulation */
|
|
||||||
#define SIMULATION_TIME_MAX 4.0f
|
|
||||||
|
|
||||||
/* Simulated dynamical system (first order) */
|
|
||||||
float TestSystem_Update(float inp);
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
/* Initialise PID controller */
|
|
||||||
PIDController pid = { PID_KP, PID_KI, PID_KD,
|
|
||||||
PID_TAU,
|
|
||||||
PID_LIM_MIN, PID_LIM_MAX,
|
|
||||||
PID_LIM_MIN_INT, PID_LIM_MAX_INT,
|
|
||||||
SAMPLE_TIME_S };
|
|
||||||
|
|
||||||
PIDController_Init(&pid);
|
|
||||||
|
|
||||||
/* Simulate response using test system */
|
|
||||||
float setpoint = 1.0f;
|
|
||||||
|
|
||||||
printf("Time (s)\tSystem Output\tControllerOutput\r\n");
|
|
||||||
for (float t = 0.0f; t <= SIMULATION_TIME_MAX; t += SAMPLE_TIME_S) {
|
|
||||||
|
|
||||||
/* Get measurement from system */
|
|
||||||
float measurement = TestSystem_Update(pid.out);
|
|
||||||
|
|
||||||
/* Compute new control signal */
|
|
||||||
PIDController_Update(&pid, setpoint, measurement);
|
|
||||||
|
|
||||||
printf("%f\t%f\t%f\r\n", t, measurement, pid.out);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float TestSystem_Update(float inp) {
|
|
||||||
|
|
||||||
static float output = 0.0f;
|
|
||||||
static const float alpha = 0.02f;
|
|
||||||
|
|
||||||
output = (SAMPLE_TIME_S * inp + output) / (1.0f + alpha * SAMPLE_TIME_S);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user