For coursework of group 3 in SOFT564Z

Dependencies:   Motordriver ros_lib_kinetic

Committer:
Jonathan738
Date:
Sun Jan 05 15:42:22 2020 +0000
Revision:
12:82b8fe254222
Parent:
11:0b9098ec11c7
Added working version of TOF code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jonathan738 4:8afc50a3e4ac 1 #include "mbed.h"
Jonathan738 4:8afc50a3e4ac 2 #include "Debug.hpp"
Jonathan738 3:7da9888ac8dc 3 #include "Battery_Monitor.hpp"
Jonathan738 3:7da9888ac8dc 4 #include "General.hpp"
Jonathan738 4:8afc50a3e4ac 5 #include "Pins.h"
Jonathan738 11:0b9098ec11c7 6 #include "rtos.h"
Jonathan738 11:0b9098ec11c7 7
Jonathan738 11:0b9098ec11c7 8 //extern Mutex Global_Battery_Level_Mutex;
Jonathan738 11:0b9098ec11c7 9 //extern float Global_Battery_Level;
Jonathan738 11:0b9098ec11c7 10 //extern float Global_Battery_Value;
Jonathan738 11:0b9098ec11c7 11
Jonathan738 11:0b9098ec11c7 12 float Global_Battery_Level;
Jonathan738 11:0b9098ec11c7 13 float Global_Battery_Value;
Jonathan738 11:0b9098ec11c7 14 bool Battery_Update_Flag;
Jonathan738 11:0b9098ec11c7 15 Mutex Global_Battery_Level_Mutex;
firnenenrif 2:b9a495b330fd 16
Jonathan738 4:8afc50a3e4ac 17 void Battery_Monitor::battCheck(void)
Jonathan738 3:7da9888ac8dc 18 {
Jonathan738 12:82b8fe254222 19 float Read_V_Batt = this->V_Batt.read() * 16.67f;
Jonathan738 4:8afc50a3e4ac 20
Jonathan738 4:8afc50a3e4ac 21 float temp_batLev = Read_V_Batt - Minimum_VBatt;
Jonathan738 4:8afc50a3e4ac 22 this->Battery_Level = (Maximum_VBatt - Minimum_VBatt) / temp_batLev;
Jonathan738 11:0b9098ec11c7 23
Jonathan738 11:0b9098ec11c7 24 Global_Battery_Level_Mutex.lock();
Jonathan738 12:82b8fe254222 25 Global_Battery_Value = Read_V_Batt;
Jonathan738 12:82b8fe254222 26 Global_Battery_Level = this->Battery_Level;
Jonathan738 11:0b9098ec11c7 27 if(Battery_Update_Flag == false)
Jonathan738 11:0b9098ec11c7 28 {
Jonathan738 11:0b9098ec11c7 29 Battery_Update_Flag = true;
Jonathan738 11:0b9098ec11c7 30 }
Jonathan738 11:0b9098ec11c7 31 Global_Battery_Level_Mutex.unlock();
Jonathan738 11:0b9098ec11c7 32
Jonathan738 11:0b9098ec11c7 33 /*
Jonathan738 4:8afc50a3e4ac 34 Channel_1.write(this->Battery_Level);
Jonathan738 4:8afc50a3e4ac 35 Channel_2.write(1.0f-(this->Battery_Level));
firnenenrif 2:b9a495b330fd 36
Jonathan738 7:2796f0b5228d 37 char Btry_lvl_string[20];
Jonathan738 7:2796f0b5228d 38 sprintf(Btry_lvl_string, "Battery Level is : %1.2f",Battery_Level);
Jonathan738 7:2796f0b5228d 39 Flag_Error(warning, Btry_lvl_string);
Jonathan738 7:2796f0b5228d 40
Jonathan738 4:8afc50a3e4ac 41 if(this->Battery_Level < 0.2f && this->Battery_Level > 0.1f)
Jonathan738 4:8afc50a3e4ac 42 {
Jonathan738 4:8afc50a3e4ac 43 Flag_Error(warning, "Power Below 20% - Charging Required!\n\r");
Jonathan738 4:8afc50a3e4ac 44 } else if(this->Battery_Level < 0.05f) {
Jonathan738 4:8afc50a3e4ac 45 Flag_Error(criticalFAILURE, "Power Below 5% - Power Failure Iminent!\n\r");
Jonathan738 4:8afc50a3e4ac 46 }
Jonathan738 11:0b9098ec11c7 47 */
Jonathan738 4:8afc50a3e4ac 48 //pc.printf("Voltage readings are: VBATT: %f\n\r", Read_V_Batt);
Jonathan738 4:8afc50a3e4ac 49 }