Automatic Curtain  MVP
Software repository for an automatic curtain using stepper motor, TMC2209 and ESP32
MotorDriver Class Reference

#include <motor_driver.h>

Inheritance diagram for MotorDriver:
Collaboration diagram for MotorDriver:

Public Member Functions

 MotorDriver (std::shared_ptr< Logging > &logging)
 Initializes motor drive TMC2209, and required pins. More...
 
 MotorDriver (std::shared_ptr< Logging > &logging, CONFIG_SET::CALIB_PARAMS calib_param)
 Initializes motor drive TMC2209, and required pins. More...
 
 ~MotorDriver ()
 Cleans and disables motor driver. More...
 
CONFIG_SET::DRIVER_STATUS GetStatus ()
 Returns the status of the motor driver, by checking if the motor is running or the driver is in fault, or the motor is available for next request. More...
 
int GetSteps ()
 Returns the current steps of motor. More...
 
int GetPercentage ()
 Returns the current percentage of motor. More...
 
bool FulfillRequest (CONFIG_SET::MOTION_REQUEST request)
 This is the primary contact function for external requests, it will handle all requests from the controller or anywhere else, run the thread for supplying steps. More...
 
bool CancelCurrentRequest ()
 Cancels current request. More...
 
void UpdateCalibParams (CONFIG_SET::CALIB_PARAMS calib_param)
 Updates calibration parameters to be used by motor driver. More...
 
void StopHandler ()
 Stop handler thread. More...
 

Static Public Member Functions

static void InterruptForIndex ()
 Runs on a timer, supplies step and direction signal to motor driver. More...
 

Private Member Functions

void Handler ()
 Motor Driver class handler, communicates with driver and is responsible for reading latest motion request, cancellationof request, and acting upon it i.e. moving the motor and stopping it when stall is detected, or motor reached destination or stop is requested or timer limit is reached. More...
 
bool EnableDriver (bool enable)
 Enable Motor Driver Give argument as true for enabling, false for disabling the driver. More...
 
void InitializeDriver ()
 Sets needed parameters for the driver. More...
 
void StartMotor ()
 Responsible for starting the motor, i.e. setups the driver and sets required velocity of motor. More...
 
void StopMotor ()
 Responsible for stopping the motor, i.e. disables the driver and sets velocity of motor to zero. More...
 
void StartHandler ()
 Starts handler thread. More...
 
void ResetSteps ()
 Reset the current steps of motor. More...
 

Private Attributes

CONFIG_SET::DRIVER_STATUS driver_status_
 
CONFIG_SET::CALIB_PARAMS calib_params_
 
std::shared_ptr< Logginglogger_
 
bool is_motor_running_ = false
 
hw_timer_t * step_timer_ = NULL
 
int expected_step_ = 0
 
bool blind_traversal_requested_ = false
 
bool stop_requested_ = false
 
bool keep_handler_running_ = false
 
std::time_t last_motor_start_time_sec_ = std::time(nullptr)
 
std::unique_ptr< std::thread > handler_thread_ {nullptr}
 

Static Private Attributes

static int full_rot_step_count_ = (4 * CONFIG_SET::MOTOR_DRIVER_MICROSTEP)
 
static int current_step_ = 0
 
static bool direction_ = false
 

Constructor & Destructor Documentation

◆ MotorDriver() [1/2]

MotorDriver::MotorDriver ( std::shared_ptr< Logging > &  logging)

Initializes motor drive TMC2209, and required pins.

◆ MotorDriver() [2/2]

MotorDriver::MotorDriver ( std::shared_ptr< Logging > &  logging,
CONFIG_SET::CALIB_PARAMS  calib_param 
)

Initializes motor drive TMC2209, and required pins.

Here is the call graph for this function:

◆ ~MotorDriver()

MotorDriver::~MotorDriver ( )

Cleans and disables motor driver.

Here is the call graph for this function:

Member Function Documentation

◆ CancelCurrentRequest()

bool MotorDriver::CancelCurrentRequest ( )

