diff --git a/firmware/src/hw/cc_driver.cpp b/firmware/src/hw/cc_driver.cpp deleted file mode 100644 index 0c88a36..0000000 --- a/firmware/src/hw/cc_driver.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**** Includes ****/ -#include "../utils/utils.h" -#include "../utils/interpolate.h" -#include "potentiometer.h" - -using namespace hw; - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ - -/**** Public function definitions ****/ -hw::Potentiometer::Potentiometer(board::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone) -{ - this->ain_ch = ain_ch; - this->low_deadzone = low_deadzone; - this->high_deadzone = high_deadzone; - this->percent = 0; -} - -hw::Potentiometer::~Potentiometer(void) -{ - return; -} - -uint8_t hw::Potentiometer::read(void) -{ - // Update input - this->ain_ch->read(); - - // Calculate percent - this->percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100); - - return this->percent; -} - -/**** Private function definitions ****/ diff --git a/firmware/src/hw/cc_driver.h b/firmware/src/hw/cc_driver.h deleted file mode 100644 index 834c8c2..0000000 --- a/firmware/src/hw/cc_driver.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CONST_CURRENT_DRIVER_H_ -#define CONST_CURRENT_DRIVER_H_ - -/**** Includes ****/ -#include -#include "../board/ain.h" -#include "../board/halfbridge.h" - -namespace hw { - -/**** Public definitions ****/ - -class CCdriver -{ - protected: - board::AnalogIn* sup_voltage; - board::AnalogIn* sup_current; - board::AnalogIn* ain_ch; - board::AnalogIn* ain_ch; - - public: - CCdriver(board::AnalogIn* ain_ch); - ~CCdriver(void); -}; - -/**** Public function declarations ****/ - -#ifdef TESTING -#endif - -} //namespace - -#endif /* CONST_CURRENT_DRIVER_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/cv_driver.cpp b/firmware/src/hw/cv_driver.cpp new file mode 100644 index 0000000..734d8eb --- /dev/null +++ b/firmware/src/hw/cv_driver.cpp @@ -0,0 +1,40 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "cv_driver.h" + +using namespace hw; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ + +/**** Public function definitions ****/ +hw::CVdriver::CVdriver(board::AnalogIn* sup_voltage, board::AnalogIn* out_voltage, board::Hafbridge* hbridge) +{ + this->sup_voltage = sup_voltage; + this->hbridge = hbridge; + this->target = 0; + this->off = 1; +} + +hw::CVdriver::~CVdriver(void) +{ + return; +} + +void hw::CVdriver::update(void) +{ + // Update all inputs + this->sup_voltage->read(); + + // Calculate ratio + uint16_t ratio = util::sat_ratio(this->target, this->sup_voltage->last_read); + + // Set output + this->hbridge->write(ratio); +} + + + +/**** Private function definitions ****/ diff --git a/firmware/src/hw/cv_driver.h b/firmware/src/hw/cv_driver.h new file mode 100644 index 0000000..a39e357 --- /dev/null +++ b/firmware/src/hw/cv_driver.h @@ -0,0 +1,37 @@ +#ifndef CONST_VOLTAGE_DRIVER_H_ +#define CONST_VOLTAGE_DRIVER_H_ + +/**** Includes ****/ +#include +#include "../board/ain.h" +#include "../board/halfbridge.h" + +namespace hw { + +/**** Public definitions ****/ + +class CVdriver +{ + protected: + board::AnalogIn* sup_voltage; + + board::Hafbridge* hbridge; + + public: + CVdriver(board::AnalogIn* sup_voltage, board::Hafbridge* hbridge); + ~CVdriver(void); + + uint16_t target = 0; + uint8_t off = 0; + + void process(void); +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* CONST_VOLTAGE_DRIVER_H_ */ \ No newline at end of file diff --git a/firmware/src/uDCCD.cppproj b/firmware/src/uDCCD.cppproj index 1b21809..7601bb2 100644 --- a/firmware/src/uDCCD.cppproj +++ b/firmware/src/uDCCD.cppproj @@ -204,10 +204,10 @@ compile - + compile - + compile