forked from grblHAL/core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stepper.h
140 lines (116 loc) · 6.83 KB
/
stepper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
Part of grblHAL
Copyright (c) 2019-2023 Terje Io
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
Copyright (c) 2009-2011 Simen Svale Skogsrud
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include "planner.h"
#ifndef _STEPPER_H_
#define _STEPPER_H_
typedef enum {
SquaringMode_Both = 0, //!< 0
SquaringMode_A, //!< 1
SquaringMode_B, //!< 2
} squaring_mode_t;
/*! \brief Holds the planner block Bresenham algorithm execution data for the segments in the segment buffer.
__NOTE:__ This data is copied from the prepped planner blocks so that the planner blocks may be
discarded when entirely consumed and completed by the segment buffer. Also, AMASS alters this
data for its own use. */
typedef struct st_block {
uint_fast8_t id; //!< Id may be used by driver to track changes
struct st_block *next; //!< Pointer to next element in cirular list of blocks
uint32_t steps[N_AXIS];
uint32_t step_event_count;
axes_signals_t direction_bits;
gc_override_flags_t overrides; //!< Block bitfield variable for overrides
float steps_per_mm;
float millimeters;
float programmed_rate;
char *message; //!< Message to be displayed when block is executed
output_command_t *output_commands; //!< Output commands (linked list) to be performed when block is executed
bool backlash_motion;
bool dynamic_rpm; //!< Tracks motions that require dynamic RPM adjustment
spindle_ptrs_t *spindle; //!< Pointer to current spindle for motions that require dynamic RPM adjustment
} st_block_t;
typedef struct st_segment {
uint_fast8_t id; //!< Id may be used by driver to track changes
struct st_segment *next; //!< Pointer to next element in cirular list of segments
st_block_t *exec_block; //!< Pointer to the block data for the segment
uint32_t cycles_per_tick; //!< Step distance traveled per ISR tick, aka step rate.
float current_rate;
float target_position; //!< Target position of segment relative to block start, used by spindle sync code
uint_fast16_t n_step; //!< Number of step events to be executed for this segment
uint_fast16_t spindle_pwm; //!< Spindle PWM to be set at the start of segment execution
float spindle_rpm; //!< Spindle RPM to be set at the start of the segment execution
bool spindle_sync; //!< True if block is spindle synchronized
bool cruising; //!< True when in cruising part of profile, only set for spindle synced moves
uint_fast8_t amass_level; //!< Indicates AMASS level for the ISR to execute this segment
spindle_update_pwm_ptr update_pwm; //!< Valid pointer to spindle.update_pwm() if set spindle speed at the start of the segment execution
spindle_update_rpm_ptr update_rpm; //!< Valid pointer to spindle.update_rmp() if set spindle speed at the start of the segment execution
} segment_t;
//! Stepper ISR data struct. Contains the running data for the main stepper ISR.
typedef struct stepper {
uint32_t counter_x, //!< Counter variable for the Bresenham line tracer, X-axis
counter_y, //!< Counter variable for the Bresenham line tracer, Y-axis
counter_z //!< Counter variable for the Bresenham line tracer, Z-axis
#ifdef A_AXIS
, counter_a //!< Counter variable for the Bresenham line tracer, A-axis
#endif
#ifdef B_AXIS
, counter_b //!< Counter variable for the Bresenham line tracer, B-axis
#endif
#ifdef C_AXIS
, counter_c //!< Counter variable for the Bresenham line tracer, C-axis
#endif
#ifdef U_AXIS
, counter_u //!< Counter variable for the Bresenham line tracer, U-axis
#endif
#ifdef V_AXIS
, counter_v //!< Counter variable for the Bresenham line tracer, V-axis
#endif
;
bool new_block; //!< Set to true when a new block is started, might be referenced by driver code for advanced functionality.
bool dir_change; //!< Set to true on direction changes, might be referenced by driver for advanced functionality.
axes_signals_t step_outbits; //!< The stepping signals to be output.
axes_signals_t dir_outbits; //!< The direction signals to be output. The direction signals may be output only when \ref stepper.dir_change is true to reduce overhead.
uint32_t steps[N_AXIS]; //!< Number of step pulse event events per axis step pulse generated.
uint_fast8_t amass_level; //!< AMASS level for this segment.
// uint_fast16_t spindle_pwm;
uint_fast16_t step_count; //!< Steps remaining in line segment motion.
uint32_t step_event_count; //!< Number of step pulse events to be output by this segment.
st_block_t *exec_block; //!< Pointer to the block data for the segment being executed.
segment_t *exec_segment; //!< Pointer to the segment being executed.
} stepper_t;
// Initialize and setup the stepper motor subsystem
void stepper_init (void);
// Enable steppers, but cycle does not start unless called by motion control or realtime command.
void st_wake_up (void);
// Immediately disables steppers
void st_go_idle (void);
// Reset the stepper subsystem variables
void st_reset (void);
// Called by spindle_set_state() to inform about RPM changes.
void st_rpm_changed(float rpm);
// Changes the run state of the step segment buffer to execute the special parking motion.
void st_parking_setup_buffer();
// Restores the step segment buffer to the normal run state after a parking motion.
void st_parking_restore_buffer (void);
// Reloads step segment buffer. Called continuously by realtime execution system.
void st_prep_buffer (void);
// Called by planner_recalculate() when the executing block is updated by the new plan.
void st_update_plan_block_parameters (void);
// Called by realtime status reporting if realtime rate reporting is enabled in config.h.
float st_get_realtime_rate (void);
void stepper_driver_interrupt_handler (void);
#endif