Skip to content

Commit

Permalink
add no_os_pid_reset
Browse files Browse the repository at this point in the history
Useful if one wants to start the control again without performing
init/remove.

It clears the integral and derivative accumulators.

Signed-off-by: Darius Berghe <[email protected]>
  • Loading branch information
buha authored and rbolboac committed Mar 7, 2024
1 parent 9514276 commit e203504
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/no_os_pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct no_os_pid;
int no_os_pid_init(struct no_os_pid **pid, struct no_os_pid_config config);
int no_os_pid_control(struct no_os_pid *pid, int SP, int PV, int *output);
int no_os_pid_hysteresis(struct no_os_pid *pid, unsigned int hyst);
int no_os_pid_reset(struct no_os_pid *pid);
int no_os_pid_remove(struct no_os_pid *pid);

#endif
18 changes: 18 additions & 0 deletions util/no_os_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ int no_os_pid_hysteresis(struct no_os_pid *pid, unsigned int hyst)
return 0;
}

/**
* @brief Reset internal accumulators, useful when the same pid descriptor is used to start over.
* @param pid - PID descriptor created with no_os_pid_init()
* @return
* - 0 : On success
* - -EINVAL : Invalid input
*/
int no_os_pid_reset(struct no_os_pid *pid)
{
if (!pid)
return -EINVAL;

pid->iacc = 0;
pid->dacc = 0;

return 0;
}

/**
* @brief De-initialize a PID controller by freeing the allocated memory
* @param pid - PID descriptor created with no_os_pid_init()
Expand Down

0 comments on commit e203504

Please sign in to comment.