Ejemplo n.º 1
0
// Set relative coordinate system
static const char *handle_G92(float sub_command,
                              struct GCodeParser *p, const char *line) {
  // It is safe to compare raw float values here, as long as we give float
  // literals. They have been parsed from literals as well.
  if (sub_command == 92.0f) {
    char axis_l;
    float value;
    const char *remaining_line;
    while ((remaining_line = gparse_pair(p, line, &axis_l, &value))) {
      const float unit_val = value * p->unit_to_mm_factor;
      const enum GCodeParserAxis axis = gcodep_letter2axis(axis_l);
      if (axis == GCODE_NUM_AXES)
        break;    // Possibly start of new command.
      // This sets the given value to be the new zero.
      p->origin_g92[axis] = p->axes_pos[axis] - unit_val;
      
      line = remaining_line;
    }
    set_current_origin(p, p->origin_g92);
  }
  else if (sub_command == 92.1f) {
    reset_G92(p);
    set_current_origin(p, p->origin_g92);
  }
  else if (sub_command == 92.2f) {
    set_current_origin(p, p->origin_machine); // Later: G54...
  }
  else if (sub_command == 92.3f) {
    set_current_origin(p, p->origin_g92);
  }
  return line;
}
Ejemplo n.º 2
0
static const char *handle_z_probe(struct GCodeParser *p, const char *line) {
  char letter;
  float value;
  float feedrate = -1;
  float probe_thickness = 0;
  const char *remaining_line;
  while ((remaining_line = gparse_pair(p, line, &letter, &value))) {
    const float unit_value = value * p->unit_to_mm_factor;
    if (letter == 'F') feedrate = f_param_to_feedrate(unit_value);
    else if (letter == 'Z') probe_thickness = value * p->unit_to_mm_factor;
    else break;
    line = remaining_line;
  }
  // Probe for the travel endstop
  float probed_pos;
  if (p->callbacks.probe_axis(p->callbacks.user_data, feedrate, AXIS_Z,
                              &probed_pos)) {
    p->axes_pos[AXIS_Z] = probed_pos;
    // Doing implicit G92 here. Is this what we want ? Later, this might
    // be part of tool-offset or something.
    p->global_offset_g92[AXIS_Z] = (p->axes_pos[AXIS_Z] - probe_thickness)
      - p->current_origin[AXIS_Z];
    set_current_origin(p, p->current_origin, p->global_offset_g92);
  }
  return line;
}
Ejemplo n.º 3
0
// Reset coordinate systems etc. that should be assumed at
// the beginnig of a program.
static void gcodep_program_start_defaults(GCodeParser_t *object) {
  // Initial values for various constants.
  object->unit_to_mm_factor = 1.0f;     // G21
  set_all_axis_to_absolute(object, 1);  // G90
  reset_G92(object);

  object->arc_normal = AXIS_Z;  // Arcs in XY-plane

  set_current_origin(object, object->origin_machine);

  // Some initial machine states
  object->callbacks.set_speed_factor(object->callbacks.user_data, 1);
  object->callbacks.set_fanspeed(object->callbacks.user_data, 0);
  object->callbacks.set_temperature(object->callbacks.user_data, 0);
}