From 666eaae303dbed61c4a2cf9c8d64b8461e3c32f0 Mon Sep 17 00:00:00 2001 From: Stefan Hechenberger Date: Sat, 14 Apr 2012 19:36:37 -0400 Subject: [PATCH] reverting to hex file from lasaur app binary distribution --- README.md | 11 +++-- config.h | 29 +----------- gcode.c | 82 ++++++++++++++------------------- planner.c | 41 ++++++----------- planner.h | 31 ++++++------- sense_control.c | 14 +----- sense_control.h | 1 - stepper.c | 118 +++++++++++++++++------------------------------- 8 files changed, 113 insertions(+), 214 deletions(-) diff --git a/README.md b/README.md index a8a2f76bc..b2b5b9053 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ Grbl - An embedded g-code interpreter and motion-controller for the Arduino/AVR3 For more information [on Grbl](https://github.com/simen/grbl) +TODO +------ +- g55 wrong offset +- homing cycle cannot recover out of bounds when limit already triggering mbed merger notes ------------------ @@ -58,10 +62,9 @@ Coordinate Systems stop, pause, resume -------------------- -stop on: power, chiller, limit, '!' command -resume from stop: '~' command -pause on: door open -resume from pause: door close +stop on: power, chiller, limit, \03 control char +stop resume on: \02 control char +pause on: door, resume on door close diff --git a/config.h b/config.h index b7a6c2d0f..1582f50c8 100644 --- a/config.h +++ b/config.h @@ -24,7 +24,7 @@ #include -#define LASAURGRBL_VERSION "v12.03-beta1" +#define LASAURGRBL_VERSION "v12.02-beta1" #define BAUD_RATE 9600 @@ -41,28 +41,6 @@ #define CONFIG_Z_ORIGIN_OFFSET 0.0 // mm, z-offset of table origin from physical home #define CONFIG_INVERT_X_AXIS 1 // 0 is regular, 1 inverts the x direction #define CONFIG_INVERT_Y_AXIS 1 // 0 is regular, 1 inverts the y direction -// alphasurs X_AXIS=1; Y_AXIS=1 -// hypersaur X_AXIS=1; Y_AXIS=0 -// yagersaur X_AXIS=0; Y_AXIS=0 - -// beam dynamics configuration -// With these setting the laser intensity can be dynamically adapted to slowdowns -// resulting from de/acceleration phases. The stepper driver code looks at the ratio -// of actual to nominal speed and uses this to also reduce the nominal laser intensity. -// The diminution profile can also be fine-tuned (as a linear mapping is too aggressive). -// It uses this function: y=x^2*d+(1-d) where d is the diminution severity (0.0 to 1.0). -// 0.0 is no diminution and anything > 0.7 is more aggresive than linear. -#define CONFIG_BEAM_DYNAMICS 1 // 0 or 1 -#define CONFIG_BEAM_DIMINUTION 0.3 - -// use laser enable bit -// This uses the LASER_ENABLE_BIT to switch the laser instead of just setting the intensity to 0. -// With some lasers (e.g. DPSS YAG) this is necessary because they have a high latency when changing -// the intensity. On/off during G0 seek motions is instead achieved with an optical switch in the -// resonator which also might have a slight delay; hence the latency config. The firmware can accomodate. -#define CONFIG_USE_LASER_ENABLE_BIT 0 // whether (0 or 1) to use the laser enable pin on seeks (G0) -#define CONFIG_USE_LASER_ENABLE_LATENCY 4 // time (sec) it takes to enable the laser -#define CONFIG_USE_LASER_DISABLE_LATENCY 0.5 // time (sec) it takes to enable the laser #define LIMITS_OVERWRITE_DDR DDRD @@ -84,11 +62,6 @@ #define Y1_LIMIT_BIT 2 #define Y2_LIMIT_BIT 3 -#define LASER_DDR DDRD -#define LASER_PORT PORTD -#define LASER_ENABLE_BIT 4 -// #define LASER_PWM_BIT 6 - #define AIRGAS_DDR DDRC #define AIRGAS_PORT PORTC #define AIR_BIT 4 diff --git a/gcode.c b/gcode.c index 06448dc5c..1d5ba1eb0 100644 --- a/gcode.c +++ b/gcode.c @@ -43,8 +43,6 @@ #define NEXT_ACTION_AIRGAS_DISABLE 6 #define NEXT_ACTION_AIR_ENABLE 7 #define NEXT_ACTION_GAS_ENABLE 8 -#define NEXT_ACTION_LASER_ENABLE 9 -#define NEXT_ACTION_LASER_DISABLE 10 #define STATUS_OK 0 #define STATUS_BAD_NUMBER_FORMAT 1 @@ -72,7 +70,6 @@ typedef struct { double offsets[6]; // coord system offsets {G54_X,G54_Y,G54_Z,G55_X,G55_Y,G55_Z} uint8_t offselect; // currently active offset, 0 -> G54, 1 -> G55 uint8_t nominal_laser_intensity; // 0-255 percentage - uint8_t prev_action; } parser_state_t; static parser_state_t gc; @@ -101,7 +98,6 @@ void gcode_init() { gc.offsets[3+X_AXIS] = CONFIG_X_ORIGIN_OFFSET; gc.offsets[3+Y_AXIS] = CONFIG_Y_ORIGIN_OFFSET; gc.offsets[3+Z_AXIS] = CONFIG_Z_ORIGIN_OFFSET; - gc.prev_action = NEXT_ACTION_NONE; position_update_requested = false; } @@ -206,11 +202,10 @@ uint8_t gcode_execute_line(char *line) { int int_value; double unit_converted_value; uint8_t next_action = NEXT_ACTION_NONE; - double target[3]; - double p = 0.0; + double target[3], offset[3]; + double p = 0; int cs = 0; int l = 0; - bool got_actual_line_command = false; // as opposed to just e.g. G1 F1200 gc.status_code = STATUS_OK; //// Pass 1: Commands @@ -238,8 +233,6 @@ uint8_t gcode_execute_line(char *line) { case 7: next_action = NEXT_ACTION_AIR_ENABLE;break; case 8: next_action = NEXT_ACTION_GAS_ENABLE;break; case 9: next_action = NEXT_ACTION_AIRGAS_DISABLE;break; - case 140: next_action = NEXT_ACTION_LASER_DISABLE;break; - case 141: next_action = NEXT_ACTION_LASER_ENABLE;break; default: FAIL(STATUS_UNSUPPORTED_STATEMENT); } break; @@ -251,6 +244,8 @@ uint8_t gcode_execute_line(char *line) { if (gc.status_code) { return gc.status_code; } char_counter = 0; + clear_vector(target); + clear_vector(offset); memcpy(target, gc.position, sizeof(target)); // i.e. target = gc.position //// Pass 2: Parameters @@ -275,7 +270,6 @@ uint8_t gcode_execute_line(char *line) { } else { target[letter - 'X'] += unit_converted_value; } - got_actual_line_command = true; break; case 'P': // dwelling seconds or CS selector if (next_action == NEXT_ACTION_SET_COORDINATE_OFFSET) { @@ -298,38 +292,37 @@ uint8_t gcode_execute_line(char *line) { //// Perform any physical actions switch (next_action) { - case NEXT_ACTION_SEEK: // G0 - if (CONFIG_USE_LASER_ENABLE_BIT && got_actual_line_command) { - if (gc.prev_action != NEXT_ACTION_SEEK) { - planner_control_laser_disable(CONFIG_USE_LASER_DISABLE_LATENCY); - } - // seek - keep pwm up, laser is disabled via the LASER_ENABLE_BIT - planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], - target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], - target[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS], - gc.seek_rate, gc.nominal_laser_intensity ); - } else { - // seek - turn pwm down - planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], - target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], - target[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS], - gc.seek_rate, 0 ); - } + case NEXT_ACTION_SEEK: + planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], + target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], + target[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS], + gc.seek_rate, 0 ); break; - case NEXT_ACTION_FEED: // G1 - if (CONFIG_USE_LASER_ENABLE_BIT && got_actual_line_command && gc.prev_action != NEXT_ACTION_FEED) { - // when a new path starts -> enable laser and dwell some time - planner_control_laser_enable(CONFIG_USE_LASER_ENABLE_LATENCY, gc.nominal_laser_intensity); - } + case NEXT_ACTION_FEED: planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], target[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS], gc.feed_rate, gc.nominal_laser_intensity ); break; - case NEXT_ACTION_DWELL: // G4 + case NEXT_ACTION_DWELL: planner_dwell(p, gc.nominal_laser_intensity); break; - case NEXT_ACTION_HOMING_CYCLE: // G30 + // case NEXT_ACTION_STOP: + // planner_stop(); // stop and cancel the remaining program + // gc.position[X_AXIS] = stepper_get_position_x(); + // gc.position[Y_AXIS] = stepper_get_position_y(); + // gc.position[Z_AXIS] = stepper_get_position_z(); + // planner_set_position(gc.position[X_AXIS], gc.position[Y_AXIS], gc.position[Z_AXIS]); + // // move to table origin + // target[X_AXIS] = 0; + // target[Y_AXIS] = 0; + // target[Z_AXIS] = 0; + // planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], + // target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], + // target[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS], + // gc.seek_rate, 0 ); + // break; + case NEXT_ACTION_HOMING_CYCLE: stepper_homing_cycle(); // now that we are at the physical home // zero all the position vectors @@ -346,7 +339,7 @@ uint8_t gcode_execute_line(char *line) { target[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS], gc.seek_rate, 0 ); break; - case NEXT_ACTION_SET_COORDINATE_OFFSET: // G10 + case NEXT_ACTION_SET_COORDINATE_OFFSET: if (cs == OFFSET_G54 || cs == OFFSET_G55) { if (l == 2) { //set offset to target, eg: G10 L2 P1 X15 Y15 Z0 @@ -361,28 +354,21 @@ uint8_t gcode_execute_line(char *line) { } } break; - case NEXT_ACTION_AIRGAS_DISABLE: // M9 - planner_control_airgas_disable(p); - break; - case NEXT_ACTION_AIR_ENABLE: // M7 - planner_control_air_enable(p); + case NEXT_ACTION_AIRGAS_DISABLE: + planner_control_airgas_disable(); break; - case NEXT_ACTION_GAS_ENABLE: // M8 - planner_control_gas_enable(p); + case NEXT_ACTION_AIR_ENABLE: + planner_control_air_enable(); break; - case NEXT_ACTION_LASER_ENABLE: // M141 - planner_control_laser_enable(p, gc.nominal_laser_intensity); + case NEXT_ACTION_GAS_ENABLE: + planner_control_gas_enable(); break; - case NEXT_ACTION_LASER_DISABLE: // M140 - planner_control_laser_disable(p); - break; } // As far as the parser is concerned, the position is now == target. In reality the // motion control system might still be processing the action and the real tool position // in any intermediate location. memcpy(gc.position, target, sizeof(double)*3); // gc.position[] = target[]; - gc.prev_action = next_action; return gc.status_code; } diff --git a/planner.c b/planner.c index 7a38a0560..d83ae2322 100644 --- a/planner.c +++ b/planner.c @@ -195,14 +195,21 @@ void planner_line(double x, double y, double z, double feed_rate, uint8_t nomina } +void planner_dwell(double seconds, uint8_t nominal_laser_intensity) { +// // Execute dwell in seconds. Maximum time delay is > 18 hours, more than enough for any application. +// void mc_dwell(double seconds) { +// uint16_t i = floor(seconds); +// stepper_synchronize(); +// _delay_ms(floor(1000*(seconds-i))); // Delay millisecond remainder +// while (i > 0) { +// _delay_ms(1000); // Delay one second +// i--; +// } +// } +} + -// Add a new control and/or dwell command to the queue. -// These commands can control a GPIO and then dwell for a bit. This is useful when -// the hardware being switch has some delay. Alternatively by passing TYPE_DWELL the -// switching part can be omitted and simply a dwell can be scheduled. When doing this -// with a laser intensity !=0 this is effectively a piercing action. -// Note: any command (even when dwell time is 0) causes the planner to fully decelerate. -void planner_command(uint8_t type, double seconds, uint8_t nominal_laser_intensity) { +void planner_command(uint8_t type) { // calculate the buffer head and check for space int next_buffer_head = next_block_index( block_buffer_head ); while(block_buffer_tail == next_buffer_head) { // buffer full condition @@ -215,25 +222,7 @@ void planner_command(uint8_t type, double seconds, uint8_t nominal_laser_intensi // set block type command block->type = type; - - // set dwell time in cycles - block->dwell_until = seconds * F_CPU; - - // set block fields so planner calculates a correct - // acceleration profiles for the adjacent blocks - block->nominal_laser_intensity = nominal_laser_intensity; - block->direction_bits = 0; - block->steps_x = 0; - block->steps_y = 0; - block->steps_z = 0; - block->step_event_count = 0; - block->millimeters = 0.0; - block->nominal_speed = 0.0001; //must be > 0 ? - block->nominal_rate = 0; - block->rate_delta = 1; // must be > 0 ? - block->vmax_junction = ZERO_SPEED; - block->entry_speed = 0.0; - + // Move buffer head block_buffer_head = next_buffer_head; diff --git a/planner.h b/planner.h index e1658d3bf..1e673266b 100644 --- a/planner.h +++ b/planner.h @@ -24,22 +24,15 @@ #include "config.h" -// Command types the planner and stepper can schedule for execution +// Command types the planner and stepper can schedule for execution #define TYPE_LINE 0 -#define TYPE_DWELL 1 -#define TYPE_AIRGAS_DISABLE 2 -#define TYPE_AIR_ENABLE 3 -#define TYPE_GAS_ENABLE 4 -#define TYPE_LASER_ENABLE 5 -#define TYPE_LASER_DISABLE 6 +#define TYPE_AIRGAS_DISABLE 1 +#define TYPE_AIR_ENABLE 2 +#define TYPE_GAS_ENABLE 3 - -#define planner_dwell(seconds, intensity) planner_command(TYPE_DWELL, seconds, intensity) -#define planner_control_airgas_disable(seconds) planner_command(TYPE_AIRGAS_DISABLE, seconds, 0) -#define planner_control_air_enable(seconds) planner_command(TYPE_AIR_ENABLE, seconds, 0) -#define planner_control_gas_enable(seconds) planner_command(TYPE_GAS_ENABLE, seconds, 0) -#define planner_control_laser_enable(seconds, intensity) planner_command(TYPE_LASER_ENABLE, seconds, intensity) -#define planner_control_laser_disable(seconds) planner_command(TYPE_LASER_DISABLE, seconds, 0) +#define planner_control_airgas_disable() planner_command(TYPE_AIRGAS_DISABLE) +#define planner_control_air_enable() planner_command(TYPE_AIR_ENABLE) +#define planner_control_gas_enable() planner_command(TYPE_GAS_ENABLE) // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in @@ -52,18 +45,17 @@ typedef struct { int32_t step_event_count; // The number of step events required to complete this block uint32_t nominal_rate; // The nominal step rate for this block in step_events/minute // Fields used by the motion planner to manage acceleration - double nominal_speed; // The nominal speed for this block in mm/min (must be != 0) + double nominal_speed; // The nominal speed for this block in mm/min double entry_speed; // Entry speed at previous-current junction in mm/min double vmax_junction; // max junction speed (mm/min) based on angle between segments, accel and deviation settings double millimeters; // The total travel of this block in mm - double dwell_until; // number of cycles to dwell in place (not used for TYPE_LINE) uint8_t nominal_laser_intensity; // 0-255 is 0-100% percentage bool recalculate_flag; // Planner flag to recalculate trapezoids on entry junction bool nominal_length_flag; // Planner flag for nominal speed always reached // Settings for the trapezoid generator uint32_t initial_rate; // The jerk-adjusted step rate at start of block uint32_t final_rate; // The minimal rate at exit - int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be > 0) + int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be positive) uint32_t accelerate_until; // The index of the step event on which to stop acceleration uint32_t decelerate_after; // The index of the step event on which to start decelerating @@ -76,9 +68,12 @@ void planner_init(); // the signed, absolute target position in millimaters. Feed rate specifies the speed of the motion. void planner_line(double x, double y, double z, double feed_rate, uint8_t nominal_laser_intensity); +// Add a new piercing action, lasing at one spot +void planner_dwell(double seconds, uint8_t nominal_laser_intensity); + // Add a non-motion command to the queue. // Typical types are: TYPE_AIRGAS_DISABLE, TYPE_AIR_ENABLE, TYPE_GAS_ENABLE -void planner_command(uint8_t type, double seconds, uint8_t nominal_laser_intensity); +void planner_command(uint8_t type); bool planner_blocks_available(); diff --git a/sense_control.c b/sense_control.c index 3957312c4..2e04afd59 100644 --- a/sense_control.c +++ b/sense_control.c @@ -24,6 +24,7 @@ #include "planner.h" + void sense_init() { //// power, chiller, door SENSE_DDR &= ~(SENSE_MASK); // set as input pins @@ -48,10 +49,6 @@ void control_init() { TCCR0A |= (1 << WGM00); // set phase correct PWM mode, has half the freq of fast PWM TCCR0B |= (1 << CS00); // prescaler to 1, PWMfreq = 16000/(2*256*1) = 31.25kH - //// laser enable/disable pin - LASER_DDR |= (1 << LASER_ENABLE_BIT); // set as output pin - control_laser_enable(false); - //// air and gas assist control AIRGAS_DDR |= (1 << AIR_BIT); // set as output pin AIRGAS_DDR |= (1 << GAS_BIT); // set as output pin @@ -64,15 +61,6 @@ void control_init() { } - -void control_laser_enable(bool enable) { - if (enable) { - LASER_PORT |= (1 << LASER_ENABLE_BIT); - } else { - LASER_PORT &= ~(1 << LASER_ENABLE_BIT); - } -} - void control_laser_intensity(uint8_t intensity) { OCR0A = intensity; } diff --git a/sense_control.h b/sense_control.h index 8d5ceaefc..a86dfad15 100644 --- a/sense_control.h +++ b/sense_control.h @@ -35,7 +35,6 @@ void sense_init(); void control_init(); -void control_laser_enable(bool enable); void control_laser_intensity(uint8_t intensity); //0-255 is 0-100% void control_air(bool enable); diff --git a/stepper.c b/stepper.c index abfb22400..f0056909b 100644 --- a/stepper.c +++ b/stepper.c @@ -70,15 +70,16 @@ static volatile uint8_t busy; // true whe stepper ISR is in already running // Variables used by the trapezoid generation static uint32_t cycles_per_step_event; // The number of machine cycles between each step event -static uint32_t tick_counter; // The cycles since last speed change. +static uint32_t acceleration_tick_counter; // The cycles since last acceleration_tick. // Used to generate ticks at a steady pace without allocating a separate timer. static uint32_t adjusted_rate; // The current rate of step_events according to the speed profile static bool processing_flag; // indicates if blocks are being processed static volatile bool stop_requested; // when set to true stepper interrupt will go idle on next entry + // prototypes for static functions (non-accesible from other files) static bool acceleration_tick(); -static void adjust_speed( uint32_t steps_per_minute, bool adjust_laser ); +static void adjust_speed( uint32_t steps_per_minute ); static uint32_t config_step_timer(uint32_t cycles); @@ -104,9 +105,9 @@ void stepper_init() { TCCR2B = 0; // Disable timer until needed. TIMSK2 |= (1< simply suspend processing - if (CONFIG_USE_LASER_ENABLE_BIT) { - control_laser_enable(false); - } busy = false; return; } @@ -251,28 +246,21 @@ ISR(TIMER1_COMPA_vect) { stepper_go_idle(); busy = false; return; - } - // event - starting new block - if (current_block->type == TYPE_LINE) { + } + if (current_block->type == TYPE_LINE) { // starting on new line block adjusted_rate = current_block->initial_rate; - tick_counter = CYCLES_PER_ACCELERATION_TICK/2; // start halfway, midpoint rule. - adjust_speed( adjusted_rate, true ); // initialize cycles_per_step_event and timer interval + acceleration_tick_counter = CYCLES_PER_ACCELERATION_TICK/2; // start halfway, midpoint rule. + adjust_speed( adjusted_rate ); // initialize cycles_per_step_event counter_x = -(current_block->step_event_count >> 1); counter_y = counter_x; counter_z = counter_x; step_events_completed = 0; - } else { // TYPE_DWELL, ... - tick_counter = 0; // use tick_counter to keep track of dwell time - adjust_speed( 6000, false ); // set stepper timer resolution to about 10ms (0.01s) - if (current_block->type == TYPE_DWELL || current_block->type == TYPE_LASER_ENABLE) { - control_laser_intensity(current_block->nominal_laser_intensity); - } } } - //// process current block, populate out_bits (or handle other commands) //// - - if (current_block->type == TYPE_LINE) { + // process current block, populate out_bits (or handle other commands) + switch (current_block->type) { + case TYPE_LINE: ////// Execute step displacement profile by bresenham line algorithm out_bits = current_block->direction_bits; counter_x += current_block->steps_x; @@ -325,14 +313,14 @@ ISR(TIMER1_COMPA_vect) { if (adjusted_rate > current_block->nominal_rate) { // overshot adjusted_rate = current_block->nominal_rate; } - adjust_speed( adjusted_rate, true ); + adjust_speed( adjusted_rate ); } // deceleration start } else if (step_events_completed == current_block->decelerate_after) { // reset counter, midpoint rule // makes sure deceleration is performed the same every time - tick_counter = CYCLES_PER_ACCELERATION_TICK/2; + acceleration_tick_counter = CYCLES_PER_ACCELERATION_TICK/2; // decelerating } else if (step_events_completed >= current_block->decelerate_after) { @@ -341,7 +329,7 @@ ISR(TIMER1_COMPA_vect) { if (adjusted_rate < current_block->final_rate) { // overshot adjusted_rate = current_block->final_rate; } - adjust_speed( adjusted_rate, true ); + adjust_speed( adjusted_rate ); } // cruising @@ -349,45 +337,35 @@ ISR(TIMER1_COMPA_vect) { // No accelerations. Make sure we cruise exactly at the nominal rate. if (adjusted_rate != current_block->nominal_rate) { adjusted_rate = current_block->nominal_rate; - adjust_speed( adjusted_rate, true ); + adjust_speed( adjusted_rate ); } } } else { // block finished current_block = NULL; planner_discard_current_block(); - out_bits = INVERT_MASK; } ////////// END OF SPEED ADJUSTMENT - } else { //TYPE_DWELL, TYPE_AIRGAS_DISABLE, ... - // on first entry do switching based on type - if (tick_counter == 0) { - switch (current_block->type) { - case TYPE_AIRGAS_DISABLE: - control_air(false); - control_gas(false); - break; - case TYPE_AIR_ENABLE: - control_air(true); - break; - case TYPE_GAS_ENABLE: - control_gas(true); - break; - case TYPE_LASER_ENABLE: - control_laser_enable(true); - break; - case TYPE_LASER_DISABLE: - control_laser_enable(false); - break; - } - } - // keep track of time - tick_counter += cycles_per_step_event; - // finalize when dwell time is over - if(tick_counter > current_block->dwell_until) { - current_block = NULL; - planner_discard_current_block(); - } // else reenter and increase tick_counter until dwell time over + break; + + case TYPE_AIRGAS_DISABLE: + control_air(false); + control_gas(false); + current_block = NULL; + planner_discard_current_block(); + break; + + case TYPE_AIR_ENABLE: + control_air(true); + current_block = NULL; + planner_discard_current_block(); + break; + + case TYPE_GAS_ENABLE: + control_gas(true); + current_block = NULL; + planner_discard_current_block(); + break; } busy = false; @@ -400,9 +378,9 @@ ISR(TIMER1_COMPA_vect) { // keeping track of the number of elapsed cycles during a de/ac-celeration. The code assumes that // step_events occur significantly more often than the acceleration velocity iterations. static bool acceleration_tick() { - tick_counter += cycles_per_step_event; - if(tick_counter > CYCLES_PER_ACCELERATION_TICK) { - tick_counter -= CYCLES_PER_ACCELERATION_TICK; + acceleration_tick_counter += cycles_per_step_event; + if(acceleration_tick_counter > CYCLES_PER_ACCELERATION_TICK) { + acceleration_tick_counter -= CYCLES_PER_ACCELERATION_TICK; return true; } else { return false; @@ -450,24 +428,12 @@ static uint32_t config_step_timer(uint32_t cycles) { } -static void adjust_speed( uint32_t steps_per_minute, bool adjust_laser ) { +static void adjust_speed( uint32_t steps_per_minute ) { if (steps_per_minute < MINIMUM_STEPS_PER_MINUTE) { steps_per_minute = MINIMUM_STEPS_PER_MINUTE; } cycles_per_step_event = config_step_timer((CYCLES_PER_MICROSECOND*1000000*60)/steps_per_minute); - if (adjust_laser) { - if (CONFIG_BEAM_DYNAMICS) { - double slowdown_pct = steps_per_minute/current_block->nominal_rate; - // using y=x^2*d+(1-d) to soften the diminuation (d is CONFIG_BEAM_DIMINUTION). - // We could use slowdown_pct directly but this tends to be too aggressive and leads - // to corners getting too little power (opposite problem). To get a sense of the - // dynamic factor simply graph y=x^2*d+(1-d) for d in [0.0, 1.0] - double dynamic_factor = slowdown_pct*slowdown_pct*(CONFIG_BEAM_DIMINUTION)+(1-CONFIG_BEAM_DIMINUTION); - control_laser_intensity(current_block->nominal_laser_intensity * dynamic_factor); - } else { - // run at constant intensity - control_laser_intensity(current_block->nominal_laser_intensity); - } - } + // run at constant intensity for now + control_laser_intensity(current_block->nominal_laser_intensity); }