First parsed G-code commandgit add .!

This commit is contained in:
Anders Sandstrom
2022-01-18 15:28:28 +01:00
parent 6ce6b78ebe
commit 6e4bd2410f
7 changed files with 219 additions and 97 deletions

View File

@@ -22,6 +22,9 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include "ecmcPluginDefs.h"
#include "ecmcPluginClient.h"
@@ -35,33 +38,22 @@ extern "C" {
static int lastEcmcError = 0;
static char* lastConfStr = NULL;
static int alreadyLoaded = 0;
int initDone = 0;
pthread_t tid;
/** Optional.
* Will be called once after successfull load into ecmc.
* Return value other than 0 will be considered error.
* configStr can be used for configuration parameters.
**/
int grblConstruct(char *configStr)
{
if(alreadyLoaded) {
return 1;
}
alreadyLoaded = 1;
// create SocketCAN object and register data callback
lastConfStr = strdup(configStr);
// copied for grbl main.c
void *ecmc_grbl_main_thread(void *ptr) {
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// Initialize system upon power-up.
//serial_init(); // Setup serial baud rate and interrupts
serial_init(); // Setup serial baud rate and interrupts
ecmc_init_file(); // create and clear file (simulated eeprom)
settings_restore(0b1111); // restore all to defaults
settings_init(); // Load Grbl settings from EEPROM
stepper_init(); // Configure stepper pins and interrupt timers
system_init(); // Configure pinout pins and pin-change interrupt
memset(sys_position,0,sizeof(sys_position)); // Clear machine position.
//sei(); // Enable interrupts
// Initialize system state.
#ifdef FORCE_INITIALIZATION_ALARM
// Force Grbl into an ALARM state upon a power-cycle or hard reset.
@@ -80,11 +72,9 @@ int grblConstruct(char *configStr)
#ifdef HOMING_INIT_LOCK
if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
#endif
// Grbl initialization loop upon power-up or a system abort. For the latter, all processes
// Grbl initialization loop upon power-up or a system abort. For the latter, all processes
// will return to this loop to be cleanly re-initialized.
//for(;;) {
for(;;) {
// Reset system variables.
uint8_t prior_state = sys.state;
memset(&sys, 0, sizeof(system_t)); // Clear system struct variable.
@@ -116,10 +106,81 @@ int grblConstruct(char *configStr)
// Print welcome message. Indicates an initialization has occured at power-up or with a reset.
report_init_message();
// Start Grbl main loop. Processes program inputs and executes them.
//protocol_main_loop(); This is for serial interface use.. comment out for now..
//}
// ready for commands through serial interface
initDone = 1;
protocol_main_loop();
}
}
/** Optional.
* Will be called once after successfull load into ecmc.
* Return value other than 0 will be considered error.
* configStr can be used for configuration parameters.
**/
int grblConstruct(char *configStr)
{
if(alreadyLoaded) {
return 1;
}
alreadyLoaded = 1;
// create SocketCAN object and register data callback
lastConfStr = strdup(configStr);
// start grbl main thread and wait for init done!
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
int err;
err = pthread_create(&(tid), NULL, *ecmc_grbl_main_thread, NULL);
if (err != 0) {
printf("\n Can't create thread :[%s]", strerror(err));
return 1;
}
else
printf("\n grbl main thread created successfully\n");
// whait for initDone!
printf("Waiting for grbl init..");
while(!initDone) {
sleep(1);
printf(".");
}
printf("\n");
printf("\n grbl ready for commands!\n");
sleep(1);
// test some commands
printf("Test command:G0X11\n");
ecmc_write_command_serial("G0X11\n");
printf("Test command:$J=X10.0Y-1.5\n");
ecmc_write_command_serial("$J=X10.0Y-1.5\n");
printf("Test command:#\n");
ecmc_write_command_serial("#\n");
printf("Test command:?\n");
ecmc_write_command_serial("?\n");
printf("Test command:G1X200Y100\n");
ecmc_write_command_serial("G1X200Y100\n");
return 0;
printf("system_execute_line(G0 X11), %d \n ",system_execute_line("G0X11\0"));
printf("end\n");
printf("system_execute_line(G1X200Y100), %d \n",system_execute_line("G1X200Y100\0"));
printf("end\n");
printf("system_execute_line($$), %d \n",system_execute_line("$$\0"));
printf("end\n");
printf("system_execute_line($), %d \n",system_execute_line("$\0"));
printf("end\n");
printf("system_execute_line(#), %d \n",system_execute_line("#\0"));
printf("end\n");
printf("system_execute_line(?), %d \n",system_execute_line("?\0"));
printf("end\n");
printf("system_execute_line($J=X10.0Y-1.5), %d \n",system_execute_line("$J=X10.0Y-1.5\0"));
printf("end\n");
printf("gc_execute_line(G0 X100.25), %d \n",gc_execute_line("G0 X100.25\0"));
printf("end\n");
printf("gc_execute_line(G1X200Y100), %d \n",gc_execute_line("G1X200Y100\0"));
printf("end\n");
return 0; //createSocketCAN(configStr,getEcmcSampleTimeMS());
}

View File

@@ -41,6 +41,8 @@ parser_block_t gc_block;
void gc_init()
{
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
memset(&gc_state, 0, sizeof(parser_state_t));
// Load default G54 coordinate system.
@@ -54,6 +56,8 @@ void gc_init()
// limit pull-off routines.
void gc_sync_position()
{
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
system_convert_array_steps_to_mpos(gc_state.position,sys_position);
}
@@ -65,6 +69,8 @@ void gc_sync_position()
// coordinates, respectively.
uint8_t gc_execute_line(char *line)
{
printf("%s:%s:%d:%s\n",__FILE__,__FUNCTION__,__LINE__,line);
/* -------------------------------------------------------------------------------------
STEP 1: Initialize parser block struct and copy current g-code state modes. The parser
updates these modes and commands as the block line is parser and will only be used and
@@ -115,13 +121,15 @@ uint8_t gc_execute_line(char *line)
else { char_counter = 0; }
while (line[char_counter] != 0) { // Loop until no more g-code words in line.
printf("1\n");
// Import the next g-code word, expecting a letter followed by a value. Otherwise, error out.
letter = line[char_counter];
printf("letter=%c\n", letter);
if((letter < 'A') || (letter > 'Z')) { FAIL(STATUS_EXPECTED_COMMAND_LETTER); } // [Expected word letter]
char_counter++;
if (!read_float(line, &char_counter, &value)) { FAIL(STATUS_BAD_NUMBER_FORMAT); } // [Expected word value]
printf("value=%f\n", value);
// Convert values to smaller uint8 significand and mantissa values for parsing this word.
// NOTE: Mantissa is multiplied by 100 to catch non-integer command values. This is more
// accurate than the NIST gcode requirement of x10 when used for commands, but not quite
@@ -131,6 +139,8 @@ uint8_t gc_execute_line(char *line)
// Maybe update this later.
int_value = trunc(value);
mantissa = round(100*(value - int_value)); // Compute mantissa for Gxx.x commands.
printf("int_value=%d\n", int_value);
printf("mantissa=%d\n", mantissa);
// NOTE: Rounding must be used to catch small floating point errors.
// Check if the g-code word is supported or errors due to modal group violations or has
@@ -166,6 +176,8 @@ uint8_t gc_execute_line(char *line)
if (axis_command) { FAIL(STATUS_GCODE_AXIS_COMMAND_CONFLICT); } // [Axis word/command conflict]
axis_command = AXIS_COMMAND_MOTION_MODE;
// No break. Continues to next line.
printf("axis_command=%d\n", axis_command);
case 80:
word_bit = MODAL_GROUP_G1;
gc_block.modal.motion = int_value;
@@ -175,7 +187,8 @@ uint8_t gc_execute_line(char *line)
}
gc_block.modal.motion += (mantissa/10)+100;
mantissa = 0; // Set to zero to indicate valid non-integer G command.
}
}
printf("here!!\n");
break;
case 17: case 18: case 19:
word_bit = MODAL_GROUP_G2;
@@ -232,11 +245,13 @@ uint8_t gc_execute_line(char *line)
break;
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G command]
}
printf("here 2!!\n");
if (mantissa > 0) { FAIL(STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER); } // [Unsupported or invalid Gxx.x command]
// Check for more than one command per modal group violations in the current block
// NOTE: Variable 'word_bit' is always assigned, if the command is valid.
if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
command_words |= bit(word_bit);
printf("here 3!!\n");
break;
case 'M':
@@ -282,13 +297,12 @@ uint8_t gc_execute_line(char *line)
#endif
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported M command]
}
// Check for more than one command per modal group violations in the current block
// NOTE: Variable 'word_bit' is always assigned, if the command is valid.
if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
command_words |= bit(word_bit);
break;
// NOTE: All remaining letters assign values.
default:
@@ -330,8 +344,9 @@ uint8_t gc_execute_line(char *line)
if (value < 0.0) { FAIL(STATUS_NEGATIVE_VALUE); } // [Word value cannot be negative]
}
value_words |= bit(word_bit); // Flag to indicate parameter assigned.
}
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
}
// Parsing complete!
@@ -366,15 +381,19 @@ uint8_t gc_execute_line(char *line)
// Determine implicit axis command conditions. Axis words have been passed, but no explicit axis
// command has been sent. If so, set axis command to current motion mode.
printf("%s:%s:%d:axis_words=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_words);
printf("%s:%s:%d:axis_command=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_command);
if (axis_words) {
if (!axis_command) { axis_command = AXIS_COMMAND_MOTION_MODE; } // Assign implicit motion-mode
}
printf("%s:%s:%d:axis_command=%d\n",__FILE__,__FUNCTION__,__LINE__,axis_command);
// Check for valid line number N value.
if (bit_istrue(value_words,bit(WORD_N))) {
// Line number value cannot be less than zero (done) or greater than max line number.
if (gc_block.values.n > MAX_LINE_NUMBER) { FAIL(STATUS_GCODE_INVALID_LINE_NUMBER); } // [Exceeds max line number]
}
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// bit_false(value_words,bit(WORD_N)); // NOTE: Single-meaning value word. Set at end of error-checking.
// Track for unused words at the end of error-checking.
@@ -389,10 +408,14 @@ uint8_t gc_execute_line(char *line)
// [2. Set feed rate mode ]: G93 F word missing with G1,G2/3 active, implicitly or explicitly. Feed rate
// is not defined after switching to G94 from G93.
// NOTE: For jogging, ignore prior feed rate mode. Enforce G94 and check for required F word.
printf("%s:%s:%d:gc_parser_flags=%d\n",__FILE__,__FUNCTION__,__LINE__,gc_parser_flags);
if (gc_parser_flags & GC_PARSER_JOG_MOTION) {
if (bit_isfalse(value_words,bit(WORD_F))) { FAIL(STATUS_GCODE_UNDEFINED_FEED_RATE); }
if (gc_block.modal.units == UNITS_MODE_INCHES) { gc_block.values.f *= MM_PER_INCH; }
} else {
printf("%s:%s:%d:gc_block.modal.feed_rate=%d\n",__FILE__,__FUNCTION__,__LINE__,gc_block.modal.feed_rate);
if (gc_block.modal.feed_rate == FEED_RATE_MODE_INVERSE_TIME) { // = G93
// NOTE: G38 can also operate in inverse time, but is undefined as an error. Missing F word check added here.
if (axis_command == AXIS_COMMAND_MOTION_MODE) {
@@ -418,6 +441,8 @@ uint8_t gc_execute_line(char *line)
if (bit_istrue(value_words,bit(WORD_F))) {
if (gc_block.modal.units == UNITS_MODE_INCHES) { gc_block.values.f *= MM_PER_INCH; }
} else {
printf("%s:%s:%d:gc_state.feed_rate=%f\n",__FILE__,__FUNCTION__,__LINE__,gc_state.feed_rate);
gc_block.values.f = gc_state.feed_rate; // Push last state feed rate
}
} // Else, switching to G94 from G93, so don't push last state feed rate. Its undefined or the passed F word value.

View File

@@ -74,12 +74,11 @@ void protocol_main_loop()
uint8_t char_counter = 0;
uint8_t c;
for (;;) {
// Process one line of incoming serial data, as the data becomes available. Performs an
// initial filtering by removing spaces and comments and capitalizing all letters.
while((c = serial_read()) != SERIAL_NO_DATA) {
while((c = serial_read()) != SERIAL_NO_DATA) {
if ((c == '\n') || (c == '\r')) { // End of line reached
printf("NEW_CHAR\n");
protocol_execute_realtime(); // Runtime command check point.
if (sys.abort) { return; } // Bail to calling function upon system abort

View File

@@ -128,11 +128,10 @@ void serial_write(uint8_t data) {
// if (tail == serial_tx_buffer_head) { UCSR0B &= ~(1 << UDRIE0); }
//}
// Fetches the first byte in the serial read buffer. Called by main program.
uint8_t serial_read()
{
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
//printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
uint8_t tail = serial_rx_buffer_tail; // Temporary serial_rx_buffer_tail (to optimize for volatile)
if (serial_rx_buffer_head == tail) {
return SERIAL_NO_DATA;
@@ -147,64 +146,73 @@ uint8_t serial_read()
}
}
//ISR(SERIAL_RX)
//{
// uint8_t data = UDR0;
// uint8_t next_head;
//
// // Pick off realtime command characters directly from the serial stream. These characters are
// // not passed into the main buffer, but these set system state flag bits for realtime execution.
// switch (data) {
// case CMD_RESET: mc_reset(); break; // Call motion control reset routine.
// case CMD_STATUS_REPORT: system_set_exec_state_flag(EXEC_STATUS_REPORT); break; // Set as true
// case CMD_CYCLE_START: system_set_exec_state_flag(EXEC_CYCLE_START); break; // Set as true
// case CMD_FEED_HOLD: system_set_exec_state_flag(EXEC_FEED_HOLD); break; // Set as true
// default :
// if (data > 0x7F) { // Real-time control characters are extended ACSII only.
// switch(data) {
// case CMD_SAFETY_DOOR: system_set_exec_state_flag(EXEC_SAFETY_DOOR); break; // Set as true
// case CMD_JOG_CANCEL:
// if (sys.state & STATE_JOG) { // Block all other states from invoking motion cancel.
// system_set_exec_state_flag(EXEC_MOTION_CANCEL);
// }
// break;
// #ifdef DEBUG
// case CMD_DEBUG_REPORT: {uint8_t sreg = SREG; cli(); bit_true(sys_rt_exec_debug,EXEC_DEBUG_REPORT); SREG = sreg;} break;
// #endif
// case CMD_FEED_OVR_RESET: system_set_exec_motion_override_flag(EXEC_FEED_OVR_RESET); break;
// case CMD_FEED_OVR_COARSE_PLUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_COARSE_PLUS); break;
// case CMD_FEED_OVR_COARSE_MINUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_COARSE_MINUS); break;
// case CMD_FEED_OVR_FINE_PLUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_FINE_PLUS); break;
// case CMD_FEED_OVR_FINE_MINUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_FINE_MINUS); break;
// case CMD_RAPID_OVR_RESET: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_RESET); break;
// case CMD_RAPID_OVR_MEDIUM: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_MEDIUM); break;
// case CMD_RAPID_OVR_LOW: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_LOW); break;
// case CMD_SPINDLE_OVR_RESET: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_RESET); break;
// case CMD_SPINDLE_OVR_COARSE_PLUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_PLUS); break;
// case CMD_SPINDLE_OVR_COARSE_MINUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_MINUS); break;
// case CMD_SPINDLE_OVR_FINE_PLUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_PLUS); break;
// case CMD_SPINDLE_OVR_FINE_MINUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_MINUS); break;
// case CMD_SPINDLE_OVR_STOP: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_STOP); break;
// case CMD_COOLANT_FLOOD_OVR_TOGGLE: system_set_exec_accessory_override_flag(EXEC_COOLANT_FLOOD_OVR_TOGGLE); break;
// #ifdef ENABLE_M7
// case CMD_COOLANT_MIST_OVR_TOGGLE: system_set_exec_accessory_override_flag(EXEC_COOLANT_MIST_OVR_TOGGLE); break;
// #endif
// }
// // Throw away any unfound extended-ASCII character by not passing it to the serial buffer.
// } else { // Write character to buffer
// next_head = serial_rx_buffer_head + 1;
// if (next_head == RX_RING_BUFFER) { next_head = 0; }
//
// // Write data to buffer unless it is full.
// if (next_head != serial_rx_buffer_tail) {
// serial_rx_buffer[serial_rx_buffer_head] = data;
// serial_rx_buffer_head = next_head;
// }
// }
// }
//}
//
void ecmc_add_char_to_buffer(char data)
{
printf("Adding %c to buffer %s\n",data,serial_rx_buffer);
//uint8_t data = UDR0;
uint8_t next_head;
// Pick off realtime command characters directly from the serial stream. These characters are
// not passed into the main buffer, but these set system state flag bits for realtime execution.
switch (data) {
case CMD_RESET: mc_reset(); break; // Call motion control reset routine.
case CMD_STATUS_REPORT: system_set_exec_state_flag(EXEC_STATUS_REPORT); break; // Set as true
case CMD_CYCLE_START: system_set_exec_state_flag(EXEC_CYCLE_START); break; // Set as true
case CMD_FEED_HOLD: system_set_exec_state_flag(EXEC_FEED_HOLD); break; // Set as true
default :
if (data > 0x7F) { // Real-time control characters are extended ACSII only.
switch(data) {
case CMD_SAFETY_DOOR: system_set_exec_state_flag(EXEC_SAFETY_DOOR); break; // Set as true
case CMD_JOG_CANCEL:
if (sys.state & STATE_JOG) { // Block all other states from invoking motion cancel.
system_set_exec_state_flag(EXEC_MOTION_CANCEL);
}
break;
#ifdef DEBUG
case CMD_DEBUG_REPORT: {uint8_t sreg = SREG; cli(); bit_true(sys_rt_exec_debug,EXEC_DEBUG_REPORT); SREG = sreg;} break;
#endif
case CMD_FEED_OVR_RESET: system_set_exec_motion_override_flag(EXEC_FEED_OVR_RESET); break;
case CMD_FEED_OVR_COARSE_PLUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_COARSE_PLUS); break;
case CMD_FEED_OVR_COARSE_MINUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_COARSE_MINUS); break;
case CMD_FEED_OVR_FINE_PLUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_FINE_PLUS); break;
case CMD_FEED_OVR_FINE_MINUS: system_set_exec_motion_override_flag(EXEC_FEED_OVR_FINE_MINUS); break;
case CMD_RAPID_OVR_RESET: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_RESET); break;
case CMD_RAPID_OVR_MEDIUM: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_MEDIUM); break;
case CMD_RAPID_OVR_LOW: system_set_exec_motion_override_flag(EXEC_RAPID_OVR_LOW); break;
case CMD_SPINDLE_OVR_RESET: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_RESET); break;
case CMD_SPINDLE_OVR_COARSE_PLUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_PLUS); break;
case CMD_SPINDLE_OVR_COARSE_MINUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_COARSE_MINUS); break;
case CMD_SPINDLE_OVR_FINE_PLUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_PLUS); break;
case CMD_SPINDLE_OVR_FINE_MINUS: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_FINE_MINUS); break;
case CMD_SPINDLE_OVR_STOP: system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_STOP); break;
case CMD_COOLANT_FLOOD_OVR_TOGGLE: system_set_exec_accessory_override_flag(EXEC_COOLANT_FLOOD_OVR_TOGGLE); break;
#ifdef ENABLE_M7
case CMD_COOLANT_MIST_OVR_TOGGLE: system_set_exec_accessory_override_flag(EXEC_COOLANT_MIST_OVR_TOGGLE); break;
#endif
}
// Throw away any unfound extended-ASCII character by not passing it to the serial buffer.
} else { // Write character to buffer
next_head = serial_rx_buffer_head + 1;
if (next_head == RX_RING_BUFFER) { next_head = 0; }
// Write data to buffer unless it is full.
if (next_head != serial_rx_buffer_tail) {
serial_rx_buffer[serial_rx_buffer_head] = data;
serial_rx_buffer_head = next_head;
}
}
}
}
// write direct to serial buffer
void ecmc_write_command_serial(char* line) {
for(int i=0; i<strlen(line);i++) {
ecmc_add_char_to_buffer(line[i]);
}
}
void serial_reset_read_buffer()
{

View File

@@ -37,6 +37,8 @@
#define SERIAL_NO_DATA 0xff
void ecmc_write_command_serial(char* line);
void serial_init();
// Writes one byte to the TX serial buffer. Called by main program.

View File

@@ -221,20 +221,24 @@ static bool stepperInterruptEnable = 0;
are shown and defined in the above illustration.
*/
void ecmc_grbl_main_thread();
void ecmc_grbl_main_rt_thread();
pthread_t tid;
void *ecmc_dummy_thread(void *ptr) {
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
while (stepperInterruptEnable) {
for(int i=0; i< 30;i++) {
ecmc_grbl_main_thread();
ecmc_grbl_main_rt_thread();
}
printf("%s:%s:%d Positions(x,y,x)=%d,%d,%d..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
sleep(0.001);
}
}
void ecmc_start_dummy_thread()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
int i = 0;
int err;
@@ -251,6 +255,8 @@ void ecmc_start_dummy_thread()
// enabled. Startup init and limits call this function but shouldn't start the cycle.
void st_wake_up()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// Enable stepper drivers.
//if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }
//else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }
@@ -281,6 +287,8 @@ void st_wake_up()
// Stepper shutdown
void st_go_idle()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
stepperInterruptEnable = 0;
// Disable Stepper Driver Interrupt. Allow Stepper Port Reset Interrupt to finish, if active.
@@ -352,8 +360,9 @@ void st_go_idle()
// with probing and homing cycles that require true real-time positions.
// call from plugin execute
void ecmc_grbl_main_thread()
void ecmc_grbl_main_rt_thread()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
if (busy) { return; } // The busy-flag is used to avoid reentering this interrupt
@@ -551,6 +560,8 @@ void ecmc_grbl_main_thread()
// Generates the step and direction port invert masks used in the Stepper Interrupt Driver.
void st_generate_step_dir_invert_masks()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
uint8_t idx;
step_port_invert_mask = 0;
dir_port_invert_mask = 0;
@@ -571,6 +582,8 @@ void st_generate_step_dir_invert_masks()
// Reset and clear stepper subsystem variables
void st_reset()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// Initialize stepper driver idle state.
st_go_idle();
@@ -602,6 +615,8 @@ void st_reset()
// Initialize and start the stepper motor subsystem
void stepper_init()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// Configure step and direction interface pins
// STEP_DDR |= STEP_MASK;
// STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
@@ -634,6 +649,8 @@ void stepper_init()
// Called by planner_recalculate() when the executing block is updated by the new plan.
void st_update_plan_block_parameters()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
if (pl_block != NULL) { // Ignore if at start of a new block.
prep.recalculate_flag |= PREP_FLAG_RECALCULATE;
pl_block->entry_speed_sqr = prep.current_speed*prep.current_speed; // Update entry speed.
@@ -645,6 +662,8 @@ void st_update_plan_block_parameters()
// Increments the step segment buffer block data ring buffer.
static uint8_t st_next_block_index(uint8_t block_index)
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
block_index++;
if ( block_index == (SEGMENT_BUFFER_SIZE-1) ) { return(0); }
return(block_index);
@@ -704,6 +723,8 @@ static uint8_t st_next_block_index(uint8_t block_index)
*/
void st_prep_buffer()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
// Block step prep buffer, while in a suspend state and there is no suspend motion to execute.
if (bit_istrue(sys.step_control,STEP_CONTROL_END_MOTION)) { return; }
@@ -1125,6 +1146,8 @@ void st_prep_buffer()
// divided by the ACCELERATION TICKS PER SECOND in seconds.
float st_get_realtime_rate()
{
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
if (sys.state & (STATE_CYCLE | STATE_HOMING | STATE_HOLD | STATE_JOG | STATE_SAFETY_DOOR)){
return prep.current_speed;
}

View File

@@ -129,14 +129,15 @@ void system_execute_startup(char *line)
// since there are motions already stored in the buffer. However, this 'lag' should not
// be an issue, since these commands are not typically used during a cycle.
//Nice!!
uint8_t system_execute_line(char *line)
{
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
printf("\n%s:%s:%d:###################\n",__FILE__,__FUNCTION__,__LINE__);
printf("%s:%s:%d:%s\n",__FILE__,__FUNCTION__,__LINE__,line);
uint8_t char_counter = 1;
uint8_t helper_var = 0; // Helper variable
float parameter, value;
printf("system_execute_line switch line[1]=%c\n",line[char_counter]);
switch( line[char_counter] ) {
case 0 : report_grbl_help(); break;
case 'J' : // Jogging
@@ -262,8 +263,11 @@ uint8_t system_execute_line(char *line)
// No break. Continues into default: to read remaining command characters.
}
default : // Storing setting methods [IDLE/ALARM]
printf("1\n");
if(!read_float(line, &char_counter, &parameter)) { return(STATUS_BAD_NUMBER_FORMAT); }
printf("2 parameter %f\n",parameter);
if(line[char_counter++] != '=') { return(STATUS_INVALID_STATEMENT); }
printf("3\n");
if (helper_var) { // Store startup line
// Prepare sending gcode block to gcode parser by shifting all characters
helper_var = char_counter; // Set helper variable as counter to start of gcode block