Skip to content

Commit

Permalink
Minor updates, improvements, and bug fixes.
Browse files Browse the repository at this point in the history
- Allowed status_message function to be called by others. This is to
centralize all feedback into protocol.c.

- Fixed a bug where line number words 'N' were causing the parser to
error out.

- Allowed homing routine feed rates to move slower than the
MINIMUM_STEP_RATE parameter in config.h.

- Homing performs idle lock at the end of the routine.

- Stepper idle lock time will now not disable the steppers when the
value is set at 255. This is accomodate users who prefer to keep their
axes enabled at all times.

- Moved some defines around to where they need to be.
  • Loading branch information
chamnit committed Oct 13, 2012
1 parent 00701ff commit 34f6d2e
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 15 deletions.
5 changes: 4 additions & 1 deletion gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ void gc_init()
gc.feed_rate = settings.default_feed_rate;
select_plane(X_AXIS, Y_AXIS, Z_AXIS);
gc.absolute_mode = true;

// protocol_status_message(settings_execute_startup());
}

// Sets g-code parser position in mm. Input in steps. Called by the system abort routine.
Expand Down Expand Up @@ -180,6 +182,7 @@ uint8_t gc_execute_line(char *line)
case 20: gc.inches_mode = true; break;
case 21: gc.inches_mode = false; break;
case 28: case 30:
// NOTE: G28.1, G30.1 sets home position parameters. Not currently supported.
if (bit_istrue(settings.flags,FLAG_BIT_HOMING_ENABLE)) {
non_modal_action = NON_MODAL_GO_HOME;
} else {
Expand Down Expand Up @@ -259,7 +262,7 @@ uint8_t gc_execute_line(char *line)
char_counter = 0;
while(next_statement(&letter, &value, line, &char_counter)) {
switch(letter) {
case 'G': case 'M': break; // Ignore command statements
case 'G': case 'M': case 'N': break; // Ignore command statements and line numbers
case 'F':
if (value <= 0) { FAIL(STATUS_INVALID_COMMAND); } // Must be greater than zero
if (gc.inverse_feed_rate_mode) {
Expand Down
14 changes: 10 additions & 4 deletions limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "motion_control.h"
#include "planner.h"
#include "protocol.h"
#include "limits.h"

#define MICROSECONDS_PER_ACCELERATION_TICK (1000000/ACCELERATION_TICKS_PER_SECOND)

Expand Down Expand Up @@ -76,9 +77,11 @@ static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, int8_t pos_dir,

// Nominal and initial time increment per step. Nominal should always be greater then 3
// usec, since they are based on the same parameters as the main stepper routine. Initial
// is based on the MINIMUM_STEPS_PER_MINUTE config.
// is based on the MINIMUM_STEPS_PER_MINUTE config. Since homing feed can be very slow,
// disable acceleration when rates are below MINIMUM_STEPS_PER_MINUTE.
uint32_t dt_min = lround(1000000*60/(ds*homing_rate)); // Cruising (usec/step)
uint32_t dt = 1000000*60/MINIMUM_STEPS_PER_MINUTE; // Initial (usec/step)
if (dt > dt_min) { dt = dt_min; } // Disable acceleration for very slow rates.

// Set default out_bits.
uint8_t out_bits0 = settings.invert_mask;
Expand Down Expand Up @@ -164,8 +167,8 @@ void limits_go_home()
STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT);

// Jog all axes toward home to engage their limit switches at faster homing seek rate.
homing_cycle(false, false, true, true, false, settings.homing_seek_rate); // First jog the z axis
homing_cycle(true, true, false, true, false, settings.homing_seek_rate); // Then jog the x and y axis
homing_cycle(false, false, true, true, false, settings.homing_seek_rate); // First jog the z axis
homing_cycle(true, true, false, true, false, settings.homing_seek_rate); // Then jog the x and y axis
delay_ms(settings.homing_debounce_delay); // Delay to debounce signal

// Now in proximity of all limits. Carefully leave and approach switches in multiple cycles
Expand All @@ -183,6 +186,9 @@ void limits_go_home()
}
}

delay_ms(settings.stepper_idle_lock_time);
// Disable steppers by setting stepper disable
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
if (settings.stepper_idle_lock_time != 0xff) {
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
}
}
2 changes: 2 additions & 0 deletions limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef limits_h
#define limits_h

#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits

// initialize the limits module
void limits_init();

