11#include <soc/gpio_num.h>
12#include <driver/ledc.h>
20 static constexpr const char* TAG =
"Device::Motors";
23 static constexpr gpio_num_t LEFT_SPEED_PIN = GPIO_NUM_32;
24 static constexpr gpio_num_t LEFT_DIRECTION_PIN = GPIO_NUM_33;
25 static constexpr gpio_num_t RIGHT_SPEED_PIN = GPIO_NUM_2;
26 static constexpr gpio_num_t RIGHT_DIRECTION_PIN = GPIO_NUM_15;
28 static constexpr ledc_timer_t LEDC_TIMER = LEDC_TIMER_0;
29 static constexpr ledc_channel_t LEFT_LEDC_CHANNEL = LEDC_CHANNEL_0;
30 static constexpr ledc_channel_t RIGHT_LEDC_CHANNEL = LEDC_CHANNEL_1;
33 bool inverse_direction[2];
void _set_direction(motor_id_t motor_id, motor_direction_t direction) const
Physically sets the direction of the given motor.
Definition motors_hardware.cpp:25
static constexpr uint8_t NUM_MOTORS
Definition motors.h:36
Motors(Robot &robot)
Definition motors.cpp:13
motor_id_t
Definition motors.h:41
@ RIGHT
Definition motors.h:43
@ LEFT
Definition motors.h:42
motor_direction_t
Definition motors.h:46
@ BACKWARD
Definition motors.h:48
@ FORWARD
Definition motors.h:47
void _set_speed(motor_id_t motor_id, uint16_t speed) const
Physically sets the speed of the given motor.
Definition motors_hardware.cpp:14
void set_speed(motor_id_t motor_id, uint16_t speed, uint16_t ramp_time=DEFAULT_RAMP_TIME_MS) const
Sets the speed of the given motor toward which it should accelerate.
Definition motors.cpp:92
void hard_stop(motor_id_t motor_id) const
Stops the given motor abruptly without ramping.
Definition motors.cpp:78
~Motors()
Definition motors.cpp:20
static constexpr uint16_t DEFAULT_RAMP_TIME_MS
Definition motors.h:38
static constexpr uint16_t MAX_MOTOR_SPEED
Definition motors.h:37
void stop(motor_id_t motor_id, uint16_t ramp_time=DEFAULT_RAMP_TIME_MS) const
Stops the given motor by gradually reducing speed for a smooth stop.
Definition motors.cpp:63
void initialize()
Sets up the necessary GPIO pins and LEDC channels.
Definition motors.cpp:27
static void enable_deep_sleep_hold()
Sets up the motor speed pins to stay low when the ESP32 goes into deep sleep mode.
Definition motors.cpp:118
void set_direction(motor_id_t motor_id, motor_direction_t direction, uint16_t ramp_time=DEFAULT_RAMP_TIME_MS) const
Sets the virtual direction of the given motor.
Definition motors.cpp:106
static constexpr uint16_t MIN_RAMP_TIME_MS
Definition motors.h:39
Class containing all the components of the robot.
Definition robot.h:32
log_source
Definition log_sources.h:12
@ LOG_SOURCE_DEVICE_MOTORS
Definition log_sources.h:24
Definition battery.cpp:14