Saltware / Mbed 2 deprecated Water Play

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
sbouber1
Date:
Tue Jun 14 15:31:30 2016 +0000
Parent:
34:e2d7865063da
Child:
36:8aeb014bd651
Commit message:
Heating in PIDController

Changed in this revision

LCDController.h Show annotated file Show diff for this revision Revisions of this file
PIDController.cpp Show annotated file Show diff for this revision Revisions of this file
PIDController.h Show annotated file Show diff for this revision Revisions of this file
TemperatureController.cpp Show annotated file Show diff for this revision Revisions of this file
TemperatureController.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LCDController.h	Tue Jun 14 11:17:06 2016 +0000
+++ b/LCDController.h	Tue Jun 14 15:31:30 2016 +0000
@@ -5,8 +5,6 @@
 #include "stdio.h"
 #include "TextLCD.h"
 
-#endif
-
 class LCDController {
 
     
@@ -23,4 +21,6 @@
         
         
         
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file
--- a/PIDController.cpp	Tue Jun 14 11:17:06 2016 +0000
+++ b/PIDController.cpp	Tue Jun 14 15:31:30 2016 +0000
@@ -1,5 +1,7 @@
 #include "PIDController.h"
-#include "SalinityController.h"
+#include "testing.h"
+
+DigitalOut heater(p18);
 
 DRV8825 mtr_fresh(p21, p27, p28, p29, p22, p23);
 DRV8825 mtr_salt(p24, p27, p28, p29, p25, p26);
@@ -7,28 +9,31 @@
 
 // This is called in the main loop on every iteration
 void PIDController::update() {
-    // You can use the variables temp, salt and proximity like this:
+    
+    // Control the heater
+    // This could be done in the pumping function as well, if needed
+    this->set_heating(temp->getValue() < 32.0f);
+
     float s = this->salt->getValue();
     float sInGrams = this->getSaltInGrams();
     
     if(s <= 6.0) {
         
         float ml = this->getMlSaltyWater(sInGrams, this->proximity->getValue());
+        int ml_int = static_cast<int>(ml);
     
-        printf("PIDCONTROLLER: need to pump %.3f ml of salty water\r\n", ml);
+        printf("PIDCONTROLLER: need to pump %d (%.3f) ml of salty water\r\n", ml_int, ml);
         
-        // MAYBE DO SOME ROUNDING HERE
-    
-        // CALL this->pump_salt_water
+        //this->pump_salt_water(ml_int);
     
     } else if(s >= 9.0) {
 
         float ml = this->getMlFreshWater(s, this->proximity->getValue());
-        printf("PIDCONTROLLER: need to pump %.3f ml of fresh water\r\n", ml);
+        int ml_int = static_cast<int>(ml);
         
-        // MAYBE DO SOME ROUNDING HERE
-    
-        // CALL this->pump_fresh_water        
+        printf("PIDCONTROLLER: need to pump %d (%.3f) ml of fresh water\r\n", ml_int, ml);
+        
+        //this->pump_fresh_water(ml_int);     
         
     }
 }
@@ -43,7 +48,7 @@
     float currentppt = this->salt->getValue(); //in ppt
     float currentvol = this->proximity->getValue(); //in ml
     
-    return currentppt * (currentvol /1000);
+    return currentppt * (currentvol / 1000);
 }
 
 
