// Perform homing cycle to locate and set machine zero. Only '$H' executes this command. // NOTE: There should be no motions in the buffer and Grbl must be in an idle state before // executing the homing cycle. This prevents incorrect buffered plans after homing. void MotionGoHome(void) { plan_init(); uint16_t limitStatus; uint16_t stepCount; sys.state = STATE_HOMING; // Set system state variable // LIMIT_PCMSK &= ~LIMIT_MASK; // Disable hard limits pin change register for cycle duration xLimitDetected = FALSE; yLimitDetected = FALSE; BSP_SetStepSize(X_AXIS, QUARTER); BSP_SetStepSize(Y_AXIS, QUARTER); BSP_SetStepSize(Z_AXIS, QUARTER); settings.steps_per_mm[X_AXIS] = X_STEPS_MM(QUARTER_STEP); settings.steps_per_mm[Y_AXIS] = Y_STEPS_MM(QUARTER_STEP); settings.steps_per_mm[Z_AXIS] = Z_STEPS_MM(QUARTER_STEP); // Find out if X or Y axis are at limit limitStatus = mPORTCReadBits(xLimitInput.pin||yLimitInput.pin); if(limitStatus) { if(limitStatus & xLimitInput.pin) // If Xat Limit { stepCount = 0; BSP_Timer3Start(100); OpenOC2(XS_PWM_ENA, (ReadPeriod3()>>1), ReadPeriod3()>>1); BSP_AxisEnable(X_AXIS, NEGATIVE); while((mPORTCReadBits(xLimitInput.pin))) { stepCount++; steps_X = 0x1; if(stepCount >= 20) mPORTGToggleBits(xAxis.directionPin.pin); } BSP_AxisDisable(X_AXIS); if(mPORTGReadBits(xAxis.directionPin.pin) == POSITIVE) gcode.position[X_AXIS] = 215.000; else gcode.position[X_AXIS] =0; } if(limitStatus & yLimitInput.pin) // If Xat Limit { stepCount = 0; BSP_Timer2Start(100); OpenOC1(XS_PWM_ENA, (ReadPeriod2()>>1), ReadPeriod2()>>1); BSP_AxisEnable(Y_AXIS, NEGATIVE); while((mPORTCReadBits(yLimitInput.pin))) { stepCount++; steps_Y = 0x1; if(stepCount >= 20) mPORTEToggleBits(yAxis.directionPin.pin); } if(mPORTEReadBits(xAxis.directionPin.pin) == POSITIVE) gcode.position[Y_AXIS] = 215.000; else gcode.position[Y_AXIS] =0; }
int main(int argc, char *argv[]) { init(); if(init_setting() != 0){ print_errmsg("ERROR: SETTING init fail. \n"); return 1; } if(gc_init() != 0){ print_errmsg("ERROR: G_CODE init fail. \n"); return 1; } if (cm_init() == false) { print_errmsg("ERROR: USB-DEV init fail. \n"); return 1; } if (cmd_init() == false) { print_errmsg("ERROR: G code init fail.\n"); cm_close(); return 1; } if (tp_init() == false) { print_errmsg("ERROR: Temperature library init fail. \n"); cmd_close(); cm_close(); return 1; } plan_init(); Config_ResetDefault(); st_init(); while(1) { LCD(10UL); getCommand(10UL); process_commands(50UL); stepper(1000L); manageHeater(10UL); } st_close(); plan_close(); tp_close(); cmd_close(); cm_close(); //debug //sfp_close(); return 0; }
/** *** LaosMotion() Constructor *** Make new motion object **/ LaosMotion::LaosMotion() { extern GlobalConfig *cfg; #if DO_MOTION_TEST tActionRequest act[2]; int i=0; Timer t; #endif pwm.period(1.0 / cfg->pwmfreq); pwm = cfg->pwmmin/100.0; if ( laser == NULL ) laser = new DigitalOut(LASER_PIN); *laser = LASEROFF; mark_speed = cfg->speed; //start.mode(PullUp); xhome.mode(PullUp); yhome.mode(PullUp); isHome = false; plan_init(); st_init(); reset(); mark_speed = cfg->speed; bitmap_speed = cfg->xspeed; action.param = 0; action.target.x = action.target.y = action.target.z = action.target.e =0; action.target.feed_rate = 60*mark_speed; #if DO_MOTION_TEST t.start(); act[0].ActionType = act[1].ActionType = AT_MOVE; act[0].target.feed_rate = 60 * 100; act[1].target.feed_rate = 60 * 200; act[0].target.x = act[0].target.y = act[0].target.z = act[0].target.e = 0; act[1].target.x = act[1].target.y = act[1].target.z = act[1].target.e = 100; act[1].target.y = 200; while(1) { while( plan_queue_full() ) led3 = !led3; led1 = 1; i++; if ( i ) printf("%d PING...\n", t.read_ms()); else printf("%d PONG...\n", t.read_ms()); if ( i > 1 || i<0) i = 0; plan_buffer_line (&act[i]); led1 = 0; } #endif }
int main(void) { sp_init(); settings_init(); plan_init(); st_init(); spindle_init(); gc_init(); for (;;) { sleep_mode(); // Wait for it ... sp_process(); // ... process the serial protocol } return 0; /* never reached */ }
int main(void) { sei(); // Enable interrupts serial_init(BAUD_RATE); protocol_init(); settings_init(); plan_init(); st_init(); spindle_init(); gc_init(); limits_init(); while (1) { // sleep_mode(); // Wait for it ... protocol_process(); // ... process the serial protocol } return 0; /* never reached */ }
int main(void) { sei(); serial_init(BAUD_RATE); protocol_init(); settings_init(); plan_init(); st_init(); laser_init(); gc_init(); limits_init(); for(;;){ sleep_mode(); // Wait for it ... protocol_process(); // ... process the serial protocol } return 0; /* never reached */ }
void PlannerThread::run() { while (!closing) { while (!startPlan) { } if (!plan_init()) { return; } restartPlan = false; while (!restartPlan) { if (!planning_cycle()) { return; } } startPlan = false; } return; }
int unicorn_init(void) { channel_tag fan = NULL; int ret = 0; board_info_t board_info; printf("unicorn_init...\n"); ret = eeprom_read_board_info(EEPROM_DEV, &board_info); if (ret < 0) { printf("Read eeprom board info failed\n"); return -1; } if (!strncasecmp("bbp1s", board_info.name, 5)) { bbp_board_type = BOARD_BBP1S; } else if(!strncasecmp("bbp1", board_info.name, 4)){ bbp_board_type = BOARD_BBP1; } printf("board name:%s, version:%s, get board type:%d \n", board_info.name, board_info.version, bbp_board_type); /* * Create fifo * fifo_plan2st, fifo_st2plan * fifo_plan2gc, fifo_gc2plan */ Fifo_Attrs fAttrs = Fifo_Attrs_DEFAULT; hFifo_plan2st = Fifo_create(&fAttrs); hFifo_st2plan = Fifo_create(&fAttrs); if ((hFifo_st2plan == NULL) || (hFifo_plan2st == NULL)) { printf("Create Fifo failed\n"); return -1; } Pause_Attrs pAttrs = Pause_Attrs_DEFAULT; hPause_printing = Pause_create(&pAttrs); if (hPause_printing == NULL) { printf("Create pause err\n"); return -1; } else { Pause_on(hPause_printing); } /* set up unicorn system */ ret = unicorn_setup(); if (ret < 0) { return ret; } /* init sub systems of unicorn */ ret = parameter_init(EEPROM_DEV); if (ret < 0) { printf("parameter_init failed\n"); return ret; } ret = analog_init(); if (ret < 0) { printf("analog_init failed\n"); return ret; } ret = temp_init(); if (ret < 0) { printf("temp_init failed\n"); return ret; } ret = pwm_init(); if (ret < 0) { printf("pwm_init failed\n"); return ret; } ret = fan_init(); if (ret < 0) { printf("fan_init failed\n"); return ret; } ret = heater_init(); if (ret < 0) { printf("heater_init failed\n"); return ret; } #ifdef SERVO if (bbp_board_type == BOARD_BBP1S) { ret = servo_init(); if (ret < 0) { printf("servo_init failed\n"); return ret; } } #endif ret = lmsw_init(); if (ret < 0) { printf("lmsw_init failed\n"); return ret; } ret = plan_init(); if (ret < 0) { printf("plan_init failed\n"); return ret; } ret = stepper_init(); if (ret < 0) { printf("stepper_init failed\n"); return ret; } ret = gcode_init(); if (ret < 0) { printf("gcode_init failed\n"); return ret; } fan = fan_lookup_by_name("fan_3"); if (fan) { fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); fan_enable(fan); } fan = fan_lookup_by_name("fan_4"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } fan = fan_lookup_by_name("fan_5"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } fan = fan_lookup_by_name("fan_6"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } printf("unicorn_init ok!!!\n"); return ret; }
int startGrbl(void) { // Initialize system serial_init(); // Setup serial baud rate and interrupts settings_init(); // Load grbl settings from EEPROM 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 sys.state = STATE_INIT; // Set alarm state to indicate unknown initial position // Wire.begin(); 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) { // Reset system. serial_reset_read_buffer(); // Clear serial read buffer plan_init(); // Clear block buffer and planner variables gc_init(); // Set g-code parser to default state protocol_init(); // Clear incoming line data and execute startup lines spindle_init(); coolant_init(); limits_init(); st_reset(); // Clear stepper subsystem variables. syspos(&encdr_x,&encdr_y,&encdr_z); ofst_x=encdr_x; ofst_y=encdr_y; ofst_z=encdr_z; // Sync cleared gcode and planner positions to current system position, which is only // cleared upon startup, not a reset/abort. sys_sync_current_position(); // Reset system variables. sys.abort = false; sys.execute = 0; if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; } // Check for power-up and set system alarm if homing is enabled to force homing cycle // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the // startup scripts, but allows access to settings and internal commands. Only a homing // cycle '$H' or kill alarm locks '$X' will disable the alarm. // NOTE: The startup script will run after successful completion of the homing cycle, but // not after disabling the alarm locks. Prevents motion startup blocks from crashing into // things uncontrollably. Very bad. #ifdef HOMING_INIT_LOCK if (sys.state == STATE_INIT && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } #endif // Check for and report alarm state after a reset, error, or an initial power up. if (sys.state == STATE_ALARM) { report_feedback_message(MESSAGE_ALARM_LOCK); } else { // All systems go. Set system to ready and execute startup script. sys.state = STATE_IDLE; protocol_execute_startup(); } } protocol_execute_runtime(); // syspos(&encdr_x,&encdr_y); protocol_process(); // ... process the serial protocol } return 0; /* never reached */ }
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 */ }
int main(void) { #ifdef PART_LM4F120H5QR // ARM code SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN ); //set system clock to 80 MHz FPUEnable(); //enable the Floating Point Unit // FPULazyStackingEnable(); // Enable stacking for interrupt handlers #endif // Initialize system serial_init(); // Setup serial baud rate and interrupts settings_init(); // Load grbl settings from EEPROM st_init(); // Setup stepper pins and interrupt timers #ifdef PART_LM4F120H5QR // ARM code IntMasterEnable(); #else // AVR code sei(); // Enable interrupts #endif memset(&sys, 0, sizeof(sys)); // Clear all system variables sys.abort = true; // Set abort to complete initialization sys.state = STATE_INIT; // Set alarm state to indicate unknown initial position 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) { // Reset system. serial_reset_read_buffer(); // Clear serial read buffer plan_init(); // Clear block buffer and planner variables gc_init(); // Set g-code parser to default state protocol_init(); // Clear incoming line data and execute startup lines spindle_init(); coolant_init(); limits_init(); st_reset(); // Clear stepper subsystem variables. // Sync cleared gcode and planner positions to current system position, which is only // cleared upon startup, not a reset/abort. sys_sync_current_position(); // Reset system variables. sys.abort = false; sys.execute = 0; if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; } // Check for power-up and set system alarm if homing is enabled to force homing cycle // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the // startup scripts, but allows access to settings and internal commands. Only a homing // cycle '$H' or kill alarm locks '$X' will disable the alarm. // NOTE: The startup script will run after successful completion of the homing cycle, but // not after disabling the alarm locks. Prevents motion startup blocks from crashing into // things uncontrollably. Very bad. #ifdef HOMING_INIT_LOCK if (sys.state == STATE_INIT && bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } #endif // Check for and report alarm state after a reset, error, or an initial power up. if (sys.state == STATE_ALARM) { report_feedback_message(MESSAGE_ALARM_LOCK); } else { // All systems go. Set system to ready and execute startup script. sys.state = STATE_IDLE; protocol_execute_startup(); } } protocol_execute_runtime(); protocol_process(); // ... process the serial protocol // When the serial protocol returns, there are no more characters in the serial read buffer to // be processed and executed. This indicates that individual commands are being issued or // streaming is finished. In either case, auto-cycle start, if enabled, any queued moves. if (sys.auto_start) { st_cycle_start(); } } // return 0; /* never reached */ }
int main() { TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); // If they are present, configure Vbus & Wake-up pins //PIO_InitializeInterrupts(0); //-------- Init parameters -------------- printf("INIT Parameters\n\r"); init_parameters(); //-------- Load parameters from Flash -------------- printf("Load parameters from Flash\n\r"); FLASH_LoadSettings(); //-------- Init UART -------------- printf("USB Seriel INIT\n\r"); samserial_init(); //-------- Init ADC without Autostart -------------- printf("Init ADC\n\r"); initadc(0); //-------- On USB recived byte call this function -------------- printf("Init Callback for USB\n\r"); samserial_setcallback(&usb_characterhandler); //-------- Init Motor driver -------------- printf("Init Motors\n\r"); motor_setup(); //-------- Init Heater I/O -------------- printf("Init Heaters\n\r"); heaters_setup(); //-------- Start SYSTICK (1ms) -------------- printf("Configuring systick.\n\r"); SysTick_Configure(1, BOARD_MCK/1000, SysTick_Handler); //-------- Timer 0 for Stepper -------------- printf("Init Stepper IO\n\r"); stepper_setup(); //Timer for Stepper //-------- Timer 0 for Stepper -------------- printf("Configuring Timer 0 Stepper\n\r"); ConfigureTc0_Stepper(); //Timer for Stepper //-------- Timer 1 for heater PWM -------------- printf("Configuring Timer 1 PWM.\n\r"); ConfigureTc_1(); //-------- Init Planner Values -------------- printf("Plan Init\n\r"); plan_init(); //-------- Check for SD card presence ------- // sdcard_handle_state(); //motor_enaxis(0,1); //motor_enaxis(1,1); while (1) { //uncomment to use//sprinter_mainloop(); //main loop events go here do_periodic(); if(buflen < (BUFSIZE-1)) get_command(); if(buflen > 0) { //-------- Check and execute G-CODE -------------- process_commands(); //-------- Increment G-Code FIFO -------------- buflen = (buflen-1); bufindr++; if(bufindr == BUFSIZE) bufindr = 0; } } }
int app_main (void) { long timer1 = 0; eParseResult parse_result; buzzer_init(); buzzer_play(1500, 100); /* low beep */ buzzer_wait(); buzzer_play(2500, 200); /* high beep */ init(); read_config(); // grbl init plan_init(); st_init(); // main loop for (;;) { // process characters from the serial port while (!serial_line_buf.seen_lf && (serial_rxchars() != 0) ) { unsigned char c = serial_popchar(); if (serial_line_buf.len < MAX_LINE) serial_line_buf.data [serial_line_buf.len++] = c; if ((c==10) || (c==13)) { if (serial_line_buf.len > 1) serial_line_buf.seen_lf = 1; else serial_line_buf.len = 0; } } // process SD file if no serial command pending if (!sd_line_buf.seen_lf && sd_printing) { if (sd_read_file (&sd_line_buf)) { sd_line_buf.seen_lf = 1; } else { sd_printing = false; serial_writestr ("Done printing file\r\n"); } } // if queue is full, we wait if (!plan_queue_full()) { /* At end of each line, put the "GCode" on movebuffer. * If there are movement to do, Timer will start and execute code which * will take data from movebuffer and generate the required step pulses * for stepper motors. */ // give priority to user commands if (serial_line_buf.seen_lf) { parse_result = gcode_parse_line (&serial_line_buf); serial_line_buf.len = 0; serial_line_buf.seen_lf = 0; } else if (sd_line_buf.seen_lf) { parse_result = gcode_parse_line (&sd_line_buf); sd_line_buf.len = 0; sd_line_buf.seen_lf = 0; } } /* Do every 100ms */ #define DELAY1 100 if (timer1 < millis()) { timer1 = millis() + DELAY1; /* If there are no activity during 30 seconds, power off the machine */ if (steptimeout > (30 * 1000/DELAY1)) { power_off(); } else { steptimeout++; } } #ifdef USE_BOOT_BUTTON // OPTION: enter bootloader on "Boot" button check_boot_request(); #endif } }