Beispiel #1
0
int main(void)
{
  // Initialize system
  serial_init(BAUD_RATE); // Setup serial baud rate and interrupts
  st_init(); // Setup stepper pins and interrupt timers
  sei(); // Enable interrupts

  memset(&sys, 0, sizeof(sys));  // Clear all system variables
  sys.abort = true;   // Set abort to complete initialization

  for(;;) {

    // Execute system reset upon a system abort, where the main program will return to this loop.
    // Once here, it is safe to re-initialize the system. At startup, the system will automatically
    // reset to finish the initialization process.
    if (sys.abort) {

      // Retain last known machine position and work coordinate offset(s). If the system abort
      // occurred while in motion, machine position is not guaranteed, since a hard stop can cause
      // the steppers to lose steps. Always perform a feedhold before an abort, if maintaining
      // accurate machine position is required.
      // TODO: Report last position and coordinate offset to users to help relocate origins. Future
      // releases will auto-reset the machine position back to [0,0,0] if an abort is used while
      // grbl is moving the machine.
/// by LETARTARE 3-> 4
      int32_t last_position[4];
      double last_coord_system[N_COORDINATE_SYSTEM][3];
      memcpy(last_position, sys.position, sizeof(sys.position)); // last_position[] = sys.position[]
      memcpy(last_coord_system, sys.coord_system, sizeof(sys.coord_system)); // last_coord_system[] = sys.coord_system[]

      // Reset system.
      memset(&sys, 0, sizeof(sys)); // Clear all system variables
      serial_reset_read_buffer(); // Clear serial read buffer
      settings_init(); // Load grbl settings from EEPROM
      protocol_init(); // Clear incoming line data
      plan_init(); // Clear block buffer and planner variables
      gc_init(); // Set g-code parser to default state
      spindle_init();
      limits_init();
      coolant_init();
      st_reset(); // Clear stepper subsystem variables.

      // Reload last known machine position and work systems. G92 coordinate offsets are reset.
      memcpy(sys.position, last_position, sizeof(last_position)); // sys.position[] = last_position[]
      memcpy(sys.coord_system, last_coord_system, sizeof(last_coord_system)); // sys.coord_system[] = last_coord_system[]
      gc_set_current_position(last_position[X_AXIS],last_position[Y_AXIS],last_position[Z_AXIS],last_position[C_AXIS]);
      plan_set_current_position(last_position[X_AXIS],last_position[Y_AXIS],last_position[Z_AXIS],last_position[C_AXIS]);

      // Set system runtime defaults
      // TODO: Eventual move to EEPROM from config.h when all of the new settings are worked out.
      // Mainly to avoid having to maintain several different versions.
      #ifdef CYCLE_AUTO_START
        sys.auto_start = true;
      #endif
      // TODO: Install G20/G21 unit default into settings and load appropriate settings.
    }

    protocol_execute_runtime();
    protocol_process(); // ... process the serial protocol

  }
  return 0;   /* never reached */
}
Beispiel #2
0
// Syncs all internal position vectors to the current system position.
void sys_sync_current_position()
{
  plan_set_current_position(sys.position[X_AXIS],sys.position[Y_AXIS],sys.position[Z_AXIS]);
  gc_set_current_position(sys.position[X_AXIS],sys.position[Y_AXIS],sys.position[Z_AXIS]);
}