Skip to content

Commit

Permalink
reverting to hex file from lasaur app binary distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Hechenberger committed Apr 14, 2012
1 parent 1fec177 commit 666eaae
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 214 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down Expand Up @@ -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



Expand Down
29 changes: 1 addition & 28 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdbool.h>


#define LASAURGRBL_VERSION "v12.03-beta1"
#define LASAURGRBL_VERSION "v12.02-beta1"
#define BAUD_RATE 9600


Expand All @@ -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
Expand All @@ -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
Expand Down
82 changes: 34 additions & 48 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand Down
41 changes: 15 additions & 26 deletions planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
31 changes: 13 additions & 18 deletions planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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();
Expand Down
Loading

0 comments on commit 666eaae

Please sign in to comment.