For coursework of group 3 in SOFT564Z
Dependencies: Motordriver ros_lib_kinetic
Diff: Battery_Monitor.cpp
- Revision:
- 4:8afc50a3e4ac
- Parent:
- 3:7da9888ac8dc
- Child:
- 7:2796f0b5228d
--- a/Battery_Monitor.cpp Thu Nov 28 13:36:44 2019 +0000 +++ b/Battery_Monitor.cpp Sat Nov 30 10:59:09 2019 +0000 @@ -1,26 +1,24 @@ +#include "mbed.h" +#include "Debug.hpp" #include "Battery_Monitor.hpp" #include "General.hpp" +#include "Pins.h" -Ticker BattCheck; -AnalogIn v_bat(PB_1); -AnalogIn v_5(PC_2); -AnalogIn v_3(PF_4); - -void battCheck(void); - -void initBattCheck(void) +void Battery_Monitor::battCheck(void) { -BattCheck.attach(&battCheck, 1.0); - while(1) - { - Thread::wait(500); - } -} + float Read_V_Batt = this->V_Batt.read(); + + float temp_batLev = Read_V_Batt - Minimum_VBatt; + this->Battery_Level = (Maximum_VBatt - Minimum_VBatt) / temp_batLev; + + Channel_1.write(this->Battery_Level); + Channel_2.write(1.0f-(this->Battery_Level)); -void battCheck(void) -{ - float analogue5V = v_5.read(); - float analogue33V = v_3.read(); - float analogueValue = v_bat.read(); - //.printf("Voltage readings are: VBATT: %f 5V0: %f 3V3: %f\n\r", analogueValue, analogue5V, analogue33V); -} \ No newline at end of file + if(this->Battery_Level < 0.2f && this->Battery_Level > 0.1f) + { + Flag_Error(warning, "Power Below 20% - Charging Required!\n\r"); + } else if(this->Battery_Level < 0.05f) { + Flag_Error(criticalFAILURE, "Power Below 5% - Power Failure Iminent!\n\r"); + } + //pc.printf("Voltage readings are: VBATT: %f\n\r", Read_V_Batt); +}