For coursework of group 3 in SOFT564Z

Dependencies:   Motordriver ros_lib_kinetic

Committer:
Jonathan738
Date:
Sat Nov 30 10:59:09 2019 +0000
Revision:
4:8afc50a3e4ac
Parent:
3:7da9888ac8dc
Child:
7:2796f0b5228d
Added Debug code, re-factored existing 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"
firnenenrif 2:b9a495b330fd 6
Jonathan738 4:8afc50a3e4ac 7 void Battery_Monitor::battCheck(void)
Jonathan738 3:7da9888ac8dc 8 {
Jonathan738 4:8afc50a3e4ac 9 float Read_V_Batt = this->V_Batt.read();
Jonathan738 4:8afc50a3e4ac 10
Jonathan738 4:8afc50a3e4ac 11 float temp_batLev = Read_V_Batt - Minimum_VBatt;
Jonathan738 4:8afc50a3e4ac 12 this->Battery_Level = (Maximum_VBatt - Minimum_VBatt) / temp_batLev;
Jonathan738 4:8afc50a3e4ac 13
Jonathan738 4:8afc50a3e4ac 14 Channel_1.write(this->Battery_Level);
Jonathan738 4:8afc50a3e4ac 15 Channel_2.write(1.0f-(this->Battery_Level));
firnenenrif 2:b9a495b330fd 16
Jonathan738 4:8afc50a3e4ac 17 if(this->Battery_Level < 0.2f && this->Battery_Level > 0.1f)
Jonathan738 4:8afc50a3e4ac 18 {
Jonathan738 4:8afc50a3e4ac 19 Flag_Error(warning, "Power Below 20% - Charging Required!\n\r");
Jonathan738 4:8afc50a3e4ac 20 } else if(this->Battery_Level < 0.05f) {
Jonathan738 4:8afc50a3e4ac 21 Flag_Error(criticalFAILURE, "Power Below 5% - Power Failure Iminent!\n\r");
Jonathan738 4:8afc50a3e4ac 22 }
Jonathan738 4:8afc50a3e4ac 23 //pc.printf("Voltage readings are: VBATT: %f\n\r", Read_V_Batt);
Jonathan738 4:8afc50a3e4ac 24 }