grblHAL core  20241107
stepper2.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include "task.h"

Go to the source code of this file.

Typedefs

typedef struct st2_motor st2_motor_t
 

Enumerations

enum  position_t { Stepper2_Steps = 0 , Stepper2_InfiniteSteps , Stepper2_mm }
 

Functions

st2_motor_tst2_motor_init (uint_fast8_t axis_idx, bool is_spindle)
 Bind and initialize a motor. More...
 
bool st2_motor_poll (st2_motor_t *motor)
 Check if motor is run by polling. More...
 
bool st2_motor_bind_spindle (uint_fast8_t axis_idx)
 Bind and initialize a motor. More...
 
float st2_get_speed (st2_motor_t *motor)
 Get current speed (RPM). More...
 
float st2_motor_set_speed (st2_motor_t *motor, float speed)
 Set speed. More...
 
bool st2_motor_move (st2_motor_t *motor, const float move, const float speed, position_t type)
 Command a motor to move. More...
 
bool st2_motor_run (st2_motor_t *motor)
 Execute a move commanded by st2_motor_move(). More...
 
bool st2_motor_running (st2_motor_t *motor)
 Check if motor is running. More...
 
bool st2_motor_cruising (st2_motor_t *motor)
 Check if motor is running in cruising phase. More...
 
bool st2_motor_stop (st2_motor_t *motor)
 Stop a move. This will initiate deceleration to stop the motor if it is running. More...
 
int64_t st2_get_position (st2_motor_t *motor)
 Get current position in steps. More...
 
bool st2_set_position (st2_motor_t *motor, int64_t position)
 Set current position in steps. More...
 
void st2_motor_register_stopped_callback (st2_motor_t *motor, foreground_task_ptr callback)
 

Typedef Documentation

◆ st2_motor_t

typedef struct st2_motor st2_motor_t

Enumeration Type Documentation

◆ position_t

enum position_t
Enumerator
Stepper2_Steps 

0

Stepper2_InfiniteSteps 

1

Stepper2_mm 

2

Function Documentation

◆ st2_get_position()

int64_t st2_get_position ( st2_motor_t motor)

Get current position in steps.

Parameters
motorpointer to a st2_motor structure.
Returns
current position as number of steps.

◆ st2_get_speed()

float st2_get_speed ( st2_motor_t motor)

Get current speed (RPM).

Parameters
motorpointer to a st2_motor structure.
Returns
current speed in RPM.

◆ st2_motor_bind_spindle()

bool st2_motor_bind_spindle ( uint_fast8_t  axis_idx)

Bind and initialize a motor.

Binds motor 0 as a spindle.

Parameters
axis_idxaxis index of motor to bind to. 3 = A, 4 = B, ...
Returns
true if successful, false if not.

◆ st2_motor_cruising()

bool st2_motor_cruising ( st2_motor_t motor)

Check if motor is running in cruising phase.

Parameters
motorpointer to a st2_motor structure.
Returns
true if motor is cruising (not acceleration or decelerating), false if not.

◆ st2_motor_init()

st2_motor_t* st2_motor_init ( uint_fast8_t  axis_idx,
bool  is_spindle 
)

Bind and initialize a motor.

Allocates and initializes motor configuration/data structure. If is_spindle is set true then axis settings will be changed to step/rev etc. when bound.
NOTE: X, Y or Z motors cannot be bound as a spindle.
NOTE: currently any axis bound as a spindle should not be instructed to move via gcode commands.

Parameters
axis_idxaxis index of motor to bind to. 0 = X, 1 = Y, 2 = Z, ...
is_spindleset to true if axis is to be used as a spindle (infinite motion).
Returns
pointer to a st2_motor structure if successful, NULL if not.

◆ st2_motor_move()

bool st2_motor_move ( st2_motor_t motor,
const float  move,
const float  speed,
position_t  type 
)

Command a motor to move.

NOTE: For all motions except single steps st2_motor_run() has to be called from the foreground process at a high frequency in order for steps to be generated. Typically this is done by registering a function with the hal.on_execute_realtime event that calls st2_motor_run().

Parameters
motorpointer to a st2_motor structure.
moverelative distance to move.
speedspeed
typea position_t enum.
Returns
true if command is accepted, false if not.

◆ st2_motor_poll()

bool st2_motor_poll ( st2_motor_t motor)

Check if motor is run by polling.

Parameters
motorpointer to a st2_motor structure.
Returns
true if motor is run by polling, false if not.

◆ st2_motor_register_stopped_callback()

void st2_motor_register_stopped_callback ( st2_motor_t motor,
foreground_task_ptr  callback 
)

◆ st2_motor_run()

bool st2_motor_run ( st2_motor_t motor)

Execute a move commanded by st2_motor_move().

This should be called from the foreground process as often as possible when step output is not driven by interrupts (polling mode).

Parameters
motorpointer to a st2_motor structure.
Returns
true if motor is moving (steps are output), false if not (motion is completed).

◆ st2_motor_running()

bool st2_motor_running ( st2_motor_t motor)

Check if motor is running.

Parameters
motorpointer to a st2_motor structure.
Returns
true if motor is running, false if not.

◆ st2_motor_set_speed()

float st2_motor_set_speed ( st2_motor_t motor,
float  speed 
)

Set speed.

Change speed of a running motor. Typically used for motors bound as a spindle. Motor will be accelerated or decelerated to the new speed.

Parameters
motorpointer to a st2_motor structure.
speednew speed.
Returns
new speed in steps/s.

◆ st2_motor_stop()

bool st2_motor_stop ( st2_motor_t motor)

Stop a move. This will initiate deceleration to stop the motor if it is running.

Parameters
motorpointer to a st2_motor structure.
Returns
true if motor was running, false if not.

◆ st2_set_position()

bool st2_set_position ( st2_motor_t motor,
int64_t  position 
)

Set current position in steps.

NOTE: position will not be set if motor is moving.

Parameters
motorpointer to a st2_motor structure.
positionposition to set.
Returns
true if new position was accepted, false if not.