Header file for motor control drivers. More...
#include <stdbool.h>
#include "pico/stdlib.h"
#include "pico/types.h"
Go to the source code of this file.
Data Structures | |
struct | motor_pins |
Contains the GPIO pins for the motor. More... | |
Typedefs | |
typedef struct motor_pins | motor_pins_t |
Contains the GPIO pins for the motor. | |
Functions | |
void | motor_move_forward (void) |
A function to move the car forward. More... | |
void | motor_reverse (void) |
A function to reverse the car. More... | |
void | motor_start (uint clkwise_gpio, uint anti_clkwise_gpio, uint pwm_gpio) |
Default initialization of a single motor. More... | |
void | motor_stop (void) |
A function to stop the car. More... | |
void | motor_turn_left (bool reverse_turn) |
A function to turn the car left. More... | |
void | motor_turn_right (bool reverse_turn) |
A function to turn the car right. More... | |
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. More... | |
void | motor_update_pwm (uint pwm_gpio, uint pwm_wrap, float duty_cycle) |
A function to update the PWM duty cycle and wrap value. More... | |
void | motor_update_ratio (float new_ratio) |
Update the ratio of the left motor's duty cycle to the right motor's duty cycle. More... | |
Header file for motor control drivers.
void motor_move_forward | ( | void | ) |
A function to move the car forward.
This function moves the car forward by setting the duty cycle of both motors to be equal, as well as setting a clockwise rotation for both motors.
References MOTOR_LEFT_PIN_ANTICLKWISE, MOTOR_LEFT_PIN_CLKWISE, MOTOR_PWM_PIN_LEFT, MOTOR_PWM_PIN_RIGHT, MOTOR_PWM_WRAP, MOTOR_RIGHT_PIN_ANTICLKWISE, MOTOR_RIGHT_PIN_CLKWISE, motor_update_direction(), and motor_update_pwm().
void motor_reverse | ( | void | ) |
A function to reverse the car.
This function reverses the car by setting the duty cycle of both motors to be equal, as well as setting an anti-clockwise rotation for both motors.
References MOTOR_LEFT_PIN_ANTICLKWISE, MOTOR_LEFT_PIN_CLKWISE, MOTOR_PWM_PIN_LEFT, MOTOR_PWM_PIN_RIGHT, MOTOR_PWM_WRAP, MOTOR_RIGHT_PIN_ANTICLKWISE, MOTOR_RIGHT_PIN_CLKWISE, motor_update_direction(), and motor_update_pwm().
void motor_start | ( | uint | clkwise_gpio, |
uint | anti_clkwise_gpio, | ||
uint | pwm_gpio | ||
) |
Default initialization of a single motor.
[in] | clkwise_gpio | GPIO pin number for clockwise rotation. |
[in] | anti_clkwise_gpio | GPIO pin number for anticlockwise rotation. |
[in] | pwm_gpio | GPIO pin number for PWM output to control motor speed. |
References MOTOR_PWM_CLKDIV.
void motor_stop | ( | void | ) |
A function to stop the car.
This function works by setting the duty cycle of both motors to 0.
References MOTOR_PWM_PIN_LEFT, MOTOR_PWM_PIN_RIGHT, MOTOR_PWM_WRAP, and motor_update_pwm().
void motor_turn_left | ( | bool | reverse_turn | ) |
A function to turn the car left.
This function turns the car left by setting the duty cycle of the left motor to be lower than the right motor, which enables the car to turn left. In addition, the left motor is set to rotate in the opposite direction of the right motor.
[in] | reverse_turn | A boolean value to indicate that the car is turning in reverse. |
References MOTOR_LEFT_PIN_ANTICLKWISE, MOTOR_LEFT_PIN_CLKWISE, MOTOR_PWM_PIN_LEFT, MOTOR_PWM_PIN_RIGHT, MOTOR_PWM_WRAP, MOTOR_RIGHT_PIN_ANTICLKWISE, MOTOR_RIGHT_PIN_CLKWISE, motor_update_direction(), and motor_update_pwm().
void motor_turn_right | ( | bool | reverse_turn | ) |
A function to turn the car right.
This function turns the car right by setting the duty cycle of the right motor to be lower than the left motor, which enables the car to turn left. In addition, the right motor is set to rotate in the opposite direction of the right motor.
reverse_turn | A boolean value to indicate that the car is turning in reverse. |
References MOTOR_LEFT_PIN_ANTICLKWISE, MOTOR_LEFT_PIN_CLKWISE, MOTOR_PWM_PIN_LEFT, MOTOR_PWM_PIN_RIGHT, MOTOR_PWM_WRAP, MOTOR_RIGHT_PIN_ANTICLKWISE, MOTOR_RIGHT_PIN_CLKWISE, motor_update_direction(), and motor_update_pwm().
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.
[in] | clkwise_gpio | The GPIO pin number for clockwise rotation. |
[in] | anti_clkwise_gpio | The GPIO pin number for anticlockwise rotation. |
[in] | clkwise | The digital value to set for clockwise rotation. |
[in] | anti_clkwise | The digital value to set for anticlockwise rotation. |
void motor_update_pwm | ( | uint | pwm_gpio, |
uint | pwm_wrap, | ||
float | duty_cycle | ||
) |
A function to update the PWM duty cycle and wrap value.
[in] | pwm_gpio | The GPIO pin number for the PWM output. |
[in] | pwm_wrap | The wrap value of the PWM slice. |
[in] | duty_cycle | The duty cycle of the PWM slice. |
void motor_update_ratio | ( | float | new_ratio | ) |
Update the ratio of the left motor's duty cycle to the right motor's duty cycle.
[in] | new_ratio | New ratio of the left motor's duty cycle to the right motor's duty cycle. |
References g_ratio.