grblHAL core  20240704
stepper2.c File Reference
#include "hal.h"
#include <math.h>
#include <stdlib.h>
#include "stepper2.h"

Data Structures

struct  st2_motor
 Internal structure for holding motor configuration and keeping track of its status. More...
 

Enumerations

enum  st2_state_t {
  State_Idle = 0 , State_Accel , State_Run , State_RunInfinite ,
  State_DecelTo , State_Decel
}
 

Functions

bool st2_motor_bind_spindle (uint_fast8_t axis_idx)
 Bind and initialize a motor. More...
 
st2_motor_tst2_motor_init (uint_fast8_t axis_idx, bool is_spindle)
 Bind and initialize a motor. 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...
 
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...
 
bool st2_motor_run (st2_motor_t *motor)
 Execute a move commanded by st2_motor_move(). 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...
 
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...
 

Enumeration Type Documentation

◆ st2_state_t

Enumerator
State_Idle 

0

State_Accel 

1

State_Run 

2

State_RunInfinite 

3

State_DecelTo 

4

State_Decel 

5

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_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_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.

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.