Skip to content

Commit 1799af0

Browse files
committed
pbio/integrator: Simplify position integrator state.
This changes the used integral value to be one-step-ahead instead of returning the previous error. This makes little difference in the overal output (it marginally changes the proportional term), but makes it easier to adjust the range limits on the current error instead of the previous error. That is, the position error and the target error are now from the same time stamp. Also removes one state value which was no longer used.
1 parent 7223631 commit 1799af0

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

lib/pbio/include/pbio/integrator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ typedef struct _pbio_position_integrator_t {
3636
bool trajectory_running; // Whether the trajectory is running (1) or paused (0)
3737
uint32_t time_pause_begin; // Time at which we began pausing most recently, stopping integration
3838
uint32_t time_paused_total; // Total time we spent in a paused state
39-
int32_t count_err_prev; // Position error in the previous control iteration
4039
int32_t count_err_integral; // Ongoing integral of position error
41-
int32_t count_err_integral_max; // Maximum value of integrator
4240
pbio_control_settings_t *settings; // Control settings, which includes integrator settings.
4341
} pbio_position_integrator_t;
4442

lib/pbio/src/integrator.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ void pbio_position_integrator_reset(pbio_position_integrator_t *itg, pbio_contro
143143
itg->count_err_integral = 0;
144144
itg->time_paused_total = 0;
145145
itg->time_pause_begin = time_now;
146-
itg->count_err_prev = 0;
147146
itg->trajectory_running = false;
148147

149148
// Resume integration
@@ -153,8 +152,7 @@ void pbio_position_integrator_reset(pbio_position_integrator_t *itg, pbio_contro
153152

154153
int32_t pbio_position_integrator_update(pbio_position_integrator_t *itg, int32_t position_error, int32_t target_error) {
155154

156-
// Previous error will be multiplied by time delta and then added to integral (unless we limit growth)
157-
int32_t error_now = itg->count_err_prev;
155+
int32_t error_now = position_error;
158156

159157
// Check if integrator magnitude would decrease due to this error
160158
bool decrease = pbio_int_math_abs(itg->count_err_integral + pbio_control_settings_mul_by_loop_time(error_now)) < pbio_int_math_abs(itg->count_err_integral);
@@ -187,9 +185,7 @@ int32_t pbio_position_integrator_update(pbio_position_integrator_t *itg, int32_t
187185
pbio_control_settings_div_by_gain(itg->settings->actuation_max, itg->settings->pid_ki));
188186
}
189187

190-
// Keep the error for use in next update
191-
itg->count_err_prev = position_error;
192-
188+
// Return current value.
193189
return itg->count_err_integral;
194190
}
195191

0 commit comments

Comments
 (0)