For coursework of group 3 in SOFT564Z

Dependencies:   Motordriver ros_lib_kinetic

Committer:
Jonathan738
Date:
Thu Dec 19 00:13:38 2019 +0000
Revision:
11:0b9098ec11c7
Parent:
7:2796f0b5228d
Child:
12:82b8fe254222
Fixed several bugs, added status information and TOF data to ROS Topics

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 4:8afc50a3e4ac 19 float Read_V_Batt = this->V_Batt.read();
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
Jonathan738 11:0b9098ec11c7 25 Global_Battery_Level_Mutex.lock();
Jonathan738 11:0b9098ec11c7 26 Global_Battery_Level = Read_V_Batt;
Jonathan738 11:0b9098ec11c7 27 Global_Battery_Value = this->Battery_Level;
Jonathan738 11:0b9098ec11c7 28 if(Battery_Update_Flag == false)
Jonathan738 11:0b9098ec11c7 29 {
Jonathan738 11:0b9098ec11c7 30 Battery_Update_Flag = true;
Jonathan738 11:0b9098ec11c7 31 }
Jonathan738 11:0b9098ec11c7 32 Global_Battery_Level_Mutex.unlock();
Jonathan738 11:0b9098ec11c7 33
Jonathan738 11:0b9098ec11c7 34 /*
Jonathan738 4:8afc50a3e4ac 35 Channel_1.write(this->Battery_Level);
Jonathan738 4:8afc50a3e4ac 36 Channel_2.write(1.0f-(this->Battery_Level));
firnenenrif 2:b9a495b330fd 37
Jonathan738 7:2796f0b5228d 38 char Btry_lvl_string[20];
Jonathan738 7:2796f0b5228d 39 sprintf(Btry_lvl_string, "Battery Level is : %1.2f",Battery_Level);
Jonathan738 7:2796f0b5228d 40 Flag_Error(warning, Btry_lvl_string);
Jonathan738 7:2796f0b5228d 41
Jonathan738 4:8afc50a3e4ac 42 if(this->Battery_Level < 0.2f && this->Battery_Level > 0.1f)
Jonathan738 4:8afc50a3e4ac 43 {
Jonathan738 4:8afc50a3e4ac 44 Flag_Error(warning, "Power Below 20% - Charging Required!\n\r");
Jonathan738 4:8afc50a3e4ac 45 } else if(this->Battery_Level < 0.05f) {
Jonathan738 4:8afc50a3e4ac 46 Flag_Error(criticalFAILURE, "Power Below 5% - Power Failure Iminent!\n\r");
Jonathan738 4:8afc50a3e4ac 47 }
Jonathan738 11:0b9098ec11c7 48 */
Jonathan738 4:8afc50a3e4ac 49 //pc.printf("Voltage readings are: VBATT: %f\n\r", Read_V_Batt);
Jonathan738 4:8afc50a3e4ac 50 }