Boboter
Loading...
Searching...
No Matches
Device::Motors Class Reference

#include <motors.h>

Public Types

enum class  motor_id_t : uint8_t { LEFT = 0 , RIGHT = 1 }
enum class  motor_direction_t : uint8_t { FORWARD = 0 , BACKWARD = 1 }

Public Member Functions

 Motors (Robot &robot)
 ~Motors ()
void initialize ()
 Sets up the necessary GPIO pins and LEDC channels.
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.
void hard_stop (motor_id_t motor_id) const
 Stops the given motor abruptly without ramping.
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.
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.
void _set_speed (motor_id_t motor_id, uint16_t speed) const
 Physically sets the speed of the given motor.
void _set_direction (motor_id_t motor_id, motor_direction_t direction) const
 Physically sets the direction of the given motor.

Static Public Member Functions

static void enable_deep_sleep_hold ()
 Sets up the motor speed pins to stay low when the ESP32 goes into deep sleep mode.

Static Public Attributes

static constexpr uint8_t NUM_MOTORS = 2
static constexpr uint16_t MAX_MOTOR_SPEED = 820
static constexpr uint16_t DEFAULT_RAMP_TIME_MS = 1000
static constexpr uint16_t MIN_RAMP_TIME_MS = 100

Member Enumeration Documentation

◆ motor_direction_t

enum class Device::Motors::motor_direction_t : uint8_t
strong
Enumerator
FORWARD 
BACKWARD 

◆ motor_id_t

enum class Device::Motors::motor_id_t : uint8_t
strong
Enumerator
LEFT 
RIGHT 

Constructor & Destructor Documentation

◆ Motors()

Device::Motors::Motors ( Robot & robot)
explicit

◆ ~Motors()

Device::Motors::~Motors ( )

Member Function Documentation

◆ _set_direction()

void Device::Motors::_set_direction ( motor_id_t motor_id,
motor_direction_t direction ) const

Physically sets the direction of the given motor.

Warning
Should never be used by any task except the ramp task
Parameters
motor_idThe id of the motor of which to set the direction
directionThe target direction to set the motor to

◆ _set_speed()

void Device::Motors::_set_speed ( motor_id_t motor_id,
uint16_t speed ) const

Physically sets the speed of the given motor.

Warning
Should never be used by any task except the ramp task
Note
The motor will immediately begin turning at that exact speed
Parameters
motor_idThe id of the motor of which to set the speed
speedThe target speed to set the motor to

◆ enable_deep_sleep_hold()

void Device::Motors::enable_deep_sleep_hold ( )
static

Sets up the motor speed pins to stay low when the ESP32 goes into deep sleep mode.

◆ hard_stop()

void Device::Motors::hard_stop ( motor_id_t motor_id) const

Stops the given motor abruptly without ramping.

Parameters
motor_idThe id of the motor to stop

◆ initialize()

void Device::Motors::initialize ( )

Sets up the necessary GPIO pins and LEDC channels.

◆ set_direction()

void Device::Motors::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.

Parameters
motor_idThe id of the motor of which to set the direction
directionThe target direction to set the motor to
ramp_timeThe time to take when ramping to that speed (default: DEFAULT_RAMP_TIME_MS)

◆ set_speed()

void Device::Motors::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.

Note
The motor will immediately begin accelerating towards the specified speed
Parameters
motor_idThe id of the motor of which to set the speed
speedThe target speed to set the motor to
ramp_timeThe time to take when ramping to that speed (default: DEFAULT_RAMP_TIME_MS)

◆ stop()

void Device::Motors::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.

Parameters
motor_idThe id of the motor to stop
ramp_timeThe time to take when ramping to that speed (default: DEFAULT_RAMP_TIME_MS)

Member Data Documentation

◆ DEFAULT_RAMP_TIME_MS

uint16_t Device::Motors::DEFAULT_RAMP_TIME_MS = 1000
staticconstexpr

◆ MAX_MOTOR_SPEED

uint16_t Device::Motors::MAX_MOTOR_SPEED = 820
staticconstexpr

◆ MIN_RAMP_TIME_MS

uint16_t Device::Motors::MIN_RAMP_TIME_MS = 100
staticconstexpr

◆ NUM_MOTORS

uint8_t Device::Motors::NUM_MOTORS = 2
staticconstexpr

The documentation for this class was generated from the following files: