Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Stepper Motor Controller Interface

Stepper Motor Controller Interface . More...

Enumerations

enum  micro_step_resolution {
  STEPPER_FULL_STEP = 1 , STEPPER_MICRO_STEP_2 = 2 , STEPPER_MICRO_STEP_4 = 4 , STEPPER_MICRO_STEP_8 = 8 ,
  STEPPER_MICRO_STEP_16 = 16 , STEPPER_MICRO_STEP_32 = 32 , STEPPER_MICRO_STEP_64 = 64 , STEPPER_MICRO_STEP_128 = 128 ,
  STEPPER_MICRO_STEP_256 = 256
}
 Stepper Motor micro step resolution options. More...
 
enum  stepper_direction { STEPPER_DIRECTION_POSITIVE = 0 , STEPPER_DIRECTION_NEGATIVE }
 Stepper Motor direction options. More...
 
enum  stepper_run_mode { STEPPER_HOLD_MODE = 0 , STEPPER_POSITION_MODE , STEPPER_VELOCITY_MODE }
 Stepper Motor run mode options. More...
 
enum  stepper_signal_result { STEPPER_SIGNAL_STEPS_COMPLETED = 0 }
 Stepper Motor signal results. More...
 

Functions

int stepper_enable (const struct device *dev, const bool enable)
 Enable or Disable Motor Controller.
 
int stepper_move (const struct device *dev, int32_t micro_steps, struct k_poll_signal *async)
 Set the micro_steps to be moved from the current position i.e.
 
int stepper_set_max_velocity (const struct device *dev, uint32_t micro_steps_per_second)
 Set the target velocity to be reached by the motor.
 
int stepper_set_micro_step_res (const struct device *dev, enum micro_step_resolution resolution)
 Set the microstep resolution in stepper motor controller.
 
int stepper_get_micro_step_res (const struct device *dev, enum micro_step_resolution *resolution)
 Get the microstep resolution in stepper motor controller.
 
int stepper_set_actual_position (const struct device *dev, int32_t value)
 Set the actual a.k.a reference position of the stepper.
 
int stepper_get_actual_position (const struct device *dev, int32_t *value)
 Get the actual a.k.a reference position of the stepper.
 
int stepper_set_target_position (const struct device *dev, int32_t value, struct k_poll_signal *async)
 Set the absolute target position of the stepper.
 
int stepper_is_moving (const struct device *dev, bool *is_moving)
 Check if the stepper motor is currently moving.
 
int stepper_enable_constant_velocity_mode (const struct device *dev, enum stepper_direction direction, uint32_t value)
 Enable constant velocity mode for the stepper with a given velocity.
 

Detailed Description

Stepper Motor Controller Interface .

Enumeration Type Documentation

◆ micro_step_resolution

#include <zephyr/drivers/stepper.h>

Stepper Motor micro step resolution options.

Enumerator
STEPPER_FULL_STEP 

Full step resolution.

STEPPER_MICRO_STEP_2 

2 micro steps per full step

STEPPER_MICRO_STEP_4 

4 micro steps per full step

STEPPER_MICRO_STEP_8 

8 micro steps per full step

STEPPER_MICRO_STEP_16 

16 micro steps per full step

STEPPER_MICRO_STEP_32 

32 micro steps per full step

STEPPER_MICRO_STEP_64 

64 micro steps per full step

STEPPER_MICRO_STEP_128 

128 micro steps per full step

STEPPER_MICRO_STEP_256 

256 micro steps per full step

◆ stepper_direction

#include <zephyr/drivers/stepper.h>

Stepper Motor direction options.

Enumerator
STEPPER_DIRECTION_POSITIVE 

Positive direction.

STEPPER_DIRECTION_NEGATIVE 

Negative direction.

◆ stepper_run_mode

#include <zephyr/drivers/stepper.h>

Stepper Motor run mode options.

Enumerator
STEPPER_HOLD_MODE 

Hold Mode.

STEPPER_POSITION_MODE 

Position Mode.

STEPPER_VELOCITY_MODE 

Velocity Mode.

◆ stepper_signal_result

#include <zephyr/drivers/stepper.h>

Stepper Motor signal results.

Enumerator
STEPPER_SIGNAL_STEPS_COMPLETED 

Steps set using move or set_target_position have been executed.

Function Documentation

◆ stepper_enable()

