#include <kern/global.h>
Data Structures | |
struct | pid_controller |
Functions | |
void | init_pid (struct pid_controller *pid, float kp, float ki, float kd, float(*input)(), void(*output)(float value)) |
float | update_pid_input (struct pid_controller *pid, float current_val) |
float | update_pid (struct pid_controller *pid) |
uint8_t | dispatch_pid (struct pid_controller *pid, float tolerance, uint8_t(*stop)()) |
A Common use in robotics (especially in 6.270) is the position control of a motor. In this case the process variable is the wheels angular position, and the setpoint is a desired target position (eg: 720 degrees, or two wheel rotations forward). The wheel position is measured with shaft encoders and the motor is commanded by the PID controller to compensate for the error between the current wheel position and the desired goal.
This allows the user to command a desired amount of wheel rotation (and hence distance travelled). With a PID controller on each wheel the user can perform reasonably accurate motions (straight lines, in place turns, etc).
For more information see http://en.wikipedia.org/wiki/PID_controller
uint8_t dispatch_pid | ( | struct pid_controller * | pid, | |
float | tolerance, | |||
uint8_t(*)() | stop | |||
) |
Dispatch to a routine that will drive the PID system until the output equals the goal within tolerance. This routine blocks and only returns when done or 'stop' is non-zero and returns non-zero.
pid | PID controller | |
tolerance | how close to get towards the goal | |
stop | return when stop() is true |
void init_pid | ( | struct pid_controller * | pid, | |
float | kp, | |||
float | ki, | |||
float | kd, | |||
float(*)() | input, | |||
void(*)(float value) | output | |||
) |
Initialize a PID controller structure. This function takes an empty pid_controller structure and initializes its member variables.
pid | empty PID to initialize | |
kp | proportional constant | |
ki | integral constant | |
kd | derivative constant | |
input | input function | |
output | output function |
float update_pid | ( | struct pid_controller * | pid | ) |
Perform a single step of the PID loop. The update_pid() steps are as follows:
pid | PID controller |
float update_pid_input | ( | struct pid_controller * | pid, | |
float | current_val | |||
) |
Perform a single step of the PID loop. like update_pid() except takes a current value as an argument
pid | PID controller | |
current_val | Current control value |