Driver for PID control. More...
#include "motor/motor_control.h"
#include "pid/pid.h"
#include "magnetometer/magnetometer.h"
#include "pathfinding/maze.h"
Functions | |
void | pid_bearing_correction (float target_bearing, float current_bearing, pid_params_t *p_pid_params) |
Updates the motor differential ratio based on the target bearing and current bearing. More... | |
float | pid_calculate_correction (float current_bearing, float target_bearing, float current_ratio, pid_params_t *p_pid_params) |
Calculates the PID control signal. More... | |
void | pid_init_error_correction (pid_params_t *p_pid_params) |
Sets defaults for PID parameters. More... | |
void | pid_init_structs (pid_turn_params_t *p_turn_params) |
Sets up pid struct(s). More... | |
void | pid_navigate_turn (pid_turn_params_t *p_turn_params, maze_cardinal_direction_t direction) |
Function to turn the car and move in a given direction. More... | |
Driver for PID control.
void pid_bearing_correction | ( | float | target_bearing, |
float | current_bearing, | ||
pid_params_t * | p_pid_params | ||
) |
Updates the motor differential ratio based on the target bearing and current bearing.
[in] | target_bearing | Target bearing of the car in degrees. |
[out] | current_bearing | Current bearing of the car in degrees. |
[in,out] | p_pid_params | Pointer to the PID parameters. |
References pid_params::current_bearing, pid_params::current_ratio, pid_params::epsilon, magneto_get_curr_bearing(), motor_update_ratio(), PID_BIAS_LEFT_RATIO, pid_calculate_correction(), and pid_params::ratio_to_bearing.
float pid_calculate_correction | ( | float | current_bearing, |
float | target_bearing, | ||
float | current_ratio, | ||
pid_params_t * | p_pid_params | ||
) |
Calculates the PID control signal.
[in] | current_bearing | Current bearing of the car in degrees. |
[in] | target_bearing | Target bearing of the car in degrees. |
[in] | current_ratio | Current motor differential ratio. |
[in,out] | p_pid_params | Pointer to the PID parameters. |
References pid_params::integral, pid_params::k_d, pid_params::k_i, pid_params::k_p, PID_DEGREES_NORMALISE, and pid_params::prev_error.
void pid_init_error_correction | ( | pid_params_t * | p_pid_params | ) |
Sets defaults for PID parameters.
[out] | p_pid_params | Pointer to the PID parameters. |
References pid_params::current_bearing, pid_params::current_ratio, pid_params::epsilon, pid_params::integral, pid_params::k_d, pid_params::k_i, pid_params::k_p, PID_EPSILON, PID_KD, PID_KI, PID_KP, PID_RATIO_TO_BEARING, pid_params::prev_error, pid_params::ratio_to_bearing, and pid_params::setpoint.
void pid_init_structs | ( | pid_turn_params_t * | p_turn_params | ) |
Sets up pid struct(s).
[in,out] | p_turn_params | Pointer to the turn parameters. |
References pid_turn_params::b_is_centered, pid_turn_params::b_is_moved_cell, pid_turn_params::b_is_turn_complete, pid_turn_params::b_is_turning, pid_turn_params::encoder_step_count, and pid_turn_params::turn_direction.
void pid_navigate_turn | ( | pid_turn_params_t * | p_turn_params, |
maze_cardinal_direction_t | direction | ||
) |
Function to turn the car and move in a given direction.
[in,out] | p_turn_params | Pointer to the turn parameters. |
[in] | direction | Direction to turn. |
References pid_turn_params::b_is_centered, pid_turn_params::b_is_moved_cell, pid_turn_params::b_is_turn_complete, pid_turn_params::b_is_turning, pid_turn_params::encoder_step_count, MAZE_EAST, MAZE_SOUTH, MAZE_WEST, motor_move_forward(), motor_turn_left(), motor_turn_right(), PID_ENCODER_CENTER_OFFSET, PID_ENCODER_STEP_MOVE, PID_ENCODER_STEP_TURN_180_DEG, PID_ENCODER_STEP_TURN_90_DEG, and pid_init_structs().