90 __attribute__((always_inline))
static inline float _st2_get_speed (
st2_profile_t *profile)
95 __attribute__((always_inline))
static inline float _st2_set_speed (
st2_profile_t *profile,
float steps_per_second)
98 return profile->
speed;
109 int32_t pn = profile->
n - ((profile->
denom - 1) >> 2);
112 return profile->
speed;
126 if(profile->
speed == 0.0f)
143 __attribute__((always_inline))
static inline uint32_t _st2_calc_steps (
st2_profile_t *profile,
float move,
position_t ptype)
147 switch((profile->
ptype = ptype)) {
151 profile->
move = (uint32_t)fabsf(move);
159 return profile->
move;
162 __attribute__((always_inline))
static inline bool _st2_start (
st2_profile_t *profile)
167 }
else if(profile->
move != 0) {
168 profile->
step_run = (profile->
move - ((profile->
move & 0x0001) ? 1 : 0)) >> 1;
177 profile->
c64 = profile->
delay << 16;
184 __attribute__((always_inline))
static inline bool _st2_run (
st2_profile_t *profile)
186 switch(profile->
state) {
191 profile->
c64 -= (profile->
c64 << 1) / profile->
denom;
192 profile->
delay = (profile->
c64 + 32768) >> 16;
214 if(profile->
denom < 2) {
219 debug_writeln(
uitoa(profile->position));
222 profile->
c64 += (profile->
c64 << 1) / profile->
denom;
223 profile->
delay = (profile->
c64 - 32768) >> 16;
231 profile->
c64 += (profile->
c64 << 1) / profile->
denom;
232 profile->
delay = (profile->
c64 + 32768) >> 16;
254 __attribute__((always_inline))
static inline bool _st2_stop (
st2_profile_t *profile)
256 switch(profile->
state) {
283 __attribute__((always_inline))
static inline bool _st2_running (
st2_profile_t *profile)
292 __attribute__((always_inline))
static inline bool _st2_cruising (
st2_profile_t *profile)
char * uitoa(uint32_t n)
Definition: nuts_bolts.c:107
settings_t settings
Definition: settings.c:48
int64_t st2_get_position(st2_motor_t *motor)
Get current position in steps.
Definition: stepper2.c:391
bool st2_motor_bind_spindle(uint_fast8_t axis_idx, axis_settings_t *cfg)
Bind and initialize a motor.
Definition: stepper2.c:210
bool st2_motor_move(st2_motor_t *motor, const float move, const float speed, position_t type)
Command a motor to move.
Definition: stepper2.c:345
float st2_motor_set_speed(st2_motor_t *motor, float speed)
Set speed.
Definition: stepper2.c:320
position_t
Definition: stepper2.h:27
@ Stepper2_Steps
0
Definition: stepper2.h:28
@ Stepper2_mm
2
Definition: stepper2.h:30
@ Stepper2_InfiniteSteps
1
Definition: stepper2.h:29
st2_motor_t * st2_motor_init(uint_fast8_t axis_idx, bool is_spindle)
Bind and initialize a motor.
Definition: stepper2.c:255
bool st2_set_position(st2_motor_t *motor, int64_t position)
Set current position in steps.
Definition: stepper2.c:403
void st2_motor_register_stopped_callback(st2_motor_t *motor, foreground_task_ptr callback)
Definition: stepper2.c:199
float st2_get_speed(st2_motor_t *motor)
Get current speed (RPM).
Definition: stepper2.c:307
bool st2_motor_run(st2_motor_t *motor)
Execute a move commanded by st2_motor_move().
Definition: stepper2.c:450
bool st2_motor_cruising(st2_motor_t *motor)
Check if motor is running in cruising phase.
Definition: stepper2.c:499
bool st2_motor_poll(st2_motor_t *motor)
Check if motor is run by polling.
Definition: stepper2.c:481
bool st2_motor_running(st2_motor_t *motor)
Check if motor is running.
Definition: stepper2.c:490
bool st2_motor_stop(st2_motor_t *motor)
Stop a move. This will initiate deceleration to stop the motor if it is running.
Definition: stepper2.c:472
st2_state_t
Definition: stepper2.h:52
@ State_DecelTo
4
Definition: stepper2.h:57
@ State_Run
2
Definition: stepper2.h:55
@ State_Accel
1
Definition: stepper2.h:54
@ State_Decel
5
Definition: stepper2.h:58
@ State_Idle
0
Definition: stepper2.h:53
@ State_RunInfinite
3
Definition: stepper2.h:56
FLASHMEM void debug_printf(const char *fmt,...)
Definition: stream.c:1070
Definition: settings.h:764
float acceleration
Definition: settings.h:767
float steps_per_mm
Definition: settings.h:765
stepper_settings_t steppers
Definition: settings.h:924
Internal structure for holding motor configuration and keeping track of its status.
Definition: stepper2.c:51
volatile int64_t position
Definition: stepper2.c:55
Definition: stepper2.h:61
uint32_t move
Definition: stepper2.h:64
uint32_t step_length
Definition: stepper2.h:70
uint32_t n
Definition: stepper2.h:74
uint32_t step_down
Definition: stepper2.h:67
uint32_t min_delay
Definition: stepper2.h:72
uint32_t step_no
Definition: stepper2.h:65
uint32_t step_run
Definition: stepper2.h:66
float speed
Definition: stepper2.h:75
uint64_t delay
Definition: stepper2.h:69
float prev_speed
Definition: stepper2.h:76
float acceleration
Definition: stepper2.h:78
int32_t denom
Definition: stepper2.h:73
uint64_t c64
Definition: stepper2.h:68
position_t ptype
Definition: stepper2.h:62
uint32_t first_delay
Definition: stepper2.h:71
st2_state_t state
Definition: stepper2.h:63
float steps_per_mm
Definition: stepper2.h:77
float pulse_microseconds
Definition: settings.h:759
void(* foreground_task_ptr)(void *data)
Definition: task.h:25