Expand Down
6 changes: 6 additions & 0 deletions planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ void plan_buffer_line(float x, float y, float z, float feed_rate, uint8_t invert
// path width or max_jerk in the previous grbl version. This approach does not actually deviate
// from path, but used as a robust way to compute cornering speeds, as it takes into account the
// nonlinearities of both the junction angle and junction velocity.
// NOTE: This is basically an exact path mode (G61), but it doesn't come to a complete stop unless
// the junction deviation value is high. In the future, if continuous mode (G64) is desired, the
// math here is exactly the same. Instead of motioning all the way to junction point, the machine
// will just need to follow the arc circle defined above and check if the arc radii are no longer
// than half of either line segment to ensure no overlapping. Right now, the Arduino likely doesn't
// have the horsepower to do these calculations at high feed rates.
float vmax_junction = MINIMUM_PLANNER_SPEED; // Set default max junction speed

// Skip first block or when previous_nominal_speed is used as a flag for homing and offset cycles.
Expand Down
8 changes: 3 additions & 5 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
#include "stepper.h"
#include "planner.h"

#define LINE_BUFFER_SIZE 50

static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.
static uint8_t char_counter; // Last character counter in line variable.
static uint8_t iscomment; // Comment/block delete flag for processor to ignore comment characters.

static void status_message(int status_code)
void protocol_status_message(int8_t status_code)
{
if (status_code == 0) {
printPgmString(PSTR("ok\r\n"));
Expand Down Expand Up @@ -220,10 +218,10 @@ void protocol_process()

if (char_counter > 0) {// Line is complete. Then execute!
line[char_counter] = 0; // Terminate string
status_message(protocol_execute_line(line));
protocol_status_message(protocol_execute_line(line));
} else {
// Empty or comment line. Skip block.
status_message(STATUS_OK); // Send status message for syncing purposes.
protocol_status_message(STATUS_OK); // Send status message for syncing purposes.
}
char_counter = 0; // Reset line buffer index
iscomment = false; // Reset comment flag
Expand Down
5 changes: 5 additions & 0 deletions protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define STATUS_INVALID_COMMAND 6
#define STATUS_SETTING_DISABLED 7

#define LINE_BUFFER_SIZE 50

// Initialize the serial protocol
void protocol_init();

Expand All @@ -43,4 +45,7 @@ uint8_t protocol_execute_line(char *line);
// Checks and executes a runtime command at various stop points in main program
void protocol_execute_runtime();

// Prints g-code parser status message.
void protocol_status_message(int8_t status_code);

#endif
45 changes: 44 additions & 1 deletion settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ void settings_reset(bool reset_all) {
settings.decimal_places = DEFAULT_DECIMAL_PLACES;
}

// static void settings_startup_string(char *buf) {
// memcpy_from_eeprom_with_checksum((char*)buf,512, 4);
// }

void settings_dump() {
printPgmString(PSTR("$0 = ")); printFloat(settings.steps_per_mm[X_AXIS]);
printPgmString(PSTR(" (steps/mm x)\r\n$1 = ")); printFloat(settings.steps_per_mm[Y_AXIS]);
Expand All @@ -124,19 +128,42 @@ void settings_dump() {
printPgmString(PSTR(" (milliseconds homing debounce delay)\r\n$14 = ")); printInteger(settings.stepper_idle_lock_time);
printPgmString(PSTR(" (milliseconds stepper idle lock time)\r\n$15 = ")); printInteger(settings.decimal_places);
printPgmString(PSTR(" (float decimal places)"));

// char buf[4];
// settings_startup_string((char *)buf);
// printPgmString(PSTR("\r\n Startup: ")); printString(buf);

printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n"));
}

// Parameter lines are on the form '$4=374.3' or '$' to dump current settings
uint8_t settings_execute_line(char *line) {
uint8_t char_counter = 1;
// unsigned char letter;
float parameter, value;
if(line[0] != '$') {
return(STATUS_UNSUPPORTED_STATEMENT);
}
if(line[char_counter] == 0) {
settings_dump(); return(STATUS_OK);
}
// if(line[char_counter] >= 'A' || line[char_counter] <= 'Z') {
// letter = line[char_counter++];
// if(line[char_counter++] != '=') {
// return(STATUS_UNSUPPORTED_STATEMENT);
// }
// for (char_counter = 0; char_counter < LINE_BUFFER_SIZE-3; char_counter++) {
// line[char_counter] = line[char_counter+3];
// }
// uint8_t status = gc_execute_line(line);
// if (status) { return(status); }
// else { settings_store_startup_line(line); }
//
//
// // Opt stop and block delete are referred to as switches.
// // How to store home position and work offsets real-time??
//
// } else {
if(!read_float(line, &char_counter, &parameter)) {
return(STATUS_BAD_NUMBER_FORMAT);
};
Expand All @@ -151,11 +178,16 @@ uint8_t settings_execute_line(char *line) {
}
settings_store_setting(parameter, value);
return(STATUS_OK);
// }
}

void write_settings() {
eeprom_put_char(0, SETTINGS_VERSION);
memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(settings_t));
//
// char buf[4]; buf[0] = 'G'; buf[1] = '2'; buf[2] = '0'; buf[3] = 0;
// memcpy_to_eeprom_with_checksum(512, (char*)buf, 4);
//
}

int read_settings() {
Expand Down Expand Up @@ -254,5 +286,16 @@ void settings_init() {
settings_reset(true);
write_settings();
settings_dump();
}
}
}

// int8_t settings_execute_startup() {
//
// char buf[4];
// settings_startup_string((char *)buf);
// uint8_t i = 0;
// while (i < 4) {
// serial_write(buf[i++]);
// }
// return(gc_execute_line(buf));
// }
4 changes: 3 additions & 1 deletion settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
// when firmware is upgraded. Always stored in byte 0 of eeprom
#define SETTINGS_VERSION 52
#define SETTINGS_VERSION 53

// Define bit flag masks in settings.flag.
#define FLAG_BIT_HOMING_ENABLE bit(0)
Expand Down Expand Up @@ -68,4 +68,6 @@ uint8_t settings_execute_line(char *line);
// A helper method to set new settings from command line
void settings_store_setting(int parameter, float value);

// int8_t settings_execute_startup();

#endif
6 changes: 4 additions & 2 deletions stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ void st_go_idle()
TIMSK1 &= ~(1<<OCIE1A);
// Force stepper dwell to lock axes for a defined amount of time to ensure the axes come to a complete
// stop and not drift from residual inertial forces at the end of the last movement.
delay_ms(settings.stepper_idle_lock_time);
delay_ms(settings.stepper_idle_lock_time);
// Disable steppers by setting stepper disable
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
if (settings.stepper_idle_lock_time != 0xff) {
STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT);
}
}

// This function determines an acceleration velocity change every CYCLES_PER_ACCELERATION_TICK by
Expand Down
1 change: 0 additions & 1 deletion stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <avr/sleep.h>

// Some useful constants
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
Expand Down

0 comments on commit 34f6d2e

Please sign in to comment.