Align AXIS control flow and fix pause and program rendering
Document source UI gates, explicit native live-plot clearing, and remaining parity boundaries. Fix pause/resume transport continuity, repeated stepping, coordinate previews, and spindle override state. Optimize large program snapshots and rendering, and cover the control flows with native Tcl, WASM, and browser checks. Validation: 22 native tests and source/browser checks pass. Worker/App regression: 113 of 123 pass; 10 pre-existing failures remain documented with no new failures.
This commit is contained in:
@@ -310,6 +310,7 @@ static void reset_runtime(sim_program *program) {
|
||||
program->motion_control_mode = SIM_PROGRAM_MOTION_CONTINUOUS;
|
||||
program->path_tolerance = 0.0;
|
||||
program->naive_cam_tolerance = 0.0;
|
||||
program->pause_from = SIM_PROGRAM_RUNNING;
|
||||
memset(&program->motion, 0, sizeof(program->motion));
|
||||
memset(program->subroutines, 0, sizeof(program->subroutines));
|
||||
memset(program->call_stack, 0, sizeof(program->call_stack));
|
||||
@@ -344,9 +345,21 @@ void sim_program_destroy(sim_program *program) {
|
||||
}
|
||||
|
||||
int32_t sim_program_load(sim_program *program, const char *source, uint32_t length) {
|
||||
sim_coordinate_context coordinates;
|
||||
sim_interpreter_state modal_state;
|
||||
if (program == NULL || source == NULL) return SIM_PROGRAM_ERR_ARGUMENT;
|
||||
if (length == 0 || length > SIM_PROGRAM_MAX_SOURCE_BYTES) return SIM_PROGRAM_ERR_RANGE;
|
||||
modal_state = program->interpreter.state;
|
||||
if (sim_interpreter_get_coordinates(&program->interpreter, &coordinates) != SIM_INTERP_OK) return SIM_PROGRAM_ERR_INTERPRETER;
|
||||
if (sim_program_reset(program) != SIM_PROGRAM_OK) return SIM_PROGRAM_ERR_INTERPRETER;
|
||||
if (sim_interpreter_set_coordinates(&program->interpreter, &coordinates) != SIM_INTERP_OK) return SIM_PROGRAM_ERR_INTERPRETER;
|
||||
program->interpreter.state.units = modal_state.units;
|
||||
program->interpreter.state.distance_mode = modal_state.distance_mode;
|
||||
program->interpreter.state.plane = modal_state.plane;
|
||||
program->interpreter.state.motion_mode = modal_state.motion_mode;
|
||||
program->interpreter.state.feed = modal_state.feed;
|
||||
program->interpreter.state.speed = modal_state.speed;
|
||||
program->interpreter.state.spindle_mode = modal_state.spindle_mode;
|
||||
if (append_source(program, source, length) != SIM_PROGRAM_OK) return SIM_PROGRAM_ERR_RANGE;
|
||||
program->main_line_count = program->line_count;
|
||||
program->status = SIM_PROGRAM_LOADED;
|
||||
@@ -370,20 +383,10 @@ int32_t sim_program_set_rapid_velocity(sim_program *program, double velocity) {
|
||||
int32_t sim_program_set_position(sim_program *program, const sim_posemath_pose *position) {
|
||||
const double *values;
|
||||
size_t index;
|
||||
if (program == NULL || position == NULL || program->status == SIM_PROGRAM_IDLE) return SIM_PROGRAM_ERR_ARGUMENT;
|
||||
if (program == NULL || position == NULL) return SIM_PROGRAM_ERR_ARGUMENT;
|
||||
values = &position->tran.x;
|
||||
for (index = 0; index < 9; ++index) if (!isfinite(values[index])) return SIM_PROGRAM_ERR_RANGE;
|
||||
program->interpreter.state.x = position->tran.x;
|
||||
program->interpreter.state.y = position->tran.y;
|
||||
program->interpreter.state.z = position->tran.z;
|
||||
program->interpreter.state.a = position->a;
|
||||
program->interpreter.state.b = position->b;
|
||||
program->interpreter.state.c = position->c;
|
||||
program->interpreter.state.u = position->u;
|
||||
program->interpreter.state.v = position->v;
|
||||
program->interpreter.state.w = position->w;
|
||||
program->interpreter.state.status = SIM_INTERP_OK;
|
||||
return SIM_PROGRAM_OK;
|
||||
return sim_interpreter_sync_position(&program->interpreter, position) == SIM_INTERP_OK ? SIM_PROGRAM_OK : SIM_PROGRAM_ERR_INTERPRETER;
|
||||
}
|
||||
|
||||
int32_t sim_program_start(sim_program *program) {
|
||||
@@ -412,14 +415,15 @@ int32_t sim_program_start(sim_program *program) {
|
||||
}
|
||||
|
||||
int32_t sim_program_pause(sim_program *program) {
|
||||
if (program == NULL || program->status != SIM_PROGRAM_RUNNING) return SIM_PROGRAM_ERR_STATE;
|
||||
if (program == NULL || (program->status != SIM_PROGRAM_RUNNING && program->status != SIM_PROGRAM_COMPLETED && program->status != SIM_PROGRAM_LOADED)) return SIM_PROGRAM_ERR_STATE;
|
||||
program->pause_from = program->status;
|
||||
program->status = SIM_PROGRAM_PAUSED;
|
||||
return SIM_PROGRAM_OK;
|
||||
}
|
||||
|
||||
int32_t sim_program_resume(sim_program *program) {
|
||||
if (program == NULL || program->status != SIM_PROGRAM_PAUSED) return SIM_PROGRAM_ERR_STATE;
|
||||
program->status = SIM_PROGRAM_RUNNING;
|
||||
program->status = program->pause_from;
|
||||
return SIM_PROGRAM_OK;
|
||||
}
|
||||
|
||||
@@ -494,8 +498,11 @@ int32_t sim_program_step(sim_program *program) {
|
||||
}
|
||||
|
||||
int32_t sim_program_seek(sim_program *program, uint32_t line) {
|
||||
sim_coordinate_context coordinates;
|
||||
if (program == NULL || line > program->line_count) return SIM_PROGRAM_ERR_RANGE;
|
||||
if (sim_interpreter_get_coordinates(&program->interpreter, &coordinates) != SIM_INTERP_OK) return SIM_PROGRAM_ERR_INTERPRETER;
|
||||
if (sim_interpreter_reset(&program->interpreter) != SIM_INTERP_OK) return SIM_PROGRAM_ERR_INTERPRETER;
|
||||
if (sim_interpreter_set_coordinates(&program->interpreter, &coordinates) != SIM_INTERP_OK) return SIM_PROGRAM_ERR_INTERPRETER;
|
||||
program->current_line = 0; program->status = SIM_PROGRAM_PAUSED; program->has_motion = 0;
|
||||
while (program->current_line < line) {
|
||||
int result = sim_program_step(program);
|
||||
@@ -528,11 +535,22 @@ uint32_t sim_program_canonical(const sim_program *program, char *output, uint32_
|
||||
char *destination = output == NULL ? discard : output;
|
||||
uint32_t destination_capacity = output == NULL ? 1 : capacity;
|
||||
int written;
|
||||
sim_coordinate_context coordinates;
|
||||
char coordinate_json[3072];
|
||||
size_t used = 0;
|
||||
if (program == NULL) return 0;
|
||||
if (sim_interpreter_get_coordinates(&program->interpreter, &coordinates) != SIM_INTERP_OK) return 0;
|
||||
used += (size_t)snprintf(coordinate_json + used, sizeof(coordinate_json) - used, "{\"system\":%d,\"offsets\":[", coordinates.system);
|
||||
for (int system = 0; system < 9; ++system) {
|
||||
used += (size_t)snprintf(coordinate_json + used, sizeof(coordinate_json) - used, "%s[", system ? "," : "");
|
||||
for (int axis = 0; axis < 9; ++axis) used += (size_t)snprintf(coordinate_json + used, sizeof(coordinate_json) - used, "%s%.17g", axis ? "," : "", coordinates.offsets[system][axis]);
|
||||
used += (size_t)snprintf(coordinate_json + used, sizeof(coordinate_json) - used, "]");
|
||||
}
|
||||
(void)snprintf(coordinate_json + used, sizeof(coordinate_json) - used, "]}");
|
||||
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_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\"}",
|
||||
"{\"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\",\"coordinate_context\":%s,\"pause_from\":%u}",
|
||||
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));
|
||||
(unsigned long long)sim_interpreter_state_hash(&program->interpreter), coordinate_json, program->pause_from);
|
||||
return written < 0 ? 0 : (uint32_t)written + 1u;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user