Skip to content

Commit

Permalink
remove redundant max value
Browse files Browse the repository at this point in the history
  • Loading branch information
v923z committed Feb 20, 2024
1 parent a765c35 commit c3b541f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 4 additions & 3 deletions code/pid/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pid_pid_offset_obj, 2, 3, pid_pid_offset);


static mp_float_t pid_pid_convert(pid_series_t series, mp_float_t x) {

// taking the coefficients of the Taylor expansion, returns the
// approximate value of a function at the value x
mp_float_t dx = x - series.x0;
mp_float_t *coeffs = (mp_float_t *)series.coeffs;
mp_float_t y = *coeffs++;
Expand Down Expand Up @@ -348,14 +349,14 @@ mp_obj_t pid_pid_step(mp_obj_t _self) {
// TODO: get system time here!
mp_float_t t = self->last_time + 1.0;
pid_pid_loop(self, value, t);

// convert value in output buffer
value = pid_pid_convert(self->out.series, self->output);
// ensure that output is within limits

if(self->out.buffer.bitdepth != 0) {
value = (value < 0 ? 0 : value);
value = (value > self->max ? self->max: value);
value = (value > (mp_float_t)self->out.buffer.mask ? (mp_float_t)self->out.buffer.mask : value);
}

uint32_t output = ((uint32_t)value) & self->out.buffer.mask;
Expand Down
1 change: 0 additions & 1 deletion code/pid/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ typedef struct _pid_obj_t {
mp_float_t value; // the last converted value supplied to the loop
mp_float_t error; // the last calculated error; the difference between value and set_point
mp_float_t last_time; // the last time the loop was advanced
mp_float_t max; // the maximum allowed output value; calculated, if out.buffer.bitdepth is given
uint64_t steps;
} pid_obj_t;

Expand Down

0 comments on commit c3b541f

Please sign in to comment.