.

Dependencies:   L432KC_SPI_Pey_Lal

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers asservissement.cpp Source File

asservissement.cpp

00001 #include "asservissement.hpp"
00002 #include "toolbox.hpp"
00003 
00004 double kp = 1;
00005 double ki = 1;
00006 double errorIntegral = 0;
00007 double integralLimit = 10;
00008 
00009 uint32_t PID(double error, double sampleRate)
00010 {
00011     errorIntegral += error / sampleRate;
00012     errorIntegral = limitToInterval(errorIntegral, -integralLimit, integralLimit);
00013     double correction = kp * error + ki * errorIntegral;
00014     double correctionPWM = SPEED_TO_PWM_TRANSFORM(correction);
00015     return limitToInterval(correctionPWM, 1000, 1500);
00016 }
00017 
00018 void setPIDParameters(double kp_, double ki_)
00019 {
00020     kp = kp_;
00021     ki = ki_;
00022 }