diff --git a/TinyG2/canonical_machine.cpp b/TinyG2/canonical_machine.cpp index 8541fc83..e63dc071 100755 --- a/TinyG2/canonical_machine.cpp +++ b/TinyG2/canonical_machine.cpp @@ -702,6 +702,7 @@ stat_t cm_is_alarmed() } /* + * cm_halt_all() - stop, spindle and coolant immediately * cm_halt_motion() - stop motion immediately. Does not affect spindle, coolant, or other IO * * Stop motors and reset all system states accordingly. @@ -709,6 +710,13 @@ stat_t cm_is_alarmed() * in order to prevent an axis from crashing. */ +void cm_halt_all(void) +{ + cm_halt_motion(); + cm_spindle_off_immediate(); + cm_coolant_off_immediate(); +} + void cm_halt_motion(void) { mp_halt_runtime(); // stop the runtime. Do this immediately. (Reset is in cm_clear) @@ -750,8 +758,10 @@ stat_t cm_alarm(stat_t status, const char *msg) cm.machine_state = MACHINE_ALARM; cm_request_feedhold(); // stop motion cm_request_queue_flush(); // do a queue flush once runtime is not busy - cm_spindle_control_immediate(SPINDLE_OFF); - cm_coolant_off_immediate(); +// cm_spindle_control_immediate(SPINDLE_OFF); +// cm_coolant_off_immediate(); +// cm_spindle_optional_pause(spindle.pause_on_hold); +// cm_coolant_optional_pause(coolant.pause_on_hold); // build a secondary message string (info) and call the exception report /* @@ -790,7 +800,7 @@ stat_t cm_shutdown(stat_t status, const char *msg) } cm_halt_motion(); // halt motors (may have already been done from GPIO) spindle_reset(); // stop spindle immediately and set speed to 0 RPM - coolant_reset(); + coolant_reset(); cm_queue_flush(); // flush all queues and reset positions for (uint8_t i = 0; i < HOMING_AXES; i++) { // unhome axes and the machine @@ -1384,8 +1394,6 @@ stat_t cm_traverse_override_factor(uint8_t flag) // M51 * cm_request_queue_flush() */ void cm_request_feedhold(void) { -// OMC if (cm.estop_state != ESTOP_INACTIVE) { return; } - // honor request if not already in a feedhold and you are moving if ((cm.hold_state == FEEDHOLD_OFF) && (cm.motion_state != MOTION_STOP)) { cm.hold_state = FEEDHOLD_REQUESTED; @@ -1394,19 +1402,15 @@ void cm_request_feedhold(void) { void cm_request_end_hold(void) { -// OMC if (cm.estop_state != ESTOP_INACTIVE) { return; } cm.end_hold_requested = true; } void cm_request_queue_flush() { -// OMC if (cm.estop_state != ESTOP_INACTIVE) { return; } - if ((cm.hold_state != FEEDHOLD_OFF) && // don't honor request unless you are in a feedhold (cm.queue_flush_state == FLUSH_OFF)) { // ...and only once xio_flush_read(); // flush the input buffers - you can do that now cm.queue_flush_state = FLUSH_REQUESTED; // request planner flush once motion has stopped -// OMC cm.waiting_for_gcode_resume = true; } } @@ -1442,10 +1446,11 @@ bool cm_has_hold() void cm_start_hold() { - if (mp_has_runnable_buffer()) { // meaning there's something running + if (mp_has_runnable_buffer()) { // meaning there's something running cm_spindle_optional_pause(spindle.pause_on_hold); // pause if this option is selected - cm_set_motion_state(MOTION_HOLD); - cm.hold_state = FEEDHOLD_SYNC; // invokes hold from aline execution + cm_coolant_optional_pause(coolant.pause_on_hold); // pause if this option is selected + cm_set_motion_state(MOTION_HOLD); + cm.hold_state = FEEDHOLD_SYNC; // invokes hold from aline execution } } @@ -1457,15 +1462,18 @@ void cm_end_hold() // State machine cases: if (cm.machine_state == MACHINE_ALARM) { - cm_spindle_control_immediate(SPINDLE_OFF); + cm_spindle_off_immediate(); + cm_coolant_off_immediate(); } else if (cm.motion_state == MOTION_STOP) { // && (! MACHINE_ALARM) - cm_spindle_control_immediate(SPINDLE_OFF); + cm_spindle_off_immediate(); + cm_coolant_off_immediate(); cm_cycle_end(); } else { // (MOTION_RUN || MOTION_PLANNING) && (! MACHINE_ALARM) cm_cycle_start(); cm_spindle_resume(spindle.dwell_seconds); + cm_coolant_resume(); st_request_exec_move(); } } @@ -1561,8 +1569,9 @@ static void _exec_program_finalize(float *value, float *flag) cm_set_coord_system(cm.coord_system); // reset to default coordinate system cm_select_plane(cm.select_plane); // reset to default arc plane cm_set_distance_mode(cm.distance_mode); - cm_spindle_control_immediate(SPINDLE_OFF); // M5 - cm_flood_coolant_control(false); // M9 + cm_spindle_off_immediate(); // M5 + cm_coolant_off_immediate(); // M9 +// cm_flood_coolant_control(false); // M9 cm_set_feed_rate_mode(UNITS_PER_MINUTE_MODE); // G94 cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE);// NIST specifies G1 (MOTION_MODE_STRAIGHT_FEED), but we cancel motion mode. Safer. } diff --git a/TinyG2/canonical_machine.h b/TinyG2/canonical_machine.h index 12789d27..9aaf20ee 100755 --- a/TinyG2/canonical_machine.h +++ b/TinyG2/canonical_machine.h @@ -337,11 +337,6 @@ typedef struct GCodeState { // Gcode model state - used by model, planning an uint8_t absolute_override; // G53 TRUE = move using machine coordinates - this block only (G53) uint8_t tool; // G // M6 tool change - moves "tool_select" to "tool" uint8_t tool_select; // G // T value - T sets this value -// uint8_t mist_coolant; // G // TRUE = mist on (M7), FALSE = off (M9) -// uint8_t flood_coolant; // G // TRUE = flood on (M8), FALSE = off (M9) -// uint8_t spindle_state; // G // 0=OFF (M5), 1=CW (M3), 2=CCW (M4) -// uint8_t spindle_pause; // G // 0=operating, 1=paused - } GCodeState_t; typedef struct GCodeStateExtended { // Gcode dynamic state extensions - used by model and arcs @@ -402,7 +397,7 @@ typedef struct GCodeInput { // Gcode model inputs - meaning depends on contex uint8_t mist_coolant; // TRUE = mist on (M7), FALSE = off (M9) uint8_t flood_coolant; // TRUE = flood on (M8), FALSE = off (M9) - uint8_t spindle_state; // 0=OFF (M5), 1=CW (M3), 2=CCW (M4) + uint8_t spindle_control; // 0=OFF (M5), 1=CW (M3), 2=CCW (M4) float spindle_speed; // in RPM float spindle_override_factor; // 1.0000 x S spindle speed. Go up or down from there uint8_t spindle_override_enable; // TRUE = override enabled @@ -577,7 +572,8 @@ stat_t cm_clr(nvObj_t *nv); // clear alarm a void cm_clear(void); // raw clear command void cm_parse_clear(char *s); // parse gcode for M30 or M2 clear condition stat_t cm_is_alarmed(void); // return non-zero status if alarm, shutdown or panic -void cm_halt_motion(void); // halt movement (immediate stop) but not spindle & other IO +void cm_halt_all(void); // halt motion, spindle and coolant +void cm_halt_motion(void); // halt motion (immediate stop) but not spindle & other IO stat_t cm_alarm(stat_t status, const char *msg); // enter alarm state - preserve Gcode state stat_t cm_shutdown(stat_t status, const char *msg); // enter shutdown state - dump all state stat_t cm_panic(stat_t status, const char *msg); // enter panic state - needs RESET diff --git a/TinyG2/coolant.cpp b/TinyG2/coolant.cpp index e233d18f..05c4212f 100755 --- a/TinyG2/coolant.cpp +++ b/TinyG2/coolant.cpp @@ -78,6 +78,7 @@ void cm_coolant_optional_pause(bool option) float value[] = { 0,0,0,0,0,0 }; float flags[] = { 0,0,0,0,0,0 }; + if (coolant.flood_state) { flags[COOLANT_FLOOD] = 1.0; @@ -88,6 +89,7 @@ void cm_coolant_optional_pause(bool option) coolant.mist_pause = COOLANT_PAUSE; // mark as paused } _exec_coolant_control(value, flags); // execute (w/o changing local state) + } void cm_coolant_resume() @@ -95,6 +97,9 @@ void cm_coolant_resume() float value[] = { 0,0,0,0,0,0 }; float flags[] = { 0,0,0,0,0,0 }; + cmCoolantState saved_flood_state = coolant.flood_state; + cmCoolantState saved_mist_state = coolant.mist_state; + if (coolant.flood_pause == COOLANT_PAUSE) { flags[COOLANT_FLOOD] = 1.0; value[COOLANT_FLOOD] = (float)coolant.flood_state; @@ -105,7 +110,9 @@ void cm_coolant_resume() value[COOLANT_MIST] = (float)coolant.flood_state; coolant.mist_pause = COOLANT_NORMAL; // mark as not paused } - _exec_coolant_control(value, flags); // execute (w/o changing local state) + _exec_coolant_control(value, flags); // execute (changes state) + coolant.flood_state = saved_flood_state; // restore state + coolant.mist_state = saved_mist_state; } #ifdef __ARM diff --git a/TinyG2/coolant.h b/TinyG2/coolant.h index 0ccc65bf..033f6891 100755 --- a/TinyG2/coolant.h +++ b/TinyG2/coolant.h @@ -77,7 +77,8 @@ void coolant_reset(); stat_t cm_mist_coolant_control(uint8_t mist_state); // M7 stat_t cm_flood_coolant_control(uint8_t flood_state); // M8, M9 void cm_coolant_off_immediate(void); -void cm_coolant_control_immediate(cmCoolantState coolant_state); +void cm_coolant_optional_pause(bool option); +void cm_coolant_resume(void); /*--- text_mode support functions ---*/ diff --git a/TinyG2/gcode_parser.cpp b/TinyG2/gcode_parser.cpp index 4c82263d..a926ecab 100755 --- a/TinyG2/gcode_parser.cpp +++ b/TinyG2/gcode_parser.cpp @@ -339,9 +339,9 @@ static stat_t _parse_gcode_block(char_t *buf) SET_MODAL (MODAL_GROUP_M4, program_flow, PROGRAM_STOP); case 2: case 30: SET_MODAL (MODAL_GROUP_M4, program_flow, PROGRAM_END); - case 3: SET_MODAL (MODAL_GROUP_M7, spindle_state, SPINDLE_CW); - case 4: SET_MODAL (MODAL_GROUP_M7, spindle_state, SPINDLE_CCW); - case 5: SET_MODAL (MODAL_GROUP_M7, spindle_state, SPINDLE_OFF); + case 3: SET_MODAL (MODAL_GROUP_M7, spindle_control, SPINDLE_CONTROL_CW); + case 4: SET_MODAL (MODAL_GROUP_M7, spindle_control, SPINDLE_CONTROL_CCW); + case 5: SET_MODAL (MODAL_GROUP_M7, spindle_control, SPINDLE_CONTROL_OFF); case 6: SET_NON_MODAL (tool_change, true); case 7: SET_MODAL (MODAL_GROUP_M8, mist_coolant, true); case 8: SET_MODAL (MODAL_GROUP_M8, flood_coolant, true); @@ -434,7 +434,7 @@ static stat_t _execute_gcode_block() // EXEC_FUNC(cm_spindle_override_factor, spindle_override_factor); EXEC_FUNC(cm_select_tool, tool_select); // tool_select is where it's written EXEC_FUNC(cm_change_tool, tool_change); - EXEC_FUNC(cm_spindle_control, spindle_state); // spindle on or off + EXEC_FUNC(cm_spindle_control, spindle_control); // spindle CW, CCW, OFF EXEC_FUNC(cm_mist_coolant_control, mist_coolant); EXEC_FUNC(cm_flood_coolant_control, flood_coolant); // also disables mist coolant if OFF // EXEC_FUNC(cm_feed_rate_override_enable, feed_rate_override_enable); diff --git a/TinyG2/gpio.cpp b/TinyG2/gpio.cpp index 80b3bb6c..daba9d4e 100755 --- a/TinyG2/gpio.cpp +++ b/TinyG2/gpio.cpp @@ -256,7 +256,7 @@ void static _handle_pin_changed(const uint8_t input_num_ext, const int8_t pin_va cm_start_hold(); // for now is same as STOP } if (in->action == INPUT_ACTION_HALT) { - cm_halt_motion(); // hard stop + cm_halt_all(); // hard stop, including spindle and coolant } if (in->action == INPUT_ACTION_PANIC) { char msg[10]; diff --git a/TinyG2/spindle.cpp b/TinyG2/spindle.cpp index df336edd..309cccf1 100755 --- a/TinyG2/spindle.cpp +++ b/TinyG2/spindle.cpp @@ -45,11 +45,12 @@ cmSpindleton_t spindle; static void _exec_spindle_speed(float *value, float *flag); static void _exec_spindle_control(float *value, float *flag); -static float _get_spindle_pwm (cmSpindleState spindle_state); +static float _get_spindle_pwm (cmSpindleState state, cmSpindleDir direction); +//static void _spindle_on_immediate(void); /* * spindle_init() - * spindle_reset() + * spindle_reset() - stop spindle, set speed to zero, and reset values */ void spindle_init() { @@ -64,7 +65,7 @@ void spindle_reset() { float value[AXES] = { 0,0,0,0,0,0 }; // set spindle speed to zero _exec_spindle_speed(value, value); - cm_spindle_control_immediate(SPINDLE_OFF); // turn spindle off + cm_spindle_off_immediate(); // turn spindle off } /* @@ -84,107 +85,86 @@ stat_t cm_set_spindle_speed(float speed) static void _exec_spindle_speed(float *value, float *flag) { spindle.speed = value[0]; - pwm_set_duty(PWM_1, _get_spindle_pwm(spindle.state) ); // update spindle speed if we're running - -/* OMC code - uint8_t spindle_state = cm.gm.spindle_state & (~SPINDLE_PAUSED); - bool paused = cm.gm.spindle_state & SPINDLE_PAUSED; - if(cm.estop_state != 0 || cm.interlock_state != 0 || paused) { - - if (cm.safety_interlock_state != SAFETY_INTERLOCK_ENGAGED || paused) { - spindle_state = SPINDLE_OFF; - } - pwm_set_duty(PWM_1, cm_get_spindle_pwm(spindle_state) ); // update spindle speed if we're running -*/ + spindle.direction = (cmSpindleDir)value[1]; + // update spindle speed if we're running + pwm_set_duty(PWM_1, _get_spindle_pwm(spindle.state, spindle.direction)); } /* * cm_spindle_optional_pause() - pause spindle immediately if option is true * cm_spindle_resume() - restart a paused spindle with an optional dwell + * cm_spindle_off_immediate() - turn on/off spindle w/o planning */ void cm_spindle_optional_pause(bool option) { - if (option && (spindle.state != SPINDLE_OFF)) { - cmSpindleState state = spindle.state; // local copy - cm_spindle_control_immediate(SPINDLE_OFF); // changes spindle state - spindle.pause = SPINDLE_PAUSED; // mark as paused - spindle.state = state; // restore previous spindle state + if (option && spindle.state == SPINDLE_ON) { + cm_spindle_off_immediate(); + spindle.state = SPINDLE_PAUSE; } } void cm_spindle_resume(float dwell_seconds) { - if(spindle.pause == SPINDLE_PAUSED) { + if(spindle.state == SPINDLE_PAUSE) { + spindle.state = SPINDLE_ON; mp_request_out_of_band_dwell(dwell_seconds); - cm_spindle_control_immediate(spindle.state); + float value[] = { (float)SPINDLE_ON, (float)spindle.direction, 0,0,0,0 }; + _exec_spindle_control(value, value); } - spindle.pause = SPINDLE_NORMAL; +} + +void cm_spindle_off_immediate() +{ + spindle.state = SPINDLE_OFF; + float value[] = { (float)SPINDLE_OFF, 0,0,0,0,0 }; + _exec_spindle_control(value, value); } /* * cm_spindle_control() - queue the spindle command to the planner buffer. Observe PAUSE - * cm_spindle_control_immediate() - turn on/off spindle w/o planning - * _exec_spindle_control() - execute the spindle command (called from planner) + * _exec_spindle_control() - actually execute the spindle command */ -stat_t cm_spindle_control(uint8_t spindle_state) +stat_t cm_spindle_control(uint8_t control) // requires SPINDLE_CONTROL_xxx style args { -/* OMC code - if (cm.gm.spindle_state & SPINDLE_PAUSED) - spindle_state |= SPINDLE_PAUSED; - - // This is kind of tricky... If we're in interlock but still moving around, and we get an - // M3, we just start a feedhold... Usually, before we call cm_start_hold we check if there's - // anything in the buffer to actually process the feedhold. Here, we're just about to add - // something to the buffer, so we skip the check. - if (cm.safety_interlock_state != SAFETY_INTERLOCK_ENGAGED && - !(spindle_state & SPINDLE_PAUSED) && spindle_state != SPINDLE_OFF) { - cm_start_hold(); - } -*/ - float value[AXES] = { (float)spindle_state, 0,0,0,0,0 }; + if (control == SPINDLE_CONTROL_OFF) { + spindle.state = SPINDLE_OFF; + } else { + spindle.state = SPINDLE_ON; + if (control == SPINDLE_CONTROL_CW) { + spindle.direction = SPINDLE_CW; + } else { + spindle.direction = SPINDLE_CCW; + } + } + float value[] = { (float)spindle.state, (float)spindle.direction, 0,0,0,0 }; mp_queue_command(_exec_spindle_control, value, value); return(STAT_OK); } -void cm_spindle_control_immediate(cmSpindleState spindle_state) -{ -/* OMC code - spindle_state &= ~SPINDLE_PAUSED; // remove the pause bit - if (spindle_state != cm.gm.spindle_state) { // if it's already there, skip it - float value[AXES] = { (float)spindle_state, 0,0,0,0,0 }; - _exec_spindle_control(value, value); - } -*/ - if (spindle_state == SPINDLE_OFF) { // cancel PAUSE if turning off spindle - spindle.pause = SPINDLE_NORMAL; - } - float value[AXES] = { (float)spindle_state, 0,0,0,0,0 }; - _exec_spindle_control(value, value); -} - #ifdef __ARM -#define _set_spindle_enable_bit_hi() spindle_enable_pin.set() -#define _set_spindle_enable_bit_lo() spindle_enable_pin.clear() -#define _set_spindle_direction_bit_hi() spindle_dir_pin.set() -#define _set_spindle_direction_bit_lo() spindle_dir_pin.clear() + #define _set_spindle_enable_bit_hi() spindle_enable_pin.set() + #define _set_spindle_enable_bit_lo() spindle_enable_pin.clear() + #define _set_spindle_direction_bit_hi() spindle_dir_pin.set() + #define _set_spindle_direction_bit_lo() spindle_dir_pin.clear() #endif #ifdef __AVR -#define _set_spindle_enable_bit_hi() gpio_set_bit_on(SPINDLE_BIT) -#define _set_spindle_enable_bit_lo() gpio_set_bit_off(SPINDLE_BIT) -#define _set_spindle_direction_bit_hi() gpio_set_bit_on(SPINDLE_DIR) -#define _set_spindle_direction_bit_lo() gpio_set_bit_off(SPINDLE_DIR) + #define _set_spindle_enable_bit_hi() gpio_set_bit_on(SPINDLE_BIT) + #define _set_spindle_enable_bit_lo() gpio_set_bit_off(SPINDLE_BIT) + #define _set_spindle_direction_bit_hi() gpio_set_bit_on(SPINDLE_DIR) + #define _set_spindle_direction_bit_lo() gpio_set_bit_off(SPINDLE_DIR) #endif static void _exec_spindle_control(float *value, float *flag) { - spindle.state = (cmSpindleState)value[0]; // set spindle state + spindle.state = (cmSpindleState)value[0]; // set spindle state for the record + spindle.direction = (cmSpindleDir)value[1]; // set spindle direction for the record bool enable = spindle.state ^ ~spindle.polarity_enable; // enable is the polarity to set if turning ON - if ((spindle.state == SPINDLE_CW) || (spindle.state == SPINDLE_CCW)) { + if (spindle.state == SPINDLE_ON) { // spindle is on and CW or CCW // set the direction first - if ((spindle.state & 0x02) ^ spindle.polarity_dir) { // xor the CCW bit to get direction + if (spindle.direction ^ spindle.polarity_dir) { // xor the CCW bit to get direction _set_spindle_direction_bit_hi(); } else { _set_spindle_direction_bit_lo(); @@ -197,54 +177,36 @@ static void _exec_spindle_control(float *value, float *flag) _set_spindle_enable_bit_lo(); } - } else { // SPINDLE_OFF (for safety - any value other than CW or CCW causes stop) + } else { // SPINDLE_OFF (for safety - any value other than ON causes stop) if (enable) { _set_spindle_enable_bit_lo(); } else { _set_spindle_enable_bit_hi(); } } - pwm_set_duty(PWM_1, _get_spindle_pwm(spindle.state)); - -/* OMC code - uint8_t spindle_state = (uint8_t)value[0]; - bool paused = spindle_state & SPINDLE_PAUSED; - uint8_t raw_spindle_state = spindle_state & (~SPINDLE_PAUSED); - - if(cm.estop_state != 0) { // In E-stop, don't process any spindle commands - spindle_state = raw_spindle_state = SPINDLE_OFF; - } else - // If we're paused or in interlock, send the spindle an "OFF" command (invisible to cm.gm) - //++++ THE LOGIC HERE MIGHT BE WRONG - safety_interlock_requested versus safety_interlock_state - if (paused || cm.safety_interlock_requested != 0) { - raw_spindle_state = SPINDLE_OFF; - } - //FIXME: else if(we just rebooted the ESC)... delay the pwm command... - cm_set_spindle_state (MODEL, spindle_state); - - //// the rest is the AVR/ARM bit twiddling..., and the pwm_set_duty() -*/ + pwm_set_duty(PWM_1, _get_spindle_pwm(spindle.state, spindle.direction)); } /* * _get_spindle_pwm() - return PWM phase (duty cycle) for dir and speed */ -static float _get_spindle_pwm (cmSpindleState spindle_state) + +static float _get_spindle_pwm (cmSpindleState state, cmSpindleDir direction) { float speed_lo=0, speed_hi=0, phase_lo=0, phase_hi=0; - if (spindle_state == SPINDLE_CW ) { + if (direction == SPINDLE_CW ) { speed_lo = pwm.c[PWM_1].cw_speed_lo; speed_hi = pwm.c[PWM_1].cw_speed_hi; phase_lo = pwm.c[PWM_1].cw_phase_lo; phase_hi = pwm.c[PWM_1].cw_phase_hi; - } else if (spindle_state == SPINDLE_CCW ) { + } else if (direction == SPINDLE_CCW ) { speed_lo = pwm.c[PWM_1].ccw_speed_lo; speed_hi = pwm.c[PWM_1].ccw_speed_hi; phase_lo = pwm.c[PWM_1].ccw_phase_lo; phase_hi = pwm.c[PWM_1].ccw_phase_hi; } - if (spindle_state==SPINDLE_CW || spindle_state==SPINDLE_CCW ) { + if (state == SPINDLE_ON) { // clamp spindle speed to lo/hi range if (cm.gm.spindle_speed < speed_lo) { cm.gm.spindle_speed = speed_lo; @@ -294,7 +256,7 @@ const char fmt_spo[] PROGMEM = "[spo] spindle polarity on%10d [0=low is enabled, const char fmt_spd[] PROGMEM = "[spd] spindle polarity direction%3d [0=low is clockwise,1=high is clockwise]\n"; const char fmt_sph[] PROGMEM = "[sph] spindle pause on hold%8d [0=no,1=pause_on_hold]\n"; const char fmt_sdw[] PROGMEM = "[sdw] spindle auto-dwell time%8.1f seconds\n"; -const char fmt_spc[] PROGMEM = "Spindle Control:%6d [0=OFF,1=CW,2=CCW]\n"; +const char fmt_spc[] PROGMEM = "Spindle Control:%6d [0=OFF,1=CW,2=CCW,3=CW_paused,4=CCW_paused]\n"; const char fmt_sps[] PROGMEM = "Spindle Speed: %8.0f rpm\n"; void cm_print_spo(nvObj_t *nv) { text_print(nv, fmt_spo);} // TYPE_INT diff --git a/TinyG2/spindle.h b/TinyG2/spindle.h index 6c8c6dbf..3aed7eab 100755 --- a/TinyG2/spindle.h +++ b/TinyG2/spindle.h @@ -28,22 +28,28 @@ #ifndef SPINDLE_H_ONCE #define SPINDLE_H_ONCE -typedef enum { // spindle state settings (See hardware.h for bit settings) +typedef enum { // how spindle controls are presented by the Gcode parser + SPINDLE_CONTROL_OFF = 0, // M5 + SPINDLE_CONTROL_CW, // M3 + SPINDLE_CONTROL_CCW // M4 +} cmSpindleControl; + +typedef enum { // spindle ON/OFF state SPINDLE_OFF = 0, - SPINDLE_CW, - SPINDLE_CCW, + SPINDLE_ON, + SPINDLE_PAUSE // meaning it was on and now it's off } cmSpindleState; +typedef enum { // spindle direction state + SPINDLE_CW = 0, + SPINDLE_CCW +} cmSpindleDir; + typedef enum { SPINDLE_ACTIVE_LOW = 0, SPINDLE_ACTIVE_HIGH } cmSpindlePolarity; -typedef enum { - SPINDLE_NORMAL = 0, - SPINDLE_PAUSED, -} cmSpindlePause; - typedef enum { ESC_ONLINE = 0, ESC_OFFLINE, @@ -57,19 +63,19 @@ typedef enum { */ typedef struct cmSpindleSingleton { - // configuration - cmSpindlePause pause_on_hold; // pause on feedhold + + float speed; // S in RPM + cmSpindleState state; // current spindle state, OFF, ON, PAUSE + cmSpindleDir direction; // current spindle direction, CW, CCW + + bool pause_on_hold; // pause on feedhold cmSpindlePolarity polarity_enable; // 0=active low, 1=active high cmSpindlePolarity polarity_dir; // 0=clockwise low, 1=clockwise high float dwell_seconds; // dwell on spindle resume + // float override_factor; // 1.0000 x S spindle speed. Go up or down from there // uint8_t override_enable; // TRUE = override enabled - // state variables - float speed; - cmSpindleState state; // current spindle state, OFF, CW, CCW. Might be paused, though - cmSpindlePause pause; // pause state - applies to spindle state, above - cmESCState esc_state; // state management for ESC controller uint32_t esc_boot_timer; // When the ESC last booted up uint32_t esc_lockout_timer; // When the ESC lockout last triggered @@ -84,8 +90,8 @@ extern cmSpindleton_t spindle; void spindle_init(); void spindle_reset(); stat_t cm_set_spindle_speed(float speed); // S parameter -stat_t cm_spindle_control(uint8_t spindle_state);// M3, M4, M5 integrated spindle control -void cm_spindle_control_immediate(cmSpindleState spindle_state); //like cm_spindle_control but not synchronized to planner +stat_t cm_spindle_control(uint8_t control); // M3, M4, M5 integrated spindle control +void cm_spindle_off_immediate(void); void cm_spindle_optional_pause(bool option); // stop spindle based on system options selected void cm_spindle_resume(float dwell_seconds); // restart spindle after pause based on previous state diff --git a/TinyG2/tinyg2.h b/TinyG2/tinyg2.h index 57fd894a..be44cc1e 100755 --- a/TinyG2/tinyg2.h +++ b/TinyG2/tinyg2.h @@ -38,7 +38,7 @@ /****** REVISIONS ******/ #ifndef TINYG_FIRMWARE_BUILD -#define TINYG_FIRMWARE_BUILD 080.29 // coolant checkpoint +#define TINYG_FIRMWARE_BUILD 080.30 // spindle states are more rational #endif #define TINYG_FIRMWARE_VERSION 0.98 // firmware major version