INF2004-Project v0.1
 
Loading...
Searching...
No Matches
motor_control.h
Go to the documentation of this file.
1
11#ifndef MOTOR_CONTROL_H // Include guard
12#define MOTOR_CONTROL_H
13#include <stdbool.h>
14#include "pico/stdlib.h"
15#include "pico/types.h"
16
17// Definitions
18// --------------------------------------------------------------------------------------------
19//
20
28#define MOTOR_PWM_CLKDIV 100
30#define MOTOR_PWM_WRAP 62500
32#define MOTOR_LEFT_PIN_CLKWISE 16
34#define MOTOR_LEFT_PIN_ANTICLKWISE 17
36#define MOTOR_RIGHT_PIN_CLKWISE 15
38#define MOTOR_RIGHT_PIN_ANTICLKWISE 14
40#define MOTOR_PWM_PIN_LEFT 10
42#define MOTOR_PWM_PIN_RIGHT 11
44#define MOTOR_DEFAULT_DIFF_RATIO 1.05f // End of motor_control group.
47
48// Type definitions
49// --------------------------------------------------------------------------------------------
50//
51
55typedef struct motor_pins
56{
64
65// Function prototypes
66// --------------------------------------------------------------------------------------------
67//
68
69void motor_start(uint clkwise_gpio, uint anti_clkwise_gpio, uint pwm_gpio);
70void motor_update_pwm(uint pwm_gpio, uint pwm_wrap, float duty_cycle);
71void motor_update_direction(uint clkwise_gpio,
72 uint anti_clkwise_gpio,
73 uint clkwise,
74 uint anti_clkwise);
75void motor_move_forward(void);
76void motor_stop(void);
77void motor_reverse(void);
78void motor_turn_left(bool reverse_turn);
79void motor_turn_right(bool reverse_turn);
80void motor_update_ratio(float new_ratio);
81
82#endif // MOTOR_CONTROL_H
83
84// End of file motor_control.h
void motor_reverse(void)
A function to reverse the car.
Definition: motor_control.c:134
void motor_turn_left(bool reverse_turn)
A function to turn the car left.
Definition: motor_control.c:156
void motor_update_ratio(float new_ratio)
Update the ratio of the left motor's duty cycle to the right motor's duty cycle.
Definition: motor_control.c:218
struct motor_pins motor_pins_t
Contains the GPIO pins for the motor.
void motor_update_pwm(uint pwm_gpio, uint pwm_wrap, float duty_cycle)
A function to update the PWM duty cycle and wrap value.
Definition: motor_control.c:56
void motor_update_direction(uint clkwise_gpio, uint anti_clkwise_gpio, uint clkwise, uint anti_clkwise)
A function to update the direction of the motor's rotation.
Definition: motor_control.c:85
void motor_stop(void)
A function to stop the car.
Definition: motor_control.c:120
void motor_turn_right(bool reverse_turn)
A function to turn the car right.
Definition: motor_control.c:189
void motor_start(uint clkwise_gpio, uint anti_clkwise_gpio, uint pwm_gpio)
Default initialization of a single motor.
Definition: motor_control.c:31
void motor_move_forward(void)
A function to move the car forward.
Definition: motor_control.c:102
Contains the GPIO pins for the motor.
Definition: motor_control.h:56
uint pwm_gpio_a
GPIO pin for PWM A.
Definition: motor_control.h:57
uint left_anticlkwise
GPIO pin for left motor anti-clockwise.
Definition: motor_control.h:60
uint right_anticlkwise
GPIO pin for right motor anti-clockwise.
Definition: motor_control.h:62
uint right_clkwise
GPIO pin for right motor clockwise.
Definition: motor_control.h:61
uint pwm_gpio_b
GPIO pin for PWM B.
Definition: motor_control.h:58
uint left_clkwise
GPIO pin for left motor clockwise.
Definition: motor_control.h:59