Sets ticks directly for heater test
Diff: Heater.cpp
- Revision:
- 23:65a9f9d85a3a
- Parent:
- 22:2d34a03ae57e
--- a/Heater.cpp Wed Aug 07 16:03:27 2019 +0000 +++ b/Heater.cpp Mon Aug 12 10:41:37 2019 +0000 @@ -18,13 +18,8 @@ extern DigitalOut led_0; -Heater::Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float corr_grad, const float corr_int, float R_ref) - :R_ref(R_ref),i_port(i_port),v_port(v_port),drive(drive),guard(guard),corr_grad(corr_grad),corr_int(corr_int) {} - - -// Convert from R to T using the linear relationship - T = R * corr_grad + corr_int -float Heater::R_to_T(const float R) const {return R*corr_grad + corr_int;} -float Heater::T_to_R(const float T) const {return (T - corr_int)/corr_grad;} +Heater::Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float intercept, const float slope, float R_ref) + :i_port(i_port),v_port(v_port),drive(drive),guard(guard),intercept(intercept),slope(slope) {} void Heater::output()const { @@ -79,8 +74,6 @@ } - - void Heater::hold(const int hold_time) { //Holds the heater at R_ref for the given hold time @@ -90,8 +83,8 @@ while (timer.read_ms() < end_time) { read(); - drive->write((double) (Kp * (error + error_integrated/Ti))); - guard->write((double) (Kp * GUARD_PWM_RATIO * (error + error_integrated/Ti))); + drive->period_ticks(floor((double) (Kp * (error + error_integrated/Ti)))); + guard->period_ticks((double) (Kp * GUARD_PWM_RATIO * (error + error_integrated/Ti))); //Output the error every LOG_LIM reads log_count++; @@ -125,37 +118,16 @@ } } - -void Heater::ramp_T(const int ramp_time, const float T_final, const float T_start) -{ - //Ramps the heater from T_start to T_final for the given hold time - // in: int hold_time - is the time in ms to hold the reference - // float T_final - is the final T_ref value - // float T_start - is the initial T_ref value - ramp_R(ramp_time, T_to_R(T_final), T_to_R(T_start)); -} - -void Heater::Set_R_ref(float R) +void Heater::Set_R_ref(float R) { R_ref = R; error_integrated = 0; } -void Heater::Set_T_ref(float T_ref) {R_ref = T_to_R(T_ref);} -void Heater::Set_D(float D) {drive->write(D);} - -int Heater::Get_i() const {return curr;} -int Heater::Get_v() const {return v;} - + float Heater::Get_R() const {return R;} -float Heater::Get_T() const {return R_to_T(R);} -void Heater::turn_on () -{ - *drive = 1; - *guard = GUARD_PWM_RATIO; -} void Heater::turn_off () {