Program for the water play project for the course Software Testing Practical 2016 given at the VU University

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Committer:
joran
Date:
Wed Jun 15 07:57:16 2016 +0000
Revision:
42:e7c726f9c6ed
Parent:
32:1e4919a44196
Child:
58:b5f0c0f305ff
Code cleanup: Salinitycontroller. Removed code is backed up in gdrive

Who changed what in which revision?

UserRevisionLine numberNew contents of line
6366295 0:dab140a197e0 1 #include "SalinityController.h"
6366295 0:dab140a197e0 2
6366295 0:dab140a197e0 3 AnalogIn salinity_sensor(p19);
6366295 0:dab140a197e0 4
joran 42:e7c726f9c6ed 5 //Read the sensor, update the local variable.
sbouber1 10:fd4670ec0806 6 void SalinityController::update() {
sbouber1 10:fd4670ec0806 7 this->salinity = SalinityController::getAdjustedPPT();
sbouber1 10:fd4670ec0806 8 }
sbouber1 10:fd4670ec0806 9
joran 42:e7c726f9c6ed 10 //Return the value, this function does not update the value.
sbouber1 10:fd4670ec0806 11 float SalinityController::getValue() {
sbouber1 10:fd4670ec0806 12 return this->salinity;
6366295 0:dab140a197e0 13 }
6366295 0:dab140a197e0 14
joran 42:e7c726f9c6ed 15 //Read the voltage, get an average over N values.
joran 42:e7c726f9c6ed 16 float SalinityController::getVoltage()
6366295 0:dab140a197e0 17 {
joran 42:e7c726f9c6ed 18 float voltage = 0;
6366295 0:dab140a197e0 19 float analogin_value = 0;
6366295 0:dab140a197e0 20
6366295 0:dab140a197e0 21 // Read 0-1.0 value
6366295 0:dab140a197e0 22 for(int i = 0; i < N; i++)
6366295 0:dab140a197e0 23 {
6366295 0:dab140a197e0 24 analogin_value += salinity_sensor.read();
6366295 0:dab140a197e0 25 }
6366295 0:dab140a197e0 26
joran 6:067e999b9c6e 27 // Average 10 sensor values
joran 6:067e999b9c6e 28 analogin_value /= (float) N;
joran 6:067e999b9c6e 29 voltage = analogin_value * 3.3f * (5.0f/3.0f);
joran 6:067e999b9c6e 30
joran 6:067e999b9c6e 31 return voltage;
joran 6:067e999b9c6e 32 }
joran 6:067e999b9c6e 33
joran 42:e7c726f9c6ed 34 //Convert inputvolt to corrected sensor value
joran 7:8b3aef52aa7b 35 float SalinityController::voltToSensor(float inputvolt)
joran 7:8b3aef52aa7b 36 {
joran 7:8b3aef52aa7b 37 float slope = 0.7931723;
joran 7:8b3aef52aa7b 38 float intercept = 0.0050561;
joran 7:8b3aef52aa7b 39
joran 7:8b3aef52aa7b 40 float offset = (slope * inputvolt) - intercept;
joran 7:8b3aef52aa7b 41
joran 7:8b3aef52aa7b 42 return inputvolt + offset;
joran 7:8b3aef52aa7b 43 }
joran 7:8b3aef52aa7b 44
joran 42:e7c726f9c6ed 45 //Convert corrected sensor value to actual PPT
joran 7:8b3aef52aa7b 46 float SalinityController::sensorToPPT(float inputvolt)
joran 7:8b3aef52aa7b 47 {
joran 7:8b3aef52aa7b 48 float minimum = 0.03778499;
joran 7:8b3aef52aa7b 49 if (inputvolt <= minimum) return 0.00;
joran 7:8b3aef52aa7b 50
joran 7:8b3aef52aa7b 51 float slope = 11.53368;
joran 7:8b3aef52aa7b 52 float intercept = 0.43580;
joran 7:8b3aef52aa7b 53
joran 7:8b3aef52aa7b 54 float ppt = (slope * inputvolt) - intercept;
joran 7:8b3aef52aa7b 55
joran 7:8b3aef52aa7b 56 return ppt;
joran 7:8b3aef52aa7b 57 }
joran 7:8b3aef52aa7b 58
joran 42:e7c726f9c6ed 59 //Chain the needed functions to get the proper PPT
joran 7:8b3aef52aa7b 60 float SalinityController::getAdjustedPPT()
joran 7:8b3aef52aa7b 61 {
joran 7:8b3aef52aa7b 62 return sensorToPPT(voltToSensor(getVoltage()));
joran 7:8b3aef52aa7b 63 }
joran 42:e7c726f9c6ed 64
sbouber1 10:fd4670ec0806 65
sbouber1 11:1a0a8fd74bc0 66 std::string SalinityController::get_name() {
sbouber1 10:fd4670ec0806 67 return "SalinityController";
joran 26:966bad4c6365 68 }
joran 26:966bad4c6365 69
sbouber1 32:1e4919a44196 70
sbouber1 32:1e4919a44196 71