Zap'Em Blast'Em Robots
robots that play laser tag!
Loading...
Searching...
No Matches
controller_task.c File Reference

Implements controller task state machine for robot motor control. More...

#include "motor_driver.h"
#include "controller_task.h"
#include "stm32f4xx_hal_tim.h"
#include "encoder_driver.h"
#include <stdio.h>

Typedefs

typedef void(* StateFunc) (ControllerTask *)
 Function pointer type for controller state functions.

Functions

void controller_task_run (ControllerTask *controller_task)
 Executes the current state of the controller task.
void controller_task_state_0_init (ControllerTask *controller_task)
 Initializes the controller task (State 0).
void controller_task_state_1_pos (ControllerTask *controller_task)
 Executes position control logic (State 1).

Detailed Description

Implements controller task state machine for robot motor control.

Author
Kai De La Cruz

Created on: Jun 3, 2025

Function Documentation

◆ controller_task_run()

void controller_task_run ( ControllerTask * controller_task)

Executes the current state of the controller task.

Validates the current state index and calls the appropriate state function from the task's function list.

Parameters
controller_taskPointer to the ControllerTask structure.

◆ controller_task_state_0_init()

void controller_task_state_0_init ( ControllerTask * controller_task)

Initializes the controller task (State 0).

Enables the motor, records the potentiometer's zero point, and sets the task to the next state.

Parameters
controller_taskPointer to the ControllerTask structure.

◆ controller_task_state_1_pos()

void controller_task_state_1_pos ( ControllerTask * controller_task)

Executes position control logic (State 1).

Executes the position control logic (State 1).

Calculates desired position and error from encoder data and ADC input, then applies control logic using a proportional-integral method. Timing is measured using a hardware timer.

Parameters
controller_taskPointer to the ControllerTask structure.