@@ -57,6 +62,7 @@
 }
 
 void PIDController::pump_water(DRV8825 *mtr, int ml) {
+    
     int j = 5010 * (ml - 1);
     
     for (int i = 500; i < MAX_SPEED; i += 5) {
@@ -84,8 +90,8 @@
     for (int i = 8000; i > 500; i -= 5) {
         mtr->settings(1 / MICROSTEPS_PER_STEP, RIGHT, i);
     }
-    wait(3);
     
+    wait(3);    
 }
 
 
@@ -103,8 +109,30 @@
     float outputml = (x1 / x2 * solvolume);
     
     return outputml; // amount in ml to get 7 ppt.
+}
+
+bool PIDController::is_heating() {
+    return this->heating;    
+}
+
+void PIDController::set_heating(bool enabled) {
+    if(enabled == this->heating) return;
+    
+    this->heating = enabled;
+    if(enabled) {
+        #ifdef RUN_TESTS
+        printf("Should set heater to 1\r\n");
+        #else
+        heater = 1;
+        #endif            
+    } else {
+        #ifdef RUN_TESTS
+        printf("Should set heater to 0\r\n");
+        #else
+        heater = 0;
+        #endif    
     }
-
+}
 
 float PIDController::getMlFreshWater(float ppt, float volume) {
     return (volume * (ppt / 7.0)) - volume;
--- a/PIDController.h	Tue Jun 14 11:17:06 2016 +0000
+++ b/PIDController.h	Tue Jun 14 15:31:30 2016 +0000
@@ -26,13 +26,15 @@
         
         virtual void update();
         
-        virtual std::string get_name();        
-        float getSaltInGrams();
+        virtual std::string get_name();
+        
+        bool is_heating();
     
     private:
         SensorController *temp;
         SensorController *salt;
         SensorController *proximity;
+        bool heating;
         
         void pump_salt_water(int ml);
         
@@ -44,7 +46,9 @@
         
         float getMlFreshWater(float, float);
         
+        float getSaltInGrams();
         
+        void set_heating(bool enabled);       
 };
 
 
--- a/TemperatureController.cpp	Tue Jun 14 11:17:06 2016 +0000
+++ b/TemperatureController.cpp	Tue Jun 14 15:31:30 2016 +0000
@@ -1,9 +1,7 @@
 #include "TemperatureController.h"
-#include "rtos.h"
 #include "testing.h"
 
 AnalogIn temperature_sensor(p20);
-DigitalOut heater(p18);
 
 float TemperatureController::getValue() {
     return this->temperature;    
@@ -17,29 +15,6 @@
     this->temperature = readSensor();
 }
 
-bool TemperatureController::is_heating() {
-    return this->heating;    
-}
-
-void TemperatureController::set_heating(bool enabled) {
-    if(enabled == this->heating) return;
-    
-    this->heating = enabled;
-    if(enabled) {
-        #ifdef RUN_TESTS
-        printf("Should set heater to 1\r\n");
-        #else
-        heater = 1;
-        #endif            
-    } else {
-        #ifdef RUN_TESTS
-        printf("Should set heater to 0\r\n");
-        #else
-        heater = 0;
-        #endif    
-    }
-}
-
 // Function reads sensor values and averages N sensor values
 float TemperatureController::readSensor()
 {
@@ -98,16 +73,6 @@
     return temperature;
 }
 
-// Function prints temperature sensor value in celsius
-void TemperatureController::displayTemperature()
-{
-    float temperature = 0;
-    
-    temperature = readSensor();
-    
-    printf("Temperature: %f Celsius\r\n", temperature);
-}
-
 float TemperatureController::getOffset(float voltage)
 {
     float denominator_voltage, numerator_voltage, ratio, interpolation;
@@ -141,10 +106,4 @@
     } else {
         return offset_table[0];
     }
-}
-
-void TemperatureController::controlHeater()
-{
-    this->set_heating(this->getValue() < 32.0f);
-        
 }
\ No newline at end of file
--- a/TemperatureController.h	Tue Jun 14 11:17:06 2016 +0000
+++ b/TemperatureController.h	Tue Jun 14 15:31:30 2016 +0000
@@ -2,7 +2,6 @@
 #define __TEMPERATURECONTROLLER_H__
 
 #include "mbed.h"
-#include "stdio.h"
 
 #include "SensorController.h"
 
@@ -17,25 +16,16 @@
         virtual void update();
         
         virtual std::string get_name();
-        
-        bool is_heating();
-        
-        void set_heating(bool enabled);
     
     private:
         float temperature;
         
-        bool heating;
-    
         static float readSensor();
         
         static float analoginToCelsius(float);
         
-        void controlHeater();
-        
         static float getOffset(float);
         
-        static void displayTemperature();
 };
 
 #endif
\ No newline at end of file
--- a/main.cpp	Tue Jun 14 11:17:06 2016 +0000
+++ b/main.cpp	Tue Jun 14 15:31:30 2016 +0000
@@ -115,4 +115,6 @@
             lcd.updateScreen(d);
         
     }
+    
+    return 1;
 }
\ No newline at end of file