Cancels current request.

Returns
true: Cancellation successful
false: otherwise

◆ EnableDriver()

bool MotorDriver::EnableDriver ( bool  enable)
private

Enable Motor Driver Give argument as true for enabling, false for disabling the driver.

Returns
true : if successful
false : otherwise
Here is the caller graph for this function:

◆ FulfillRequest()

bool MotorDriver::FulfillRequest ( CONFIG_SET::MOTION_REQUEST  request)

This is the primary contact function for external requests, it will handle all requests from the controller or anywhere else, run the thread for supplying steps.

Returns
true : request accepted
false : rejected

◆ GetPercentage()

int MotorDriver::GetPercentage ( )

Returns the current percentage of motor.

Returns
current percentage

◆ GetStatus()

CONFIG_SET::DRIVER_STATUS MotorDriver::GetStatus ( )

Returns the status of the motor driver, by checking if the motor is running or the driver is in fault, or the motor is available for next request.

Returns
CONFIG_SET::DRIVER_STATUS

◆ GetSteps()

int MotorDriver::GetSteps ( )

Returns the current steps of motor.

Returns
current_steps

◆ Handler()

void MotorDriver::Handler ( )
private

Motor Driver class handler, communicates with driver and is responsible for reading latest motion request, cancellationof request, and acting upon it i.e. moving the motor and stopping it when stall is detected, or motor reached destination or stop is requested or timer limit is reached.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeDriver()

void MotorDriver::InitializeDriver ( )
private

Sets needed parameters for the driver.

Here is the caller graph for this function:

◆ InterruptForIndex()

void IRAM_ATTR MotorDriver::InterruptForIndex ( )
static

Runs on a timer, supplies step and direction signal to motor driver.

Here is the caller graph for this function:

◆ ResetSteps()

void MotorDriver::ResetSteps ( )
private

Reset the current steps of motor.

Here is the caller graph for this function:

◆ StartHandler()

void MotorDriver::StartHandler ( )
private

Starts handler thread.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartMotor()

void MotorDriver::StartMotor ( )
private

Responsible for starting the motor, i.e. setups the driver and sets required velocity of motor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StopHandler()

void MotorDriver::StopHandler ( )

Stop handler thread.

Here is the caller graph for this function:

◆ StopMotor()

void MotorDriver::StopMotor ( )
private

Responsible for stopping the motor, i.e. disables the driver and sets velocity of motor to zero.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateCalibParams()

void MotorDriver::UpdateCalibParams ( CONFIG_SET::CALIB_PARAMS  calib_param)

Updates calibration parameters to be used by motor driver.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ blind_traversal_requested_

bool MotorDriver::blind_traversal_requested_ = false
private

◆ calib_params_

CONFIG_SET::CALIB_PARAMS MotorDriver::calib_params_
private

◆ current_step_

int MotorDriver::current_step_ = 0
staticprivate

◆ direction_

bool MotorDriver::direction_ = false
staticprivate

◆ driver_status_

CONFIG_SET::DRIVER_STATUS MotorDriver::driver_status_
private

◆ expected_step_

int MotorDriver::expected_step_ = 0
private

◆ full_rot_step_count_

int MotorDriver::full_rot_step_count_ = (4 * CONFIG_SET::MOTOR_DRIVER_MICROSTEP)
staticprivate

◆ handler_thread_

std::unique_ptr<std::thread> MotorDriver::handler_thread_ {nullptr}
private

◆ is_motor_running_

bool MotorDriver::is_motor_running_ = false
private

◆ keep_handler_running_

bool MotorDriver::keep_handler_running_ = false
private

◆ last_motor_start_time_sec_

std::time_t MotorDriver::last_motor_start_time_sec_ = std::time(nullptr)
private

◆ logger_

std::shared_ptr<Logging> MotorDriver::logger_
private

◆ step_timer_

hw_timer_t* MotorDriver::step_timer_ = NULL
private

◆ stop_requested_

bool MotorDriver::stop_requested_ = false
private

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