Unblock native XYZAC TP oracle
This commit is contained in:
@@ -85,6 +85,10 @@ static int code_is(double value, int integer_code) {
|
||||
return isfinite(value) && fabs(value - (double)integer_code) <= 1e-12;
|
||||
}
|
||||
|
||||
static int code_is_value(double value, double expected) {
|
||||
return isfinite(value) && fabs(value - expected) <= 1e-12;
|
||||
}
|
||||
|
||||
static int axis_index(char letter) {
|
||||
switch (letter) {
|
||||
case 'X': return 0; case 'Y': return 1; case 'Z': return 2;
|
||||
@@ -346,7 +350,7 @@ static int apply_g(sim_interpreter_state *state, interpreter_meta *meta, double
|
||||
if (code_is(code, 40) || code_is(code, 41) || code_is(code, 42)) { if (++groups[4] > 1) return SIM_INTERP_ERR_STATE; if (meta) meta->cutter_comp = (int)code; return SIM_INTERP_OK; }
|
||||
if (code_is(code, 43) || code_is(code, 49)) { if (++groups[5] > 1) return SIM_INTERP_ERR_STATE; if (meta && code_is(code, 49)) meta->tool_length = 0.0; return SIM_INTERP_OK; }
|
||||
if (code_is(code, 80) || (code >= 81.0 && code <= 89.0 && floor(code) == code)) { if (meta) meta->cycle_mode = (int)code; return SIM_INTERP_OK; }
|
||||
if (code_is(code, 64)) return SIM_INTERP_OK;
|
||||
if (code_is(code, 61) || code_is_value(code, 61.1) || code_is(code, 64)) { if (++groups[7] > 1) return SIM_INTERP_ERR_STATE; return SIM_INTERP_OK; }
|
||||
if (code_is(code, 54) || code_is(code, 55) || code_is(code, 56) || code_is(code, 57) || code_is(code, 58) || code_is(code, 59)) { if (meta) meta->coordinate_system = (int)code - 53; return SIM_INTERP_OK; }
|
||||
if (code_is(code, 53)) return SIM_INTERP_OK;
|
||||
if (code_is(code, 10)) return SIM_INTERP_OK;
|
||||
@@ -444,7 +448,7 @@ int sim_interpreter_init(sim_interpreter *interpreter) { return sim_interpreter_
|
||||
|
||||
int sim_interpreter_execute(sim_interpreter *interpreter, const char *block, uint32_t length) {
|
||||
sim_interpreter_state previous; sim_interpreter_state next; interpreter_meta *meta; expression_parser parser; const char *end;
|
||||
int groups[7] = {0}, seen_axis[9] = {0}, seen_feed = 0, seen_speed = 0, seen_line = 0, seen_p = 0, seen_r = 0, seen_l = 0, seen_g10 = 0, seen_g53 = 0, result = SIM_INTERP_OK;
|
||||
int groups[8] = {0}, seen_axis[9] = {0}, seen_feed = 0, seen_speed = 0, seen_line = 0, seen_p = 0, seen_r = 0, seen_l = 0, seen_g10 = 0, seen_g53 = 0, result = SIM_INTERP_OK;
|
||||
int seen_center[3] = {0};
|
||||
double axis_values[9] = {0}, center_values[3] = {0}, feed_value = 0.0, speed_value = 0.0, p_value = 0.0, r_value = 0.0, l_value = 0.0;
|
||||
if (interpreter == NULL || block == NULL || length == 0) return SIM_INTERP_ERR_ARGUMENT;
|
||||
|
||||
@@ -253,6 +253,45 @@ static int switch_mcode(const char *block, uint32_t length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_motion_control(sim_program *program, const char *block, uint32_t length) {
|
||||
const char *cursor = block;
|
||||
const char *end = block + length;
|
||||
int active = 0;
|
||||
double path = 0.0;
|
||||
double naive = 0.0;
|
||||
while (cursor < end) {
|
||||
char letter;
|
||||
char *number_end;
|
||||
double value;
|
||||
while (cursor < end && isspace((unsigned char)*cursor)) ++cursor;
|
||||
if (cursor >= end || *cursor == ';') break;
|
||||
if (*cursor == '(') { while (cursor < end && *cursor++ != ')') {} continue; }
|
||||
if (!isalpha((unsigned char)*cursor)) { ++cursor; continue; }
|
||||
letter = (char)toupper((unsigned char)*cursor++);
|
||||
value = strtod(cursor, &number_end);
|
||||
if (number_end == cursor) continue;
|
||||
cursor = number_end;
|
||||
if (letter == 'G') {
|
||||
if (fabs(value - 61.0) <= 1e-12) active = SIM_PROGRAM_MOTION_EXACT_PATH;
|
||||
else if (fabs(value - 61.1) <= 1e-12) active = SIM_PROGRAM_MOTION_EXACT_STOP;
|
||||
else if (fabs(value - 64.0) <= 1e-12) active = SIM_PROGRAM_MOTION_CONTINUOUS;
|
||||
else active = 0;
|
||||
if (active != 0 || fabs(value - 64.0) <= 1e-12) {
|
||||
program->motion_control_mode = active;
|
||||
path = 0.0;
|
||||
naive = 0.0;
|
||||
}
|
||||
} else if (active == SIM_PROGRAM_MOTION_CONTINUOUS && (letter == 'P' || letter == 'Q')) {
|
||||
if (!isfinite(value) || value < 0.0) return SIM_PROGRAM_ERR_RANGE;
|
||||
if (letter == 'P') path = value;
|
||||
else naive = value;
|
||||
program->path_tolerance = path;
|
||||
program->naive_cam_tolerance = naive;
|
||||
}
|
||||
}
|
||||
return SIM_PROGRAM_OK;
|
||||
}
|
||||
|
||||
static void reset_runtime(sim_program *program) {
|
||||
sim_interpreter_reset(&program->interpreter);
|
||||
program->source_length = 0;
|
||||
@@ -268,6 +307,9 @@ static void reset_runtime(sim_program *program) {
|
||||
program->has_control = 0;
|
||||
program->control_code = 0;
|
||||
program->rapid_velocity = 35.0;
|
||||
program->motion_control_mode = SIM_PROGRAM_MOTION_CONTINUOUS;
|
||||
program->path_tolerance = 0.0;
|
||||
program->naive_cam_tolerance = 0.0;
|
||||
memset(&program->motion, 0, sizeof(program->motion));
|
||||
memset(program->subroutines, 0, sizeof(program->subroutines));
|
||||
memset(program->call_stack, 0, sizeof(program->call_stack));
|
||||
@@ -356,6 +398,8 @@ int32_t sim_program_execute_block(sim_program *program, const char *block, uint3
|
||||
int result;
|
||||
if (program == NULL || block == NULL || length == 0) return SIM_PROGRAM_ERR_ARGUMENT;
|
||||
if (control_line(block)) return SIM_PROGRAM_ERR_CONTROL;
|
||||
result = parse_motion_control(program, block, length);
|
||||
if (result != SIM_PROGRAM_OK) return result;
|
||||
program->has_control = 0;
|
||||
program->control_code = switch_mcode(block, length);
|
||||
if (program->control_code != 0) program->has_control = 1;
|
||||
@@ -449,8 +493,8 @@ uint32_t sim_program_canonical(const sim_program *program, char *output, uint32_
|
||||
int written;
|
||||
if (program == NULL) return 0;
|
||||
written = snprintf(destination, destination_capacity,
|
||||
"{\"call_depth\":%u,\"control_code\":%d,\"current_line\":%u,\"error_line\":%u,\"feed\":%.17g,\"has_control\":%u,\"has_motion\":%u,\"last_error\":%d,\"line_count\":%u,\"main_line_count\":%u,\"motion_mode\":%d,\"plane\":%d,\"rapid_velocity\":%.17g,\"schema\":\"sim_program.v1\",\"speed\":%.17g,\"spindle_mode\":%d,\"status\":%u,\"subroutine_count\":%u,\"source_length\":%u,\"units\":%d,\"distance_mode\":%d,\"interpreter_state_hash\":\"%llu\"}",
|
||||
program->call_depth, program->control_code, program->current_line, program->error_line, program->interpreter.state.feed, program->has_control, program->has_motion, program->last_error, program->line_count, program->main_line_count, program->interpreter.state.motion_mode, program->interpreter.state.plane, program->rapid_velocity, program->interpreter.state.speed, program->interpreter.state.spindle_mode, program->status, program->subroutine_count, program->source_length, program->interpreter.state.units, program->interpreter.state.distance_mode,
|
||||
"{\"call_depth\":%u,\"control_code\":%d,\"current_line\":%u,\"error_line\":%u,\"feed\":%.17g,\"has_control\":%u,\"has_motion\":%u,\"last_error\":%d,\"line_count\":%u,\"main_line_count\":%u,\"motion_control_mode\":%d,\"path_tolerance\":%.17g,\"naive_cam_tolerance\":%.17g,\"motion_mode\":%d,\"plane\":%d,\"rapid_velocity\":%.17g,\"schema\":\"sim_program.v1\",\"speed\":%.17g,\"spindle_mode\":%d,\"status\":%u,\"subroutine_count\":%u,\"source_length\":%u,\"units\":%d,\"distance_mode\":%d,\"interpreter_state_hash\":\"%llu\"}",
|
||||
program->call_depth, program->control_code, program->current_line, program->error_line, program->interpreter.state.feed, program->has_control, program->has_motion, program->last_error, program->line_count, program->main_line_count, program->motion_control_mode, program->path_tolerance, program->naive_cam_tolerance, program->interpreter.state.motion_mode, program->interpreter.state.plane, program->rapid_velocity, program->interpreter.state.speed, program->interpreter.state.spindle_mode, program->status, program->subroutine_count, program->source_length, program->interpreter.state.units, program->interpreter.state.distance_mode,
|
||||
(unsigned long long)sim_interpreter_state_hash(&program->interpreter));
|
||||
return written < 0 ? 0 : (uint32_t)written + 1u;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user