Skip to content

Commit

Permalink
fix remapping for good (or so they say)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Haberler committed Oct 28, 2011
1 parent cf0e6a6 commit dfa5bd3
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 58 deletions.
11 changes: 9 additions & 2 deletions configs/sim/g8812.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,18 @@ ON_ABORT_COMMAND=o<on_abort>call
# File containing interpreter variables
PARAMETER_FILE = sim_mm.var

#
# define custom G and M codes
# syntax: GCODE=<number>,<argument spec>
# argument spec:
#
# syntax: GCODE=<number>,<modal group>,<argument spec>
#
# argument spec: 0-n characters of the class [A-KMNP-Za-kmnp-z]
# an uppercase letter for each required parameter 'word'
# a lowercase letter for each optional parameter 'word'
# superfluous words present in the current block which are neither required nor optional cause an error message
#
# an 'S' requires speed > 0
# an 'F' requires feed > 0
[CUSTOM]
# currently supported modal group: 1
GCODE=88.1,1,XYZrF
Expand All @@ -148,6 +154,7 @@ MCODE=77,7,PQ
MCODE=78,8,PQ
MCODE=79,9,PQ
MCODE=80,10,PQ
MCODE=250,10,xyzpq
# creates error message: no modal group
#MCODE=76
#MCODE=76,10,xy
Expand Down
4 changes: 2 additions & 2 deletions nc_files/g881.ngc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
o<g881> sub
(debug, in g881); x=[#1] y=[#2] z=[#3] r=[#4])

;m75

o<g881_havex> if [EXISTS[#<x>]]
(debug, X param set: #<x>)
o<g881_havex> endif
Expand All @@ -27,6 +25,8 @@ o<g881_haver> if [EXISTS[#<r>]]
(debug, R param set: #<r>)
o<g881_haver> endif

m250

o<g881> endsub [1]
m2

2 changes: 1 addition & 1 deletion nc_files/g882.ngc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
o<g882> sub
(debug, in g882 x=[#1] y=[#2] z=[#3] r=[#4], next is M75)
m75pq
m75p1q47
o<g882> endsub [1]
m2

6 changes: 3 additions & 3 deletions nc_files/t3.ngc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;f123s350m6m4m8m49g18g21g94t1
m75p2q47
g88.1X1Y2Z3f200
m75p2q47
;m75p2q47
;g88.1X1Y2Z3f200
;m75p2q47
;g88.1X1Y2Z3f200
;g88.1X1Y2Z3f200
m2
21 changes: 12 additions & 9 deletions src/emc/rs274ngc/interp_convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,9 @@ int Interp::restore_context(setup_pointer settings,

if (settings->active_g_codes[5] != settings->sub_context[from_level].saved_g_codes[5]) {
snprintf(cmd,sizeof(cmd), "G%d",settings->sub_context[from_level].saved_g_codes[5]/10);
ERP(execute(cmd));
status = execute(cmd);
if (status != INTERP_OK)
ERP(status);
memset(cmd, 0, LINELEN);
}
gen_settings((double *)settings->active_settings, (double *)settings->sub_context[from_level].saved_settings,cmd);
Expand All @@ -2809,7 +2811,8 @@ int Interp::restore_context(setup_pointer settings,

if (strlen(cmd) > 0) {
status = execute(cmd);
ERP(status);
if (status != INTERP_OK)
ERP(status);
write_g_codes((block_pointer) NULL, settings);
write_m_codes((block_pointer) NULL, settings);
write_settings(settings);
Expand All @@ -2823,7 +2826,7 @@ int Interp::restore_context(setup_pointer settings,
}

// handler epilogues
int Interp::finish_m6_command(setup_pointer settings)
int Interp::finish_m6_command(setup_pointer settings, int remap)
{
// if M6_COMMAND 'return'ed or 'endsub'ed a #<_value> > 0,
// commit the tool change
Expand All @@ -2839,11 +2842,11 @@ int Interp::finish_m6_command(setup_pointer settings)
CANON_ERROR("M6 failed (%f)", settings->return_value);
SEND_HANDLER_ABORT(round_to_int(settings->return_value));
}
remap_finished(status);
remap_finished(remap);
return (status);
}

int Interp::finish_m61_command(setup_pointer settings)
int Interp::finish_m61_command(setup_pointer settings,int remap)
{
int status = INTERP_OK;

Expand All @@ -2861,8 +2864,8 @@ int Interp::finish_m61_command(setup_pointer settings)
CANON_ERROR("M61 failed (%f)",settings->return_value);
SEND_HANDLER_ABORT(round_to_int(settings->return_value));
}
remap_finished(status);
return INTERP_OK;
remap_finished(remap);
return status;
}


Expand Down Expand Up @@ -2907,9 +2910,9 @@ const char *Interp::usercode_argspec(setup_pointer settings,int code,
}

// handler epilogue for remapped user m + g codes
int Interp::finish_user_command(setup_pointer settings)
int Interp::finish_user_command(setup_pointer settings,int remap)
{
remap_finished(INTERP_OK);
remap_finished(remap);
return INTERP_OK;
}

Expand Down
10 changes: 6 additions & 4 deletions src/emc/rs274ngc/interp_execute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int Interp::report_error(setup_pointer settings,int status,const char *text)
}

// Tx epiplogue - executed past T_COMMAND
int Interp::finish_t_command(setup_pointer settings)
int Interp::finish_t_command(setup_pointer settings,int remap)
{
int status = INTERP_OK;

Expand All @@ -241,16 +241,17 @@ int Interp::finish_t_command(setup_pointer settings)
CANON_ERROR("T<tool> - prepare failed (%f)", settings->return_value);
SEND_HANDLER_ABORT(round_to_int(settings->return_value));
}
remap_finished(status);
return(INTERP_OK);
remap_finished(remap);
return(status);
}


// common code for T_COMMAND, M6_COMMAND, ON_ABORT handlers
int Interp::execute_handler(setup_pointer settings, const char *cmd,
int (Interp::*prolog)(setup_pointer settings,
int user_data),
int (Interp::*epilog)(setup_pointer settings),
int (Interp::*epilog)(setup_pointer settings,
int remap_op),
int remap_op,
int user_data
)
Expand All @@ -268,6 +269,7 @@ int Interp::execute_handler(setup_pointer settings, const char *cmd,
// it's essentially a hidden param to the call

settings->epilog_hook = epilog;
settings->epilog_userdata = remap_op;

// this hook might call a function to enrich subroutine local params
settings->prolog_hook = prolog;
Expand Down
12 changes: 9 additions & 3 deletions src/emc/rs274ngc/interp_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ typedef struct context_struct {
int (Interp::*prolog)(setup_pointer settings, int user_data);
int userdata; // memoized parameter to prolog function
// if set, the following handler is executed on endsub/return
int (Interp::*epilog)(setup_pointer settings);
int (Interp::*epilog)(setup_pointer settings, int remap);
int epilog_arg; // memoized parameter to epilog function

}context;

Expand Down Expand Up @@ -565,9 +566,11 @@ typedef struct setup_struct
int (Interp::*prolog_hook)(setup_pointer settings, int user_data);
int prolog_userdata; // memoized parameter to prolog function
// if set on a sub call, the following function is executed on endsub/return
int (Interp::*epilog_hook)(setup_pointer settings);
int (Interp::*epilog_hook)(setup_pointer settings,int remap);
int epilog_userdata; // memoized parameter to epilog function

const char *t_command, *m6_command,*m61_command,*on_abort_command;
int executing_remap; // we are in a Tx/M6/M61 replacement procedure
//int pending_remap; // we are in a Tx/M6/M61 replacement procedure
// see enum remap_op in rs274ngc_interp.hh for values
// gcodes are 0..999
// mcodes are at offset MCODE_OFFSET
Expand Down Expand Up @@ -612,6 +615,7 @@ macros totally crash-proof. If the function call stack is deeper than
_setup.stack[_setup.stack_index][STACK_ENTRY_LEN-1] = 0; \
_setup.stack_index++; \
_setup.stack[_setup.stack_index][0] = 0; \
signal_error(INTERP_ERROR); \
return INTERP_ERROR; \
} while(0)

Expand All @@ -623,6 +627,7 @@ macros totally crash-proof. If the function call stack is deeper than
_setup.stack[_setup.stack_index][STACK_ENTRY_LEN-1] = 0; \
_setup.stack_index++; \
_setup.stack[_setup.stack_index][0] = 0; \
signal_error(error_code); \
return error_code; \
} while(0)

Expand All @@ -636,6 +641,7 @@ macros totally crash-proof. If the function call stack is deeper than
_setup.stack_index++; \
_setup.stack[_setup.stack_index][0] = 0; \
} \
signal_error(error_code); \
return error_code; \
} while(0)

Expand Down
6 changes: 5 additions & 1 deletion src/emc/rs274ngc/interp_o_word.cc
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ int Interp::convert_control_functions( /* ARGUMENTS */
// we have an epilog function. Execute it.
if (settings->sub_context[settings->call_level+1].epilog) {
fprintf(stderr,"---- return/endsub: calling epilogue\n");
int status = (*this.*settings->sub_context[settings->call_level+1].epilog)(settings);
int status = (*this.*settings->sub_context[settings->call_level+1].epilog)(settings,
settings->sub_context[settings->call_level+1].epilog_arg
);
if (status > INTERP_MIN_ERROR)
ERS("epilogue failed"); //FIXME
}
Expand Down Expand Up @@ -589,6 +591,8 @@ int Interp::convert_control_functions( /* ARGUMENTS */
settings->sub_context[settings->call_level].epilog =
settings->epilog_hook;
settings->epilog_hook = NULL; // mark as consumed
settings->sub_context[settings->call_level].epilog_arg =
settings->epilog_userdata;

// remember a prolog function
// and memoized userdata in current call frame
Expand Down
12 changes: 6 additions & 6 deletions src/emc/rs274ngc/rs274ngc_interp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,21 @@ private:
setup_pointer settings, /* pointer to machine settings */
const char *cmd,
int (Interp::*prolog)(setup_pointer settings, int user_data) = NULL,
int (Interp::*epilog)(setup_pointer settings) = NULL,
int (Interp::*epilog)(setup_pointer settings, int remap) = NULL,
int remap_op = 0, // really NO_REMAP but rather keep internal
int user_data = 0
);

int signal_error(int code);
// step through parsed block and find first active remapped item
int next_remapping(block_pointer block, setup_pointer settings);

int report_error(setup_pointer settings,int status,const char *text);

// epilog routines called post G-code handler procedure
int finish_t_command(setup_pointer settings);
int finish_m6_command(setup_pointer settings);
int finish_m61_command(setup_pointer settings);
int finish_user_command(setup_pointer settings);
int finish_t_command(setup_pointer settings,int remap);
int finish_m6_command(setup_pointer settings,int remap);
int finish_m61_command(setup_pointer settings,int remap);
int finish_user_command(setup_pointer settings, int remap);

// user-defined g/mcode support
int define_gcode(double gcode, int modal_group,const char *argspec);
Expand Down
Loading

0 comments on commit dfa5bd3

Please sign in to comment.