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:
4:8afc50a3e4ac
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 3:7da9888ac8dc 1 #include "mbed.h"
Jonathan738 4:8afc50a3e4ac 2 #include "General.hpp"
Jonathan738 4:8afc50a3e4ac 3 #include "Pins.h"
Jonathan738 11:0b9098ec11c7 4 #include "rtos.h"
Jonathan738 4:8afc50a3e4ac 5
Jonathan738 4:8afc50a3e4ac 6 #define Minimum_VBatt 3.6f
Jonathan738 4:8afc50a3e4ac 7 #define Maximum_VBatt 5.0f
Jonathan738 4:8afc50a3e4ac 8 #define PWM_Freq 200.0f
Jonathan738 4:8afc50a3e4ac 9
Jonathan738 4:8afc50a3e4ac 10 #ifndef Define_ONCE_Battery_Monitoring
Jonathan738 4:8afc50a3e4ac 11 #define Define_ONCE_Battery_Monitoring
Jonathan738 3:7da9888ac8dc 12
Jonathan738 4:8afc50a3e4ac 13 class Battery_Monitor
Jonathan738 4:8afc50a3e4ac 14 {
Jonathan738 4:8afc50a3e4ac 15 public:
Jonathan738 11:0b9098ec11c7 16 Battery_Monitor(PinName Batt_PIN, int sample_Freq): V_Batt(Batt_PIN), Sample_Freq(sample_Freq) //(PinName Batt_PIN, int sample_Freq, PinName RED_Channel, PinName GREEN_Channel, PinName BLUE_Channel): V_Batt(Batt_PIN), Sample_Freq(sample_Freq), Channel_1(RED_Channel), Channel_2(GREEN_Channel), Channel_3(BLUE_Channel)
Jonathan738 4:8afc50a3e4ac 17 {
Jonathan738 11:0b9098ec11c7 18 /*
Jonathan738 4:8afc50a3e4ac 19 this->Channel_1.write(0.0f);
Jonathan738 4:8afc50a3e4ac 20 this->Channel_1.period(1.0f/PWM_Freq);
Jonathan738 4:8afc50a3e4ac 21 this->Channel_2.write(0.0f);
Jonathan738 4:8afc50a3e4ac 22 this->Channel_2.period(1.0f/PWM_Freq);
Jonathan738 4:8afc50a3e4ac 23 this->Channel_3.write(0.0f);
Jonathan738 4:8afc50a3e4ac 24 this->Channel_3.period(1.0f/PWM_Freq);
Jonathan738 11:0b9098ec11c7 25 */
Jonathan738 4:8afc50a3e4ac 26
Jonathan738 4:8afc50a3e4ac 27 this->BattCheck.attach(this, &Battery_Monitor::battCheck, 1/Sample_Freq);
Jonathan738 4:8afc50a3e4ac 28 };
Jonathan738 4:8afc50a3e4ac 29
Jonathan738 4:8afc50a3e4ac 30 float GetBatteryLevel(void)
Jonathan738 4:8afc50a3e4ac 31 {
Jonathan738 4:8afc50a3e4ac 32 return Battery_Level;
Jonathan738 4:8afc50a3e4ac 33 }
Jonathan738 4:8afc50a3e4ac 34
Jonathan738 4:8afc50a3e4ac 35 private:
Jonathan738 4:8afc50a3e4ac 36 void battCheck(void);
Jonathan738 4:8afc50a3e4ac 37 int Sample_Freq;
Jonathan738 4:8afc50a3e4ac 38
Jonathan738 4:8afc50a3e4ac 39 float Battery_Level;
Jonathan738 4:8afc50a3e4ac 40
Jonathan738 4:8afc50a3e4ac 41 Ticker BattCheck;
Jonathan738 4:8afc50a3e4ac 42 AnalogIn V_Batt;
Jonathan738 4:8afc50a3e4ac 43
Jonathan738 11:0b9098ec11c7 44 /*
Jonathan738 4:8afc50a3e4ac 45 PwmOut Channel_1;
Jonathan738 4:8afc50a3e4ac 46 PwmOut Channel_2;
Jonathan738 4:8afc50a3e4ac 47 PwmOut Channel_3;
Jonathan738 11:0b9098ec11c7 48 */
Jonathan738 4:8afc50a3e4ac 49 };
Jonathan738 3:7da9888ac8dc 50
Jonathan738 3:7da9888ac8dc 51 #endif