Skip to content

Commit b3d6507

Browse files
committed
add deadzone
1 parent 74d4bbc commit b3d6507

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Firmware/Tasks/Src/FSMTask.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include <math.h>
1919

2020
#define MAX_VELOCITY 12000
21-
#define MAX_CURRENT_PERCENT 100.0f
21+
#define MAX_CURRENT_PERCENT 1.0f
22+
23+
#define ACCEL_DEADZONE_MIN 5u // Minimum 5% pedal pressed to register accel input, prevents ghost inputs :P
2224

2325
StaticEventGroup_t fsmInputBuffer = {0};
2426
EventGroupHandle_t fsmInputGroup = {0};
@@ -143,7 +145,7 @@ static void handle_state_forward(void) {
143145
warning_clear(WARNING_ID_REGEN_NOT_ALLOWED);
144146
velocitySetpoint = MAX_VELOCITY;
145147
currentSetpoint = fmin(apply_swoc_speed_limit(g_data_read->motor_velocity.MC_VehicleVelocity),
146-
apply_rollover_limit(((float)g_data_read->accel_brake.AccelPedal_Main_Pos)/100.0f));
148+
apply_rollover_limit(((float)((g_data_read->accel_brake.AccelPedal_Main_Pos > ACCEL_DEADZONE_MIN) ? g_data_read->accel_brake.AccelPedal_Main_Pos : 0))/100.0f));
147149
}
148150

149151
printf("Forwards Drive cmd: %f vel, %f curr\r\n", velocitySetpoint, currentSetpoint);
@@ -164,7 +166,7 @@ static void handle_state_reverse(void) {
164166
warning_set(WARNING_ID_MOTOR_DIRECTION_CHANGE_LOCKOUT);
165167
} else {
166168
velocitySetpoint = -MAX_VELOCITY;
167-
currentSetpoint = fmin(apply_swoc_speed_limit(g_data_read->motor_velocity.MC_VehicleVelocity), ((float)apply_rollover_limit(g_data_read->accel_brake.AccelPedal_Main_Pos))/100.0f);
169+
currentSetpoint = fmin(apply_swoc_speed_limit(g_data_read->motor_velocity.MC_VehicleVelocity), ((float)apply_rollover_limit(((g_data_read->accel_brake.AccelPedal_Main_Pos > ACCEL_DEADZONE_MIN) ? g_data_read->accel_brake.AccelPedal_Main_Pos : 0)))/100.0f);
168170
}
169171

170172
CAN_Send_Drive_Cmd(velocitySetpoint, currentSetpoint, 0);

0 commit comments

Comments
 (0)