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

Header file for controller task logic in Zap'Em Blast'Em Robots. More...

#include "motor_driver.h"
#include <stdlib.h>
#include <stdio.h>
#include "stm32f4xx_hal.h"
#include "encoder_driver.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ControllerTask
 Structure that defines the controller task. More...

Typedefs

typedef void(* controller_fcn_t) (ControllerTask *controller_task)
 Function pointer type for controller task state functions.

Functions

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

Detailed Description

Header file for controller task logic in Zap'Em Blast'Em Robots.

Author
Kai De La Cruz

Created on: Jun 3, 2025

Typedef Documentation

◆ controller_fcn_t

typedef void(* controller_fcn_t) (ControllerTask *controller_task)

Function pointer type for controller task state functions.

Each function takes a pointer to a ControllerTask struct.

Function Documentation

◆ controller_task_run()

void controller_task_run ( ControllerTask * controller_task)

Executes the current state of the controller task.

Parameters
controller_taskPointer to the ControllerTask instance.

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

Parameters
controller_taskPointer to the ControllerTask instance.

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 the position control logic (State 1).

Parameters
controller_taskPointer to the ControllerTask instance.

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.