int stepper_enable ( const struct device * dev,
const bool enable )

#include <zephyr/drivers/stepper.h>

Enable or Disable Motor Controller.

Parameters
devpointer to the stepper motor controller instance
enableInput enable or disable motor controller
Return values
-EIOError during Enabling
0Success

◆ stepper_enable_constant_velocity_mode()

int stepper_enable_constant_velocity_mode ( const struct device * dev,
enum stepper_direction direction,
uint32_t value )

#include <zephyr/drivers/stepper.h>

Enable constant velocity mode for the stepper with a given velocity.

activate constant velocity mode with the given velocity in micro_steps_per_second. If velocity > 0, motor shall be set into motion and run incessantly until and unless stalled or stopped using some other command, for instance, motor_enable(false).

Parameters
devpointer to the stepper motor controller instance
directionThe direction to set
valueThe velocity to set in steps per second where one step is dependent on the current microstepping resolution:

‍0: Enable constant velocity mode with the given velocity in a given direction 0: Disable constant velocity mode

Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_get_actual_position()

int stepper_get_actual_position ( const struct device * dev,
int32_t * value )

#include <zephyr/drivers/stepper.h>

Get the actual a.k.a reference position of the stepper.

Parameters
devpointer to the stepper motor controller instance
valueThe actual position to get in micro_steps
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_get_micro_step_res()

int stepper_get_micro_step_res ( const struct device * dev,
enum micro_step_resolution * resolution )

#include <zephyr/drivers/stepper.h>

Get the microstep resolution in stepper motor controller.

Parameters
devpointer to the stepper motor controller instance
resolutionmicrostep resolution
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_is_moving()

int stepper_is_moving ( const struct device * dev,
bool * is_moving )

#include <zephyr/drivers/stepper.h>

Check if the stepper motor is currently moving.

Parameters
devpointer to the stepper motor controller instance
is_movingPointer to a boolean to store the moving status of the stepper motor
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_move()

int stepper_move ( const struct device * dev,
int32_t micro_steps,
struct k_poll_signal * async )

#include <zephyr/drivers/stepper.h>

Set the micro_steps to be moved from the current position i.e.

relative movement

Parameters
devpointer to the stepper motor controller instance
micro_stepstarget micro_steps to be moved from the current position
asyncPointer to a valid and ready to be signaled struct k_poll_signal. (Note: if NULL this function will not notify the end of the transaction, and whether it went successfully or not).
Return values
-EIOGeneral input / output error
0Success

◆ stepper_set_actual_position()

int stepper_set_actual_position ( const struct device * dev,
int32_t value )

#include <zephyr/drivers/stepper.h>

Set the actual a.k.a reference position of the stepper.

Parameters
devPointer to the stepper motor controller instance.
valueThe reference position to set in micro-steps.
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_set_max_velocity()

int stepper_set_max_velocity ( const struct device * dev,
uint32_t micro_steps_per_second )

#include <zephyr/drivers/stepper.h>

Set the target velocity to be reached by the motor.

For controllers such as DRV8825 where you toggle the STEP Pin, the pulse_length would have to be calculated based on this parameter in the driver. For controllers where velocity can be set, this parameter corresponds to max_velocity

Note
Setting max velocity does not set the motor into motion, a combination of set_max_velocity and move is required to set the motor into motion.
Parameters
devpointer to the stepper motor controller instance
micro_steps_per_secondspeed in micro_steps per second
Return values
-EIOGeneral input / output error
-EINVALIf the requested velocity is not supported
0Success

◆ stepper_set_micro_step_res()

int stepper_set_micro_step_res ( const struct device * dev,
enum micro_step_resolution resolution )

#include <zephyr/drivers/stepper.h>

Set the microstep resolution in stepper motor controller.

Parameters
devpointer to the stepper motor controller instance
resolutionmicrostep resolution
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
-ENOTSUPIf the requested resolution is not supported
0Success

◆ stepper_set_target_position()

int stepper_set_target_position ( const struct device * dev,
int32_t value,
struct k_poll_signal * async )

#include <zephyr/drivers/stepper.h>

Set the absolute target position of the stepper.

Parameters
devpointer to the stepper motor controller instance
valuetarget position to set in micro_steps
asyncPointer to a valid and ready to be signaled struct k_poll_signal. If changing the target position triggers stepper movement, this can be used to await the end of the transaction. (Note: can be left NULL)
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success