INF2004-Project v0.1
 
Loading...
Searching...
No Matches
pid.c File Reference

Driver for PID control. More...

Include dependency graph for pid.c:

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...
 

Detailed Description

Driver for PID control.

Author
Bryan Seah
Version
0.1
Date
2023-10-29

Function Documentation

◆ pid_bearing_correction()

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.

Parameters
[in]target_bearingTarget bearing of the car in degrees.
[out]current_bearingCurrent bearing of the car in degrees.
[in,out]p_pid_paramsPointer 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.

Here is the call graph for this function:

◆ pid_calculate_correction()

float pid_calculate_correction ( float  current_bearing,
float  target_bearing,
float  current_ratio,
pid_params_t p_pid_params 
)

Calculates the PID control signal.

Parameters
[in]current_bearingCurrent bearing of the car in degrees.
[in]target_bearingTarget bearing of the car in degrees.
[in]current_ratioCurrent motor differential ratio.
[in,out]p_pid_paramsPointer to the PID parameters.
Returns
float Control signal.

References pid_params::integral, pid_params::k_d, pid_params::k_i, pid_params::k_p, PID_DEGREES_NORMALISE, and pid_params::prev_error.

Here is the caller graph for this function:

◆ pid_init_error_correction()

void pid_init_error_correction ( pid_params_t p_pid_params)

◆ pid_init_structs()

void pid_init_structs ( pid_turn_params_t p_turn_params)

Sets up pid struct(s).

Parameters
[in,out]p_turn_paramsPointer 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.

Here is the caller graph for this function:

◆ pid_navigate_turn()

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.

Parameters
[in,out]p_turn_paramsPointer to the turn parameters.
[in]directionDirection 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().

Here is the call graph for this function:
Here is the caller graph for this function: