mirror of
https://github.com/synthetos/g2.git
synced 2026-09-21 10:35:38 +08:00
Consolidating direct spindle controls to spindle.cpp
This commit is contained in:
+1
-16
@@ -980,22 +980,7 @@ constexpr cfgItem_t fixturing_config_items_1[] = {
|
||||
constexpr cfgSubtableFromStaticArray fixturing_config_1 {fixturing_config_items_1};
|
||||
constexpr const configSubtable * const getFixturingConfig_1() { return &fixturing_config_1; }
|
||||
|
||||
constexpr cfgItem_t spindle_config_items_1[] = {
|
||||
// Spindle functions
|
||||
{ "sp","spmo", _i0, 0, sp_print_spmo, get_nul, set_nul, nullptr, 0 }, // keeping this key around, but it returns null and does nothing
|
||||
{ "sp","spph", _bip, 0, sp_print_spph, sp_get_spph, sp_set_spph, nullptr, SPINDLE_PAUSE_ON_HOLD },
|
||||
{ "sp","spde", _fip, 2, sp_print_spde, sp_get_spde, sp_set_spde, nullptr, SPINDLE_SPINUP_DELAY },
|
||||
{ "sp","spsn", _fip, 2, sp_print_spsn, sp_get_spsn, sp_set_spsn, nullptr, SPINDLE_SPEED_MIN},
|
||||
{ "sp","spsm", _fip, 2, sp_print_spsm, sp_get_spsm, sp_set_spsm, nullptr, SPINDLE_SPEED_MAX},
|
||||
{ "sp","spep", _iip, 0, sp_print_spep, sp_get_spep, sp_set_spep, nullptr, SPINDLE_ENABLE_POLARITY },
|
||||
{ "sp","spdp", _iip, 0, sp_print_spdp, sp_get_spdp, sp_set_spdp, nullptr, SPINDLE_DIR_POLARITY },
|
||||
{ "sp","spoe", _bip, 0, sp_print_spoe, sp_get_spoe, sp_set_spoe, nullptr, SPINDLE_OVERRIDE_ENABLE},
|
||||
{ "sp","spo", _fip, 3, sp_print_spo, sp_get_spo, sp_set_spo, nullptr, SPINDLE_OVERRIDE_FACTOR},
|
||||
{ "sp","spc", _i0, 0, sp_print_spc, sp_get_spc, sp_set_spc, nullptr, 0 }, // spindle state
|
||||
{ "sp","sps", _f0, 0, sp_print_sps, sp_get_sps, sp_set_sps, nullptr, 0 }, // spindle speed
|
||||
};
|
||||
constexpr cfgSubtableFromStaticArray spindle_config_1 {spindle_config_items_1};
|
||||
constexpr const configSubtable * const getSpindleConfig_1() { return &spindle_config_1; }
|
||||
// spindle
|
||||
|
||||
constexpr cfgItem_t coolant_config_items_1[] = {
|
||||
// Coolant functions
|
||||
|
||||
@@ -579,11 +579,10 @@ static stat_t _interlock_estop_handler(void) {
|
||||
cm1.safety_state |= SAFETY_INTERLOCK_OPEN;
|
||||
|
||||
// Check if the spindle is on
|
||||
if (spindle.state != SPINDLE_OFF) {
|
||||
if (is_spindle_on_or_paused()) {
|
||||
if (cm1.machine_state == MACHINE_CYCLE) {
|
||||
cm_request_feedhold(FEEDHOLD_TYPE_ACTIONS, FEEDHOLD_EXIT_CYCLE);
|
||||
} else {
|
||||
// cm_request_cycle_start(); // proper way to restart the cycle
|
||||
spindle_control_immediate(SPINDLE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,7 +890,7 @@ stat_t _feedhold_restart_with_actions() // Execute Cases (6) and (7)
|
||||
|
||||
// Check to run first-time code
|
||||
if (cm1.hold_state == FEEDHOLD_HOLD) {
|
||||
if (!coolant_ready() || (spindle_is_on_or_paused() && !spindle_ready_to_resume())) {
|
||||
if (!coolant_ready() || (is_spindle_on_or_paused() && !is_spindle_ready_to_resume())) {
|
||||
return (STAT_EAGAIN);
|
||||
}
|
||||
|
||||
|
||||
+77
-4
@@ -39,6 +39,61 @@
|
||||
|
||||
/**** Allocate structures ****/
|
||||
|
||||
#define SPINDLE_OVERRIDE_ENABLE false
|
||||
#define SPINDLE_OVERRIDE_FACTOR 1.00
|
||||
#define SPINDLE_OVERRIDE_MIN 0.05 // 5%
|
||||
#define SPINDLE_OVERRIDE_MAX 2.00 // 200%
|
||||
#define SPINDLE_OVERRIDE_RAMP_TIME 1 // change sped in seconds
|
||||
|
||||
enum spMode {
|
||||
SPINDLE_DISABLED = 0, // spindle will not operate
|
||||
SPINDLE_PLAN_TO_STOP, // spindle operating, plans to stop
|
||||
SPINDLE_CONTINUOUS, // spindle operating, does not plan to stop
|
||||
};
|
||||
#define SPINDLE_MODE_MAX SPINDLE_CONTINUOUS
|
||||
|
||||
// *** NOTE: The spindle polarity active hi/low values currently agree with ioMode in gpio.h
|
||||
// These will all need to be changed to ACTIVE_HIGH = 0, ACTIVE_LOW = 1
|
||||
// See: https://github.com/synthetos/g2_private/wiki/GPIO-Design-Discussion#settings-common-to-all-io-types
|
||||
|
||||
enum spPolarity { // Note: These values agree with
|
||||
SPINDLE_ACTIVE_LOW = 0, // Will set output to 0 to enable the spindle or CW direction
|
||||
SPINDLE_ACTIVE_HIGH = 1, // Will set output to 1 to enable the spindle or CW direction
|
||||
};
|
||||
|
||||
enum ESCState { // electronic speed controller for some spindles
|
||||
ESC_ONLINE = 0,
|
||||
ESC_OFFLINE,
|
||||
ESC_LOCKOUT,
|
||||
ESC_REBOOTING,
|
||||
ESC_LOCKOUT_AND_REBOOTING,
|
||||
};
|
||||
|
||||
/*
|
||||
* Spindle control structure
|
||||
*/
|
||||
|
||||
struct spSpindle_t {
|
||||
|
||||
spControl state; // {spc:} OFF, ON, PAUSE, RESUME, WAIT
|
||||
spControl direction; // 1=CW, 2=CCW (subset of above state)
|
||||
|
||||
float speed; // {sps:} S in RPM
|
||||
float speed_min; // {spsn:} minimum settable spindle speed
|
||||
float speed_max; // {spsm:} maximum settable spindle speed
|
||||
float speed_actual; // hidden internal value used in speed ramping
|
||||
float speed_change_per_tick; // hidden internal value used in speed ramping
|
||||
|
||||
spPolarity enable_polarity; // {spep:} 0=active low, 1=active high
|
||||
spPolarity dir_polarity; // {spdp:} 0=clockwise low, 1=clockwise high
|
||||
bool pause_enable; // {spph:} pause on feedhold
|
||||
float spinup_delay; // {spde:} optional delay on spindle start (set to 0 to disable)
|
||||
// float spindown_delay; // {spds:} optional delay on spindle stop (set to 0 to disable)
|
||||
|
||||
bool override_enable; // {spoe:} TRUE = spindle speed override enabled (see also m48_enable in canonical machine)
|
||||
float override_factor; // {spo:} 1.0000 x S spindle speed. Go up or down from there
|
||||
};
|
||||
|
||||
spSpindle_t spindle;
|
||||
|
||||
|
||||
@@ -336,7 +391,7 @@ stat_t spindle_control_sync(spControl control) // uses spControl arg: OFF, CW,
|
||||
return (STAT_OK);
|
||||
}
|
||||
|
||||
if (spindle.speed > 0.0 && !spindle_ready_to_resume()) {
|
||||
if (spindle.speed > 0.0 && !is_spindle_ready_to_resume()) {
|
||||
// request a feedhold immediately
|
||||
cm_request_feedhold(FEEDHOLD_TYPE_ACTIONS, FEEDHOLD_EXIT_CYCLE);
|
||||
}
|
||||
@@ -386,7 +441,7 @@ stat_t spindle_speed_sync(float speed)
|
||||
return (STAT_OK);
|
||||
}
|
||||
|
||||
bool spindle_ready_to_resume() {
|
||||
bool is_spindle_ready_to_resume() {
|
||||
#ifdef ENABLE_INTERLOCK_AND_ESTOP
|
||||
if ((cm1.estop_state != 0) || (cm1.safety_state != 0)) {
|
||||
return false;
|
||||
@@ -395,7 +450,7 @@ bool spindle_ready_to_resume() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool spindle_is_on_or_paused() {
|
||||
bool is_spindle_on_or_paused() {
|
||||
if (spindle.state != SPINDLE_OFF) {
|
||||
return true;
|
||||
}
|
||||
@@ -403,7 +458,7 @@ bool spindle_is_on_or_paused() {
|
||||
}
|
||||
|
||||
// returns if it's done
|
||||
bool spindle_speed_ramp_from_systick() {
|
||||
bool do_spindle_speed_ramp_from_systick() {
|
||||
#ifdef ENABLE_INTERLOCK_AND_ESTOP
|
||||
bool done = false;
|
||||
if ((cm1.estop_state == 0) && (cm1.safety_state == 0)) {
|
||||
@@ -598,3 +653,21 @@ void sp_print_spoe(nvObj_t *nv) { text_print(nv, fmt_spoe);} // TYPE INT
|
||||
void sp_print_spo(nvObj_t *nv) { text_print(nv, fmt_spo);} // TYPE FLOAT
|
||||
|
||||
#endif // __TEXT_MODE
|
||||
|
||||
|
||||
constexpr cfgItem_t spindle_config_items_1[] = {
|
||||
// Spindle functions
|
||||
{ "sp","spmo", _i0, 0, sp_print_spmo, get_nul, set_nul, nullptr, 0 }, // keeping this key around, but it returns null and does nothing
|
||||
{ "sp","spph", _bip, 0, sp_print_spph, sp_get_spph, sp_set_spph, nullptr, SPINDLE_PAUSE_ON_HOLD },
|
||||
{ "sp","spde", _fip, 2, sp_print_spde, sp_get_spde, sp_set_spde, nullptr, SPINDLE_SPINUP_DELAY },
|
||||
{ "sp","spsn", _fip, 2, sp_print_spsn, sp_get_spsn, sp_set_spsn, nullptr, SPINDLE_SPEED_MIN},
|
||||
{ "sp","spsm", _fip, 2, sp_print_spsm, sp_get_spsm, sp_set_spsm, nullptr, SPINDLE_SPEED_MAX},
|
||||
{ "sp","spep", _iip, 0, sp_print_spep, sp_get_spep, sp_set_spep, nullptr, SPINDLE_ENABLE_POLARITY },
|
||||
{ "sp","spdp", _iip, 0, sp_print_spdp, sp_get_spdp, sp_set_spdp, nullptr, SPINDLE_DIR_POLARITY },
|
||||
{ "sp","spoe", _bip, 0, sp_print_spoe, sp_get_spoe, sp_set_spoe, nullptr, SPINDLE_OVERRIDE_ENABLE},
|
||||
{ "sp","spo", _fip, 3, sp_print_spo, sp_get_spo, sp_set_spo, nullptr, SPINDLE_OVERRIDE_FACTOR},
|
||||
{ "sp","spc", _i0, 0, sp_print_spc, sp_get_spc, sp_set_spc, nullptr, 0 }, // spindle state
|
||||
{ "sp","sps", _f0, 0, sp_print_sps, sp_get_sps, sp_set_sps, nullptr, 0 }, // spindle speed
|
||||
};
|
||||
constexpr cfgSubtableFromStaticArray spindle_config_1 {spindle_config_items_1};
|
||||
const configSubtable * const getSpindleConfig_1() { return &spindle_config_1; }
|
||||
|
||||
+6
-121
@@ -28,25 +28,12 @@
|
||||
#ifndef SPINDLE_H_ONCE
|
||||
#define SPINDLE_H_ONCE
|
||||
|
||||
#define SPINDLE_OVERRIDE_ENABLE false
|
||||
#define SPINDLE_OVERRIDE_FACTOR 1.00
|
||||
#define SPINDLE_OVERRIDE_MIN 0.05 // 5%
|
||||
#define SPINDLE_OVERRIDE_MAX 2.00 // 200%
|
||||
#define SPINDLE_OVERRIDE_RAMP_TIME 1 // change sped in seconds
|
||||
|
||||
typedef enum {
|
||||
SPINDLE_DISABLED = 0, // spindle will not operate
|
||||
SPINDLE_PLAN_TO_STOP, // spindle operating, plans to stop
|
||||
SPINDLE_CONTINUOUS, // spindle operating, does not plan to stop
|
||||
} spMode;
|
||||
#define SPINDLE_MODE_MAX SPINDLE_CONTINUOUS
|
||||
|
||||
// spControl enum is used for multiple purposes:
|
||||
// - request a spindle action (OFF, CW, CCW, PAUSE, RESUME)
|
||||
// - keep current spindle state in spindle.state
|
||||
// - store as current direction (CW/CCW) in spindle.direction
|
||||
// - enumerate internal actions such as NOP, REV that are neither states nor controls
|
||||
typedef enum { // how spindle controls are presented by the Gcode parser
|
||||
enum spControl { // how spindle controls are presented by the Gcode parser
|
||||
SPINDLE_OFF = 0, // M5
|
||||
SPINDLE_CW = 1, // M3 and store CW to spindle.direction
|
||||
SPINDLE_CCW = 2, // M4 and store CCW to spsindle.direction
|
||||
@@ -54,52 +41,9 @@ typedef enum { // how spindle controls are presented by the Gco
|
||||
SPINDLE_RESUME = 4, // request RESUME and revert spindle.state to CW, CCW
|
||||
SPINDLE_NOP, // no operation
|
||||
SPINDLE_REV // operation to reverse spindle direction
|
||||
} spControl;
|
||||
};
|
||||
#define SPINDLE_ACTION_MAX SPINDLE_RESUME
|
||||
|
||||
// *** NOTE: The spindle polarity active hi/low values currently agree with ioMode in gpio.h
|
||||
// These will all need to be changed to ACTIVE_HIGH = 0, ACTIVE_LOW = 1
|
||||
// See: https://github.com/synthetos/g2_private/wiki/GPIO-Design-Discussion#settings-common-to-all-io-types
|
||||
|
||||
typedef enum { // Note: These values agree with
|
||||
SPINDLE_ACTIVE_LOW = 0, // Will set output to 0 to enable the spindle or CW direction
|
||||
SPINDLE_ACTIVE_HIGH = 1, // Will set output to 1 to enable the spindle or CW direction
|
||||
} spPolarity;
|
||||
|
||||
typedef enum { // electronic speed controller for some spindles
|
||||
ESC_ONLINE = 0,
|
||||
ESC_OFFLINE,
|
||||
ESC_LOCKOUT,
|
||||
ESC_REBOOTING,
|
||||
ESC_LOCKOUT_AND_REBOOTING,
|
||||
} ESCState;
|
||||
|
||||
/*
|
||||
* Spindle control structure
|
||||
*/
|
||||
|
||||
typedef struct spSpindle {
|
||||
|
||||
spControl state; // {spc:} OFF, ON, PAUSE, RESUME, WAIT
|
||||
spControl direction; // 1=CW, 2=CCW (subset of above state)
|
||||
|
||||
float speed; // {sps:} S in RPM
|
||||
float speed_min; // {spsn:} minimum settable spindle speed
|
||||
float speed_max; // {spsm:} maximum settable spindle speed
|
||||
float speed_actual; // hidden internal value used in speed ramping
|
||||
float speed_change_per_tick; // hidden internal value used in speed ramping
|
||||
|
||||
spPolarity enable_polarity; // {spep:} 0=active low, 1=active high
|
||||
spPolarity dir_polarity; // {spdp:} 0=clockwise low, 1=clockwise high
|
||||
bool pause_enable; // {spph:} pause on feedhold
|
||||
float spinup_delay; // {spde:} optional delay on spindle start (set to 0 to disable)
|
||||
// float spindown_delay; // {spds:} optional delay on spindle stop (set to 0 to disable)
|
||||
|
||||
bool override_enable; // {spoe:} TRUE = spindle speed override enabled (see also m48_enable in canonical machine)
|
||||
float override_factor; // {spo:} 1.0000 x S spindle speed. Go up or down from there
|
||||
} spSpindle_t;
|
||||
extern spSpindle_t spindle;
|
||||
|
||||
/*
|
||||
* Global Scope Functions
|
||||
*/
|
||||
@@ -112,73 +56,14 @@ stat_t spindle_control_sync(spControl control);
|
||||
stat_t spindle_speed_immediate(float speed); // S parameter
|
||||
stat_t spindle_speed_sync(float speed); // S parameter
|
||||
|
||||
bool spindle_ready_to_resume(); // if the spindle can resume at this time, return true
|
||||
bool spindle_is_on_or_paused(); // returns if the stepper is on or paused - IOW would it try to resume from feedhold
|
||||
bool spindle_speed_ramp_from_systick(); // used only in systick call from stepper.cpp
|
||||
bool is_spindle_ready_to_resume(); // if the spindle can resume at this time, return true
|
||||
bool is_spindle_on_or_paused(); // returns if the stepper is on or paused - IOW would it try to resume from feedhold
|
||||
bool do_spindle_speed_ramp_from_systick(); // used only in systick call from stepper.cpp
|
||||
|
||||
stat_t spindle_override_control(const float P_word, const bool P_flag); // M51
|
||||
void spindle_start_override(const float ramp_time, const float override_factor);
|
||||
void spindle_end_override(const float ramp_time);
|
||||
|
||||
stat_t sp_get_spep(nvObj_t *nv);
|
||||
stat_t sp_set_spep(nvObj_t *nv);
|
||||
stat_t sp_get_spdp(nvObj_t *nv);
|
||||
stat_t sp_set_spdp(nvObj_t *nv);
|
||||
stat_t sp_get_spph(nvObj_t *nv);
|
||||
stat_t sp_set_spph(nvObj_t *nv);
|
||||
|
||||
stat_t sp_get_spde(nvObj_t *nv);
|
||||
stat_t sp_set_spde(nvObj_t *nv);
|
||||
//stat_t sp_get_spdn(nvObj_t *nv);
|
||||
//stat_t sp_set_spdn(nvObj_t *nv);
|
||||
|
||||
stat_t sp_get_spsn(nvObj_t *nv);
|
||||
stat_t sp_set_spsn(nvObj_t *nv);
|
||||
stat_t sp_get_spsm(nvObj_t *nv);
|
||||
stat_t sp_set_spsm(nvObj_t *nv);
|
||||
|
||||
stat_t sp_get_spoe(nvObj_t* nv);
|
||||
stat_t sp_set_spoe(nvObj_t* nv);
|
||||
stat_t sp_get_spo(nvObj_t* nv);
|
||||
stat_t sp_set_spo(nvObj_t* nv);
|
||||
|
||||
stat_t sp_get_spc(nvObj_t* nv);
|
||||
stat_t sp_set_spc(nvObj_t* nv);
|
||||
stat_t sp_get_sps(nvObj_t* nv);
|
||||
stat_t sp_set_sps(nvObj_t* nv);
|
||||
|
||||
/*--- text_mode support functions ---*/
|
||||
|
||||
#ifdef __TEXT_MODE
|
||||
|
||||
void sp_print_spmo(nvObj_t* nv);
|
||||
void sp_print_spep(nvObj_t* nv);
|
||||
void sp_print_spdp(nvObj_t* nv);
|
||||
void sp_print_spph(nvObj_t* nv);
|
||||
void sp_print_spde(nvObj_t* nv);
|
||||
// void sp_print_spdn(nvObj_t* nv);
|
||||
void sp_print_spsn(nvObj_t* nv);
|
||||
void sp_print_spsm(nvObj_t* nv);
|
||||
void sp_print_spoe(nvObj_t* nv);
|
||||
void sp_print_spo(nvObj_t* nv);
|
||||
void sp_print_spc(nvObj_t* nv);
|
||||
void sp_print_sps(nvObj_t* nv);
|
||||
|
||||
#else
|
||||
|
||||
#define sp_print_spmo tx_print_stub
|
||||
#define sp_print_spep tx_print_stub
|
||||
#define sp_print_spdp tx_print_stub
|
||||
#define sp_print_spph tx_print_stub
|
||||
#define sp_print_spde tx_print_stub
|
||||
// #define sp_print_spdn tx_print_stub
|
||||
#define sp_print_spsn tx_print_stub
|
||||
#define sp_print_spsm tx_print_stub
|
||||
#define sp_print_spoe tx_print_stub
|
||||
#define sp_print_spo tx_print_stub
|
||||
#define sp_print_spc tx_print_stub
|
||||
#define sp_print_sps tx_print_stub
|
||||
|
||||
#endif // __TEXT_MODE
|
||||
const configSubtable * const getSpindleConfig_1();
|
||||
|
||||
#endif // End of include guard: SPINDLE_H_ONCE
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ Motate::SysTickEvent dwell_systick_event{
|
||||
st_run.dwell_ticks_downcount = 1; // this'll decerement to zero shortly
|
||||
cm->hold_state = FEEDHOLD_MOTION_STOPPED;
|
||||
}
|
||||
if (spindle_speed_ramp_from_systick() && (--st_run.dwell_ticks_downcount == 0)) {
|
||||
if (do_spindle_speed_ramp_from_systick() && (--st_run.dwell_ticks_downcount == 0)) {
|
||||
st_run.dwell_ticks_downcount = 0; // in the case of stop==true, this is needed
|
||||
SysTickTimer.unregisterEvent(&dwell_systick_event);
|
||||
_load_move(); // load the next move at the current interrupt level
|
||||
|
||||
Reference in New Issue
Block a user