Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement dead zone for controller #2

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions main_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void update_motor_driver_from_control_input( struct bt_hid_state* state )

int left_output = forward_speed;
int right_output = forward_speed;
if( forward_speed > 0 )
if( forward_speed > 20 )
{
if( swerve_right_rate > 0 )
{
Expand All @@ -49,7 +49,7 @@ static void update_motor_driver_from_control_input( struct bt_hid_state* state )
left_output = clamp(left_output, 0, 128);
}
}
else if( forward_speed < 0 )
else if( forward_speed < -20 )
{
if( swerve_right_rate > 0 )
{
Expand All @@ -64,14 +64,19 @@ static void update_motor_driver_from_control_input( struct bt_hid_state* state )
}
else
{
if( swerve_right_rate != 0 )
if( swerve_right_rate >= 20 || swerve_right_rate <= -20 )
{
// rotate in place
// This handles both rotate left and right as left will be negative and right positive
left_output = swerve_right_rate;
right_output = -1*swerve_right_rate;
}
}
else
{
// otherwise no rotation
left_output = 0;
right_output = 0;
}
}

left_output = clamp(left_output, -127, 128);
Expand Down