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

Motor control functions for PWM-based direction and speed handling. More...

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

Macros

#define PWM_MAX   4800
 Maximum PWM value used for scaling duty cycle.

Functions

void set_duty (motor_t *p_mot, int32_t duty)
 Sets the motor duty cycle and direction using PWM.
void disable (motor_t *p_mot)
 Disables the motor by setting both channels to 0% duty.
void enable (motor_t *p_mot)
 Enables the motor by setting both channels to 100% duty.
void go_to (motor_t *p_mot, int k_p, int where, int from)
 Moves the motor toward a target using proportional control.

Detailed Description

Motor control functions for PWM-based direction and speed handling.

Author
Kai De La Cruz

Created on: May 29, 2025

Function Documentation

◆ disable()

void disable ( motor_t * p_mot)

Disables the motor by setting both channels to 0% duty.

Disables the motor by setting both channels to zero.

Parameters
p_motPointer to the motor structure

◆ enable()

void enable ( motor_t * p_mot)

Enables the motor by setting both channels to 100% duty.

Enables the motor by setting both channels to maximum.

Parameters
p_motPointer to the motor structure

◆ go_to()

void go_to ( motor_t * p_mot,
int k_p,
int where,
int from )

Moves the motor toward a target using proportional control.

Uses proportional control to move motor to a target.

Parameters
p_motPointer to the motor structure
k_pProportional gain
whereTarget position
fromCurrent position

◆ set_duty()

void set_duty ( motor_t * p_mot,
int32_t duty )

Sets the motor duty cycle and direction using PWM.

Sets the duty cycle and direction of the motor.

Parameters
p_motPointer to the motor structure
dutyDesired duty cycle (-100 to 100 percent)