Wrap motor control error between -180 and 180
This commit is contained in:
parent
96013a465c
commit
860805cbef
|
@ -29,6 +29,9 @@ void i2c_update_motion_control(void)
|
||||||
float target_angle_radian = target_angle / 180.0f * M_PI;
|
float target_angle_radian = target_angle / 180.0f * M_PI;
|
||||||
|
|
||||||
float error = target_angle - actual_angle;
|
float error = target_angle - actual_angle;
|
||||||
|
if(error > 180) error -= 360;
|
||||||
|
if(error < -180) error += 360;
|
||||||
|
|
||||||
float correction = error * GAIN_KD;
|
float correction = error * GAIN_KD;
|
||||||
|
|
||||||
float target_x_axis_speed = cosf(target_angle_radian) * robot.motion_control_data.x_axis_speed +
|
float target_x_axis_speed = cosf(target_angle_radian) * robot.motion_control_data.x_axis_speed +
|
||||||
|
|
Loading…
Reference in New Issue