From 2238ffa9f34c572a8789bc8d6e84f380cd2b929a Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Tue, 19 Dec 2023 18:26:46 +0900 Subject: [PATCH] Store max value in DriverState --- tfrog-motordriver/controlPWM.c | 11 +++++------ tfrog-motordriver/controlVelocity.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tfrog-motordriver/controlPWM.c b/tfrog-motordriver/controlPWM.c index 7c46818..d91a628 100644 --- a/tfrog-motordriver/controlPWM.c +++ b/tfrog-motordriver/controlPWM.c @@ -56,13 +56,12 @@ int32_t PWM_resolution = 0; int32_t PWM_thinning = 0; int32_t PWM_deadtime; int32_t PWM_cpms; -int32_t brake_cnt_max; void FIQ_PWMPeriod() RAMFUNC; void soft_brake(const int m) { - if (brake_cnt_max == 0) + if (driver_state.brake_cnt_max == 0) { for (int8_t i = 0; i < 3; i++) { @@ -72,16 +71,16 @@ void soft_brake(const int m) return; } - const int32_t pwm = PWM_resolution * motor[m].brake_cnt / brake_cnt_max; + const int32_t pwm = PWM_resolution * motor[m].brake_cnt / driver_state.brake_cnt_max; for (int8_t i = 0; i < 3; i++) { THEVA.MOTOR[m].PWM[i].H = PWM_resolution; THEVA.MOTOR[m].PWM[i].L = pwm; } motor[m].brake_cnt++; - if (motor[m].brake_cnt > brake_cnt_max) + if (motor[m].brake_cnt > driver_state.brake_cnt_max) { - motor[m].brake_cnt = brake_cnt_max; + motor[m].brake_cnt = driver_state.brake_cnt_max; } } @@ -692,7 +691,7 @@ void controlPWM_init() THEVA.GENERAL.PWM.HALF_PERIOD = PWM_resolution; THEVA.GENERAL.PWM.DEADTIME = PWM_deadtime; - brake_cnt_max = + driver_state.brake_cnt_max = 48000 * (int32_t)saved_param.soft_brake_ms / (PWM_resolution * 2 * (PWM_thinning + 1)); diff --git a/tfrog-motordriver/controlVelocity.h b/tfrog-motordriver/controlVelocity.h index 1be41d8..8c14c00 100644 --- a/tfrog-motordriver/controlVelocity.h +++ b/tfrog-motordriver/controlVelocity.h @@ -180,6 +180,7 @@ typedef struct _DriverState uint32_t ping_request; uint32_t odom_drop; int32_t vsrc_max; + int32_t brake_cnt_max; } DriverState; #ifdef static_assert