static stat_t _homing_error_exit(int8_t axis) { // Generate the warning message. Since the error exit returns via the homing callback // - and not the main controller - it requires its own display processing cmd_reset_list(); if (axis == -2) { cmd_add_conditional_message((const char_t *)"*** WARNING *** Homing error: Specified axis(es) cannot be homed");; } else { char message[CMD_MESSAGE_LEN]; sprintf_P(message, PSTR("*** WARNING *** Homing error: %c axis settings misconfigured"), cm_get_axis_char(axis)); cmd_add_conditional_message((char_t *)message); } cmd_print_list(STAT_HOMING_CYCLE_FAILED, TEXT_INLINE_VALUES, JSON_RESPONSE_FORMAT); // clean up and exit mp_flush_planner(); // should be stopped, but in case of switch closure // don't use cm_request_queue_flush() here cm_set_coord_system(hm.saved_coord_system); // restore to work coordinate system cm_set_units_mode(hm.saved_units_mode); cm_set_distance_mode(hm.saved_distance_mode); cm_set_feed_rate(hm.saved_feed_rate); cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE); cm.cycle_state = CYCLE_OFF; cm_cycle_end(); return (STAT_HOMING_CYCLE_FAILED); // homing state remains HOMING_NOT_HOMED }
stat_t mp_runtime_command(mpBuf_t *bf) { bf->cm_func(bf->value_vector, bf->flag_vector); // 2 vectors used by callbacks if (mp_free_run_buffer()) cm_cycle_end(); // free buffer & perform cycle_end if planner is empty return (STAT_OK); }
static stat_t _exec_dwell(mpBuf_t *bf) { // st_prep_dwell((uint32_t)(bf->gm.move_time * 1000000));// convert seconds to uSec st_prep_dwell((uint32_t)(bf->gm.move_time));// convert seconds to uSec if (mp_free_run_buffer()) cm_cycle_end(); // free buffer & perform cycle_end if planner is empty return (STAT_OK); }
static stat_t _homing_axis_start(int8_t axis) { // get the first or next axis if ((axis = _get_next_axis(axis)) < 0) { // axes are done or error if (axis == -1) { // -1 is done return (_set_homing_func(_homing_finalize_exit)); } else if (axis == -2) { // -2 is error cm_set_units_mode(hm.saved_units_mode); cm_set_distance_mode(hm.saved_distance_mode); cm.cycle_state = CYCLE_OFF; cm_cycle_end(); return (_homing_error_exit(-2)); } } // trap gross mis-configurations if ((fp_ZERO(cm.a[axis].search_velocity)) || (fp_ZERO(cm.a[axis].latch_velocity))) { return (_homing_error_exit(axis)); } if ((cm.a[axis].travel_max <= 0) || (cm.a[axis].latch_backoff <= 0)) { return (_homing_error_exit(axis)); } // determine the switch setup and that config is OK hm.min_mode = get_switch_mode(MIN_SWITCH(axis)); hm.max_mode = get_switch_mode(MAX_SWITCH(axis)); if ( ((hm.min_mode & SW_HOMING_BIT) ^ (hm.max_mode & SW_HOMING_BIT)) == 0) {// one or the other must be homing return (_homing_error_exit(axis)); // axis cannot be homed } hm.axis = axis; // persist the axis hm.search_velocity = fabs(cm.a[axis].search_velocity); // search velocity is always positive hm.latch_velocity = fabs(cm.a[axis].latch_velocity); // latch velocity is always positive // setup parameters homing to the minimum switch if (hm.min_mode & SW_HOMING_BIT) { hm.homing_switch = MIN_SWITCH(axis); // the min is the homing switch hm.limit_switch = MAX_SWITCH(axis); // the max would be the limit switch hm.search_travel = -cm.a[axis].travel_max; // search travels in negative direction hm.latch_backoff = cm.a[axis].latch_backoff; // latch travels in positive direction hm.zero_backoff = cm.a[axis].zero_backoff; // setup parameters for positive travel (homing to the maximum switch) } else { hm.homing_switch = MAX_SWITCH(axis); // the max is the homing switch hm.limit_switch = MIN_SWITCH(axis); // the min would be the limit switch hm.search_travel = cm.a[axis].travel_max; // search travels in positive direction hm.latch_backoff = -cm.a[axis].latch_backoff; // latch travels in negative direction hm.zero_backoff = -cm.a[axis].zero_backoff; } // if homing is disabled for the axis then skip to the next axis uint8_t sw_mode = get_switch_mode(hm.homing_switch); if ((sw_mode != SW_MODE_HOMING) && (sw_mode != SW_MODE_HOMING_LIMIT)) { return (_set_homing_func(_homing_axis_start)); } // disable the limit switch parameter if there is no limit switch if (get_switch_mode(hm.limit_switch) == SW_MODE_DISABLED) { hm.limit_switch = -1;} hm.saved_jerk = cm.a[axis].jerk_max; // save the max jerk value return (_set_homing_func(_homing_axis_clear)); // start the clear }
void mp_free_run_buffer() // EMPTY current run buf & adv to next { mp_clear_buffer(mb.r); // clear it out (& reset replannable) // mb.r->buffer_state = MP_BUFFER_EMPTY; // redundant after the clear, above mb.r = mb.r->nx; // advance to next run buffer if (mb.r->buffer_state == MP_BUFFER_QUEUED) {// only if queued... mb.r->buffer_state = MP_BUFFER_PENDING; // pend next buffer } if (mb.w == mb.r) cm_cycle_end(); // end the cycle if the queue empties mb.buffers_available++; rpt_request_queue_report(-1); // add to the "removed buffers" count }
static stat_t _homing_finalize_exit(int8_t axis) // third part of return to home { mp_flush_planner(); // should be stopped, but in case of switch closure. // don't use cm_request_queue_flush() here cm_set_coord_system(hm.saved_coord_system); // restore to work coordinate system cm_set_units_mode(hm.saved_units_mode); cm_set_distance_mode(hm.saved_distance_mode); cm_set_feed_rate(hm.saved_feed_rate); cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE); cm.cycle_state = CYCLE_OFF; // required cm_cycle_end(); return (STAT_OK); }
static stat_t _homing_finalize_exit(int8_t axis) // third part of return to home { mp_flush_planner(); // should be stopped, but in case of switch closure. // don't use cm_request_queue_flush() here cm_set_coord_system(hm.saved_coord_system); // restore to work coordinate system cm_set_units_mode(hm.saved_units_mode); cm_set_distance_mode(hm.saved_distance_mode); cm_set_feed_rate(hm.saved_feed_rate); cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE); cm.homing_state = HOMING_HOMED; cm.cycle_state = CYCLE_OFF; // required cm_cycle_end(); //+++++ DIAGNOSTIC +++++ // printf("Homed: posX: %6.3f, posY: %6.3f\n", (double)gm.position[AXIS_X], (double)gm.target[AXIS_Y]); return (STAT_OK); }