static uint8_t _execute_gcode_block() { uint8_t status = TG_OK; cm_set_model_linenum(gn.linenum); EXEC_FUNC(cm_set_inverse_feed_rate_mode, inverse_feed_rate_mode); EXEC_FUNC(cm_set_feed_rate, feed_rate); EXEC_FUNC(cm_set_spindle_speed, spindle_speed); EXEC_FUNC(cm_select_tool, tool); EXEC_FUNC(cm_change_tool, tool); EXEC_FUNC(cm_spindle_control, spindle_mode); // spindle on or 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_override_enable, feed_override_enable); if (gn.next_action == NEXT_ACTION_DWELL) { // G4 - dwell ritorno(cm_dwell(gn.dwell_time)); // return if error, otherwise complete the block } EXEC_FUNC(cm_select_plane, select_plane); EXEC_FUNC(cm_set_units_mode, units_mode); //--> cutter radius compensation goes here //--> cutter length compensation goes here EXEC_FUNC(cm_set_coord_system, coord_system); EXEC_FUNC(cm_set_path_control, path_control); EXEC_FUNC(cm_set_distance_mode, distance_mode); //--> set retract mode goes here switch (gn.next_action) { case NEXT_ACTION_GO_HOME: { status = cm_return_to_home(); break;} case NEXT_ACTION_SEARCH_HOME: { status = cm_homing_cycle(); break;} case NEXT_ACTION_SET_COORD_DATA: { status = cm_set_coord_offsets(coord_select, gn.target, gf.target); break;} case NEXT_ACTION_SET_ORIGIN_OFFSETS: { status = cm_set_origin_offsets(gn.target, gf.target); break;} case NEXT_ACTION_RESET_ORIGIN_OFFSETS: { status = cm_reset_origin_offsets(); break;} case NEXT_ACTION_SUSPEND_ORIGIN_OFFSETS: { status = cm_suspend_origin_offsets(); break;} case NEXT_ACTION_RESUME_ORIGIN_OFFSETS: { status = cm_resume_origin_offsets(); break;} case NEXT_ACTION_DEFAULT: { cm_set_absolute_override(gn.absolute_override); // apply override setting to gm struct switch (gn.motion_mode) { case MOTION_MODE_CANCEL_MOTION_MODE: { gm.motion_mode = gn.motion_mode; break;} case MOTION_MODE_STRAIGHT_TRAVERSE: { status = cm_straight_traverse(gn.target, gf.target); break;} case MOTION_MODE_STRAIGHT_FEED: { status = cm_straight_feed(gn.target, gf.target); break;} case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC: // gf.radius sets radius mode if radius was collected in gn { status = cm_arc_feed(gn.target, gf.target, gn.arc_offset[0], gn.arc_offset[1], gn.arc_offset[2], gn.arc_radius, gn.motion_mode); break;} } cm_set_absolute_override(false); // now un-set it (for reporting purposes) } } if (gf.program_flow == true) { // do the M stops: M0, M1, M2, M30, M60 } return (status); }
static stat_t _homing_axis_move(int8_t axis, float target, float velocity) { float vect[] = {0,0,0,0,0,0}; float flags[] = {false, false, false, false, false, false}; vect[axis] = target; flags[axis] = true; cm_set_feed_rate(velocity); mp_flush_planner(); // don't use cm_request_queue_flush() here cm_request_cycle_start(); ritorno(cm_straight_feed(vect, flags)); return (STAT_EAGAIN); }
static stat_t _probing_start() { // initial probe state, don't probe if we're already contacted! int8_t probe = gpio_read_input(pb.probe_input); // false is SW_OPEN in old code, and INPUT_INACTIVE in new if ( probe == INPUT_INACTIVE ) { cm_straight_feed(pb.target, pb.flags); return (_set_pb_func(_probing_backoff)); } cm.probe_state = PROBE_SUCCEEDED; return (_set_pb_func(_probing_finish)); }
static stat_t _probing_start() { // initial probe state, don't probe if we're already contacted! int8_t probe = gpio_read_input(pb.probe_input); // INPUT_INACTIVE means switch is OPEN if ( probe == INPUT_INACTIVE ) { cm_straight_feed(pb.target, pb.flags); return (_set_pb_func(_probing_backoff)); } else { cm.probe_state = PROBE_SUCCEEDED; return (_set_pb_func(_probing_finish)); } }
/* * _probing_backoff() */ static stat_t _probing_backoff() { // If we've contacted, back off & then record position int8_t probe = gpio_read_input(pb.probe_input); /* true is SW_CLOSED in old code, and INPUT_ACTIVE in new */ if (probe == INPUT_ACTIVE) { cm.probe_state = PROBE_SUCCEEDED; // FIXME: this should be its own parameter // cm_set_feed_rate(cm.a[AXIS_Z].latch_velocity); cm_straight_feed(pb.start_position, pb.flags); return (_set_pb_func(_probing_finish)); } else { cm.probe_state = PROBE_FAILED; return (_set_pb_func(_probing_finish)); } }
static stat_t _probing_backoff() { // Test if we've contacted int8_t probe = gpio_read_input(pb.probe_input); // INPUT_INACTIVE means switch is OPEN (at least for now) if ( probe == INPUT_INACTIVE ) { cm.probe_state = PROBE_FAILED; } else { cm.probe_state = PROBE_SUCCEEDED; // capture contact position in step space and convert from steps to mm. // snapshot was taken by switch interrupt at the time of closure float contact_position[AXES]; kn_forward_kinematics(en_get_encoder_snapshot_vector(), contact_position); cm_queue_flush(); // flush queue & end feedhold cm_straight_feed(contact_position, pb.flags); // NB: feed rate is the same as the probe move } return (_set_pb_func(_probing_finish)); }
static stat_t _execute_gcode_block() { stat_t status = STAT_OK; cm_set_model_linenum(gn.linenum); EXEC_FUNC(cm_set_inverse_feed_rate_mode, inverse_feed_rate_mode); EXEC_FUNC(cm_set_feed_rate, feed_rate); EXEC_FUNC(cm_feed_rate_override_factor, feed_rate_override_factor); EXEC_FUNC(cm_traverse_override_factor, traverse_override_factor); EXEC_FUNC(cm_set_spindle_speed, spindle_speed); EXEC_FUNC(cm_spindle_override_factor, spindle_override_factor); EXEC_FUNC(cm_select_tool, tool); EXEC_FUNC(cm_change_tool, tool); EXEC_FUNC(cm_spindle_control, spindle_mode); // spindle on or 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); EXEC_FUNC(cm_traverse_override_enable, traverse_override_enable); EXEC_FUNC(cm_spindle_override_enable, spindle_override_enable); EXEC_FUNC(cm_override_enables, override_enables); if (gn.next_action == NEXT_ACTION_DWELL) { // G4 - dwell ritorno(cm_dwell(gn.parameter)); // return if error, otherwise complete the block } EXEC_FUNC(cm_select_plane, select_plane); EXEC_FUNC(cm_set_units_mode, units_mode); //--> cutter radius compensation goes here //--> cutter length compensation goes here EXEC_FUNC(cm_set_coord_system, coord_system); EXEC_FUNC(cm_set_path_control, path_control); EXEC_FUNC(cm_set_distance_mode, distance_mode); //--> set retract mode goes here switch (gn.next_action) { case NEXT_ACTION_SEARCH_HOME: { status = cm_homing_cycle_start(); break;} // G28.2 // case NEXT_ACTION_STRAIGHT_PROBE: { status = cm_probe_cycle_start(); break;} case NEXT_ACTION_SET_ABSOLUTE_ORIGIN: { status = cm_set_absolute_origin(gn.target, gf.target); break;} // G28.3 case NEXT_ACTION_SET_G28_POSITION: { status = cm_set_g28_position(); break;} // G28.1 case NEXT_ACTION_GOTO_G28_POSITION: { status = cm_goto_g28_position(gn.target, gf.target); break;} // G28 case NEXT_ACTION_SET_G30_POSITION: { status = cm_set_g30_position(); break;} // G30.1 case NEXT_ACTION_GOTO_G30_POSITION: { status = cm_goto_g30_position(gn.target, gf.target); break;} // G30 case NEXT_ACTION_SET_COORD_DATA: { status = cm_set_coord_offsets(gn.parameter, gn.target, gf.target); break;} case NEXT_ACTION_SET_ORIGIN_OFFSETS: { status = cm_set_origin_offsets(gn.target, gf.target); break;} case NEXT_ACTION_RESET_ORIGIN_OFFSETS: { status = cm_reset_origin_offsets(); break;} case NEXT_ACTION_SUSPEND_ORIGIN_OFFSETS: { status = cm_suspend_origin_offsets(); break;} case NEXT_ACTION_RESUME_ORIGIN_OFFSETS: { status = cm_resume_origin_offsets(); break;} case NEXT_ACTION_DEFAULT: { cm_set_absolute_override(gn.absolute_override); // apply override setting to gm struct switch (gn.motion_mode) { case MOTION_MODE_CANCEL_MOTION_MODE: { gm.motion_mode = gn.motion_mode; break;} case MOTION_MODE_STRAIGHT_TRAVERSE: { status = cm_straight_traverse(gn.target, gf.target); break;} case MOTION_MODE_STRAIGHT_FEED: { status = cm_straight_feed(gn.target, gf.target); break;} case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC: // gf.radius sets radius mode if radius was collected in gn { status = cm_arc_feed(gn.target, gf.target, gn.arc_offset[0], gn.arc_offset[1], gn.arc_offset[2], gn.arc_radius, gn.motion_mode); break;} } } } cm_set_absolute_override(false); // un-set abs overrride (for reporting purposes) // do the M stops: M0, M1, M2, M30, M60 if (gf.program_flow == true) { if (gn.program_flow == PROGRAM_STOP) { cm_program_stop(); } else { cm_program_end(); } } return (status); }