Merge branch 'master' of github:szmoore/MCTX3420 into report
[matches/MCTX3420.git] / server / actuators / pregulator.c
index 3740729..1cd62d3 100644 (file)
@@ -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);
 }
 

UCC git Repository :: git.ucc.asn.au