X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=server%2Factuators%2Fpregulator.c;h=8b9d06e626fd6e254dee39f8f9fb8735b9983037;hb=1f6cc726ae4ec11ea0bf9c16f6f90cdb5d132cd6;hp=37407291aa702b0c1509fc8af1eb89f871888d2d;hpb=3dfde391486e81a357e08a24ccb7903c8adfa5aa;p=matches%2FMCTX3420.git diff --git a/server/actuators/pregulator.c b/server/actuators/pregulator.c index 3740729..8b9d06e 100644 --- a/server/actuators/pregulator.c +++ b/server/actuators/pregulator.c @@ -1,10 +1,17 @@ #include "pregulator.h" #include "../bbb_pin.h" + +#include "../data.h" #define PREGULATOR_PWM ECAP0 #define PREGULATOR_PERIOD 500000 //16666667 +/** PWM duty cycles raw **/ +static double pwm_raw[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6}; +/** Calibrated pressure values match with pwm_raw **/ +static double preg_cal[] = {96, 190, 285, 380, 475, 569}; + /** * Initiliase the pressure regulator */ @@ -23,11 +30,17 @@ bool Pregulator_Cleanup(int id) bool Pregulator_Set(int id, double value) { - return PWM_Set(PREGULATOR_PWM, false, PREGULATOR_PERIOD, value*(PREGULATOR_PERIOD)); + double anti_calibrated = Data_Calibrate(value, preg_cal, pwm_raw, sizeof(pwm_raw)/sizeof(double)); + Log(LOGDEBUG, "Pregulator value %f -> PWM duty cycle %f", value, anti_calibrated); + if (anti_calibrated < 0) + anti_calibrated = 0; + if (anti_calibrated > 1) + anti_calibrated = 1; + return PWM_Set(PREGULATOR_PWM, false, PREGULATOR_PERIOD, anti_calibrated*(PREGULATOR_PERIOD)); } bool Pregulator_Sanity(int id, double value) { - return (value >= 0.0 && value <= 1.0); + return (value >= 0 && value < 570); }