From b9afa2d459ba1968143987c4eea8958bed4e74a6 Mon Sep 17 00:00:00 2001 From: Stefan Hechenberger Date: Mon, 13 Feb 2012 18:04:05 +0100 Subject: [PATCH] merging: testing all features, sensors working (after grounding the shield of the wire), multiple offsets, homing, stopping and resuming, ... --- README.md | 5 +++ config.h | 7 +++- gcode.c | 30 ++++++++++---- sense_control.c | 4 +- sense_control.h | 18 ++++---- stepper.c | 107 ++++++++++++++++++++++++------------------------ 6 files changed, 96 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 2305e6edc..b2b5b9053 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@ 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 ------------------ - removed diff --git a/config.h b/config.h index fd8857781..9b27f9d3c 100644 --- a/config.h +++ b/config.h @@ -34,6 +34,7 @@ #define SENSE_DDR DDRD #define SENSE_PORT PORTD +#define SENSE_PIN PIND #define POWER_BIT 2 #define CHILLER_BIT 3 #define DOOR_BIT 5 @@ -107,8 +108,10 @@ #define CHAR_XOFF '\x13' #define CHAR_XON '\x11' -#define CHAR_STOP '\x03' -#define CHAR_RESUME '\x02' +// #define CHAR_STOP '\x03' +// #define CHAR_RESUME '\x02' +#define CHAR_STOP '!' +#define CHAR_RESUME '~' #define X_AXIS 0 #define Y_AXIS 1 diff --git a/gcode.c b/gcode.c index 532c56405..5c5d1925d 100644 --- a/gcode.c +++ b/gcode.c @@ -51,6 +51,9 @@ #define STATUS_FLOATING_POINT_ERROR 4 #define STATUS_STOP_STATE_ERROR 5 +#define OFFSET_G54 0 +#define OFFSET_G55 1 + #define BUFFER_LINE_SIZE 80 char rx_line[BUFFER_LINE_SIZE]; @@ -85,13 +88,13 @@ void gcode_init() { gc.nominal_laser_intensity = 0U; gc.offselect = 0; // default to G54 coordinate system // prime G54 cs - // refine with "G10 L2 P1 X_ Y_ Z_" + // refine with "G10 L2 P0 X_ Y_ Z_" gc.offsets[X_AXIS] = CONFIG_X_ORIGIN_OFFSET; gc.offsets[Y_AXIS] = CONFIG_Y_ORIGIN_OFFSET; gc.offsets[Z_AXIS] = CONFIG_Z_ORIGIN_OFFSET; // prime G55 cs - // refine with "G10 L2 P2 X_ Y_ Z_" - // or set to any current location with "G10 L20 P2" + // refine with "G10 L2 P1 X_ Y_ Z_" + // or set to any current location with "G10 L20 P1" 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; @@ -218,8 +221,8 @@ uint8_t gcode_execute_line(char *line) { case 20: gc.inches_mode = true; break; case 21: gc.inches_mode = false; break; case 30: next_action = NEXT_ACTION_HOMING_CYCLE; break; - case 54: gc.offselect = 0; break; - case 55: gc.offselect = 1; break; + case 54: gc.offselect = OFFSET_G54; break; + case 55: gc.offselect = OFFSET_G55; break; case 90: gc.absolute_mode = true; break; case 91: gc.absolute_mode = false; break; default: FAIL(STATUS_UNSUPPORTED_STATEMENT); @@ -327,9 +330,18 @@ uint8_t gcode_execute_line(char *line) { clear_vector(target); stepper_set_position(0.0, 0.0, 0.0); planner_set_position(0.0, 0.0, 0.0); + // move head to g54 offset + gc.offselect = OFFSET_G54; + 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_SET_COORDINATE_OFFSET: - if (cs == 0 || cs == 1) { // corresponds to G54, G55 + if (cs == OFFSET_G54 || cs == OFFSET_G55) { if (l == 2) { //set offset to target, eg: G10 L2 P1 X15 Y15 Z0 gc.offsets[3*cs+X_AXIS] = target[X_AXIS]; @@ -337,9 +349,9 @@ uint8_t gcode_execute_line(char *line) { gc.offsets[3*cs+Z_AXIS] = target[Z_AXIS]; } else if (l == 20) { // set offset to current pos, eg: G10 L20 P2 - gc.offsets[3*cs+X_AXIS] = gc.position[X_AXIS]; - gc.offsets[3*cs+Y_AXIS] = gc.position[X_AXIS]; - gc.offsets[3*cs+Z_AXIS] = gc.position[X_AXIS]; + gc.offsets[3*cs+X_AXIS] = gc.position[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS]; + gc.offsets[3*cs+Y_AXIS] = gc.position[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS]; + gc.offsets[3*cs+Z_AXIS] = gc.position[Z_AXIS] + gc.offsets[3*gc.offselect+Z_AXIS]; } } break; diff --git a/sense_control.c b/sense_control.c index 4fa720f54..2e04afd59 100644 --- a/sense_control.c +++ b/sense_control.c @@ -28,11 +28,11 @@ void sense_init() { //// power, chiller, door SENSE_DDR &= ~(SENSE_MASK); // set as input pins - // LIMIT_PORT |= LIMIT_MASK; //activate pull-up resistors + // SENSE_PORT |= SENSE_MASK; //activate pull-up resistors //// x1_lmit, x2_limit, y1_limit, y2_limit LIMIT_DDR &= ~(LIMIT_MASK); // set as input pins - LIMIT_PORT |= LIMIT_MASK; //activate pull-up resistors + // LIMIT_PORT |= LIMIT_MASK; //activate pull-up resistors } diff --git a/sense_control.h b/sense_control.h index f973eb6e9..a86dfad15 100644 --- a/sense_control.h +++ b/sense_control.h @@ -22,15 +22,15 @@ void sense_init(); -#define SENSE_POWER ((SENSE_PORT >> POWER_BIT) & 1) -#define SENSE_CHILLER ((SENSE_PORT >> CHILLER_BIT) & 1) -#define SENSE_DOOR ((SENSE_PORT >> DOOR_BIT) & 1) -#define SENSE_X1_LIMIT ((SENSE_PORT >> X1_LIMIT_BIT) & 1) -#define SENSE_X2_LIMIT ((SENSE_PORT >> X2_LIMIT_BIT) & 1) -#define SENSE_Y1_LIMIT ((SENSE_PORT >> Y1_LIMIT_BIT) & 1) -#define SENSE_Y2_LIMIT (SENSE_PORT >> Y2_LIMIT_BIT) & 1 -#define SENSE_LIMITS ((LIMIT_PORT & LIMIT_MASK) > 0) -#define SENSE_ANY (((LIMIT_PORT & LIMIT_MASK) > 0) && ((SENSE_PORT & SENSE_MASK) > 0)) +#define SENSE_POWER_OFF !((SENSE_PIN >> POWER_BIT) & 1) +#define SENSE_CHILLER_OFF !((SENSE_PIN >> CHILLER_BIT) & 1) +#define SENSE_DOOR_OPEN !((SENSE_PIN >> DOOR_BIT) & 1) +#define SENSE_X1_LIMIT !((LIMIT_PIN >> X1_LIMIT_BIT) & 1) +#define SENSE_X2_LIMIT !((LIMIT_PIN >> X2_LIMIT_BIT) & 1) +#define SENSE_Y1_LIMIT !((LIMIT_PIN >> Y1_LIMIT_BIT) & 1) +#define SENSE_Y2_LIMIT !((LIMIT_PIN >> Y2_LIMIT_BIT) & 1) +#define SENSE_LIMITS (SENSE_X1_LIMIT || SENSE_X2_LIMIT || SENSE_Y1_LIMIT || SENSE_Y2_LIMIT) +#define SENSE_ANY (SENSE_LIMITS || SENSE_POWER_OFF || SENSE_CHILLER_OFF || SENSE_DOOR_OPEN) void control_init(); diff --git a/stepper.c b/stepper.c index 0219e7536..060cd9b32 100644 --- a/stepper.c +++ b/stepper.c @@ -210,14 +210,15 @@ ISR(TIMER1_COMPA_vect) { } if (SENSE_ANY) { - // printString("sense_any\n"); // no power (e-stop), no chiller, door open, limit switch situation - if (SENSE_POWER || SENSE_CHILLER || SENSE_LIMITS) { + if (SENSE_POWER_OFF || SENSE_CHILLER_OFF || SENSE_LIMITS) { + // printString("sense\n"); // stop program stepper_request_stop(); busy = false; return; - } else { + } else if (SENSE_DOOR_OPEN) { + // printString("door\n"); // door open -> simply suspend processing busy = false; return; @@ -447,54 +448,54 @@ static void adjust_speed( uint32_t steps_per_minute ) { static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, bool reverse_direction, uint32_t microseconds_per_pulse) { - // uint32_t step_delay = microseconds_per_pulse - CONFIG_PULSE_MICROSECONDS; - // uint8_t out_bits = DIRECTION_MASK; - // uint8_t limit_bits; - // - // if (x_axis) { out_bits |= (1<