@@ -10,8 +10,6 @@ void trajectoryResetTrapezoidal(TrapezoidalProfileState& state,
1010 float target_position) {
1111 state.position = current_position;
1212 state.velocity = current_velocity;
13- state.acceleration = 0 .0f ;
14- state.target = target_position;
1513 state.initialized = true ;
1614}
1715// Bang-bang acceleration control with trapezoidal velocity profile
@@ -36,20 +34,18 @@ TrapezoidalProfileOutput trajectoryStepTrapezoidal(TrapezoidalProfileState& stat
3634 if (!state.initialized ) {
3735 trajectoryResetTrapezoidal (state, current_position, current_velocity, target_position);
3836 }
39- state.target = target_position;
4037
4138 // Disabled acceleration limit means direct target snap.
4239 if (!_isset (acceleration_abs_limit) || acceleration_abs_limit <= 0 .0f ) {
43- state.position = state. target ;
40+ state.position = target_position ;
4441 state.velocity = 0 .0f ;
45- state.acceleration = 0 .0f ;
4642 out.position = state.position ;
4743 out.velocity = state.velocity ;
48- out.acceleration = state. acceleration ;
44+ out.acceleration = 0 . 0f ;
4945 return out;
5046 }
5147
52- float position_error = state. target - state.position ;
48+ float position_error = target_position - state.position ;
5349 float direction_to_target = _sign (position_error);
5450 float commanded_accel = 0 .0f ;
5551 float distance_remaining = fabsf (position_error);
@@ -63,7 +59,7 @@ TrapezoidalProfileOutput trajectoryStepTrapezoidal(TrapezoidalProfileState& stat
6359
6460 // If nearly at target and almost stopped, finalize immediately.
6561 if (distance_remaining < 1e-6f && speed_magnitude < (acceleration_abs_limit * dt)) {
66- state.position = state. target ;
62+ state.position = target_position ;
6763 state.velocity = 0 .0f ;
6864 commanded_accel = 0 .0f ;
6965 } else {
@@ -92,17 +88,16 @@ TrapezoidalProfileOutput trajectoryStepTrapezoidal(TrapezoidalProfileState& stat
9288 float position_step = state.velocity * dt;
9389 if (fabsf (position_error) <= fabsf (position_step)) {
9490 // Clamp final step to avoid overshoot around the endpoint.
95- state.position = state. target ;
91+ state.position = target_position ;
9692 state.velocity = 0 .0f ;
9793 commanded_accel = 0 .0f ;
9894 } else {
9995 state.position += position_step;
10096 }
10197 }
10298
103- state .acceleration = commanded_accel;
99+ out .acceleration = commanded_accel;
104100 out.position = state.position ;
105101 out.velocity = state.velocity ;
106- out.acceleration = state.acceleration ;
107102 return out;
108103}
0 commit comments