X-Git-Url: https://git.ucc.asn.au/?p=matches%2FMCTX3420.git;a=blobdiff_plain;f=server%2Factuators%2Fpregulator.c;h=1cd62d3a3b055c0032335aeba046494d7dcdf1db;hp=37407291aa702b0c1509fc8af1eb89f871888d2d;hb=f4f4c762db8c7cb2934bb03ae85063e453d68169;hpb=75b9743b95672218a61811b03433c0ab6e00ec5c diff --git a/server/actuators/pregulator.c b/server/actuators/pregulator.c index 3740729..1cd62d3 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,16 @@ 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)); + 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); }