Implement WebAssembly runtime and kinematics coverage
This commit is contained in:
@@ -49,6 +49,10 @@ int32_t sim_hal_get_pin(const char *name, sim_hal_value *out);
|
||||
int32_t sim_hal_connect(const char *source, const char *target);
|
||||
int32_t sim_hal_register_thread(const char *name, uint32_t period_ticks);
|
||||
int32_t sim_hal_register_function(const char *thread, const char *name);
|
||||
/* Register the static LinuxCNC corexy_by_hal component and its servo pins. */
|
||||
int32_t sim_hal_register_corexy_by_hal(const char *component, const char *thread);
|
||||
/* Execute one deterministic CoreXY command/feedback transform immediately. */
|
||||
int32_t sim_hal_corexy_transform(const char *component);
|
||||
int32_t sim_hal_set_function_failure(const char *name, uint32_t fail);
|
||||
int32_t sim_hal_step(uint32_t ticks);
|
||||
uint32_t sim_hal_tick(void);
|
||||
|
||||
74
wasm-core/include/sim_interpreter.h
Normal file
74
wasm-core/include/sim_interpreter.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef LINUXCNC_WEB_WASM_SIM_INTERPRETER_H
|
||||
#define LINUXCNC_WEB_WASM_SIM_INTERPRETER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum sim_interpreter_result {
|
||||
SIM_INTERP_OK = 0,
|
||||
SIM_INTERP_ERR_ARGUMENT = -500,
|
||||
SIM_INTERP_ERR_NONFINITE = -501,
|
||||
SIM_INTERP_ERR_SYNTAX = -502,
|
||||
SIM_INTERP_ERR_RANGE = -503,
|
||||
SIM_INTERP_ERR_UNKNOWN_CODE = -504,
|
||||
SIM_INTERP_ERR_STATE = -505,
|
||||
SIM_INTERP_ERR_BUFFER = -506,
|
||||
};
|
||||
|
||||
enum sim_interpreter_units {
|
||||
SIM_INTERP_UNITS_INCH = 20,
|
||||
SIM_INTERP_UNITS_MM = 21,
|
||||
};
|
||||
|
||||
enum sim_interpreter_distance_mode {
|
||||
SIM_INTERP_ABSOLUTE = 90,
|
||||
SIM_INTERP_INCREMENTAL = 91,
|
||||
};
|
||||
|
||||
typedef struct sim_interpreter_state {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
double a;
|
||||
double b;
|
||||
double c;
|
||||
double u;
|
||||
double v;
|
||||
double w;
|
||||
double feed;
|
||||
double speed;
|
||||
uint32_t line;
|
||||
int units;
|
||||
int distance_mode;
|
||||
int plane;
|
||||
int motion_mode;
|
||||
int spindle_mode;
|
||||
int program_end;
|
||||
int status;
|
||||
} sim_interpreter_state;
|
||||
|
||||
#define SIM_INTERPRETER_CANONICAL_CAPACITY 512u
|
||||
|
||||
typedef struct sim_interpreter {
|
||||
sim_interpreter_state state;
|
||||
uint64_t block_hash;
|
||||
uint32_t canonical_length;
|
||||
char canonical[SIM_INTERPRETER_CANONICAL_CAPACITY];
|
||||
} sim_interpreter;
|
||||
|
||||
int sim_interpreter_init(sim_interpreter *interpreter);
|
||||
int sim_interpreter_reset(sim_interpreter *interpreter);
|
||||
int sim_interpreter_execute(sim_interpreter *interpreter, const char *block, uint32_t length);
|
||||
int sim_interpreter_read_state(const sim_interpreter *interpreter, sim_interpreter_state *state);
|
||||
uint32_t sim_interpreter_canonical(const sim_interpreter *interpreter, char *output, uint32_t capacity);
|
||||
uint64_t sim_interpreter_state_hash(const sim_interpreter *interpreter);
|
||||
uint64_t sim_interpreter_block_hash(const sim_interpreter *interpreter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
174
wasm-core/include/sim_kinematics.h
Normal file
174
wasm-core/include/sim_kinematics.h
Normal file
@@ -0,0 +1,174 @@
|
||||
#ifndef LINUXCNC_WEB_WASM_SIM_KINEMATICS_H
|
||||
#define LINUXCNC_WEB_WASM_SIM_KINEMATICS_H
|
||||
|
||||
#include "sim_posemath.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum sim_kinematics_result {
|
||||
SIM_KIN_OK = 0,
|
||||
SIM_KIN_ERR_ARGUMENT = -700,
|
||||
SIM_KIN_ERR_NONFINITE = -701,
|
||||
SIM_KIN_ERR_RANGE = -702,
|
||||
SIM_KIN_ERR_CONFIGURATION = -703,
|
||||
SIM_KIN_ERR_SINGULAR = -704,
|
||||
SIM_KIN_ERR_UNKNOWN_TYPE = -705,
|
||||
SIM_KIN_ERR_UNSUPPORTED = -706,
|
||||
};
|
||||
|
||||
enum sim_kinematics_type {
|
||||
SIM_KIN_TRIVKINS = 1,
|
||||
SIM_KIN_XYZAC_TRT = 2,
|
||||
SIM_KIN_XYZBC_TRT = 3,
|
||||
SIM_KIN_XYZBCW = 4,
|
||||
SIM_KIN_COREXY = 5,
|
||||
SIM_KIN_ROSE = 6,
|
||||
SIM_KIN_MAXKINS = 7,
|
||||
SIM_KIN_ROTATEKINS = 8,
|
||||
SIM_KIN_5AXISKINS = 9,
|
||||
SIM_KIN_SCARA = 10,
|
||||
SIM_KIN_PUMA = 11,
|
||||
SIM_KIN_SCORBOT = 12,
|
||||
SIM_KIN_GENSER = 13,
|
||||
SIM_KIN_LINEAR_DELTA = 14,
|
||||
SIM_KIN_ROTARY_DELTA = 15,
|
||||
SIM_KIN_TRIPOD = 16,
|
||||
SIM_KIN_GENHEX = 17,
|
||||
SIM_KIN_PENTAPOD = 18,
|
||||
};
|
||||
|
||||
/* LinuxCNC kinematics mode semantics. Zero means the module default. */
|
||||
enum sim_kinematics_mode {
|
||||
SIM_KIN_MODE_DEFAULT = 0,
|
||||
SIM_KIN_MODE_IDENTITY = 1,
|
||||
SIM_KIN_MODE_FORWARD_ONLY = 2,
|
||||
SIM_KIN_MODE_INVERSE_ONLY = 3,
|
||||
SIM_KIN_MODE_BOTH = 4,
|
||||
};
|
||||
|
||||
/* Delta mechanisms expose the two analytic roots through the flags fields.
|
||||
* The default (zero) is LinuxCNC's lower/platform root; bit zero selects the
|
||||
* alternate root for callers that need an explicit branch comparison. */
|
||||
#define SIM_KIN_DELTA_ALTERNATE_ROOT UINT64_C(1)
|
||||
/* Tripod forward flags select the below-base solution when set. */
|
||||
#define SIM_KIN_TRIPOD_BELOW_ROOT UINT64_C(1)
|
||||
/* Genhex forward flags select the alternate (below-platform) initial seed. */
|
||||
#define SIM_KIN_GENHEX_ALTERNATE_SEED UINT64_C(2)
|
||||
|
||||
#define SIM_KIN_MAX_JOINTS 9u
|
||||
#define SIM_KIN_GENHEX_STRUTS 6u
|
||||
#define SIM_KIN_PENTA_STRUTS 5u
|
||||
|
||||
typedef struct sim_kinematics_config {
|
||||
int type;
|
||||
int mode;
|
||||
uint32_t joint_count;
|
||||
/* Total configured joints and the prefix owned by kinematics. */
|
||||
uint32_t kinematics_joint_count;
|
||||
uint32_t extra_joint_count;
|
||||
char coordinates[16];
|
||||
double x_rot_point;
|
||||
double y_rot_point;
|
||||
double z_rot_point;
|
||||
double x_offset;
|
||||
double y_offset;
|
||||
double z_offset;
|
||||
double tool_offset;
|
||||
double pivot_length;
|
||||
double scara_d1;
|
||||
double scara_d2;
|
||||
double scara_d3;
|
||||
double scara_d4;
|
||||
double scara_d5;
|
||||
double scara_d6;
|
||||
double puma_a2;
|
||||
double puma_a3;
|
||||
double puma_d3;
|
||||
double puma_d4;
|
||||
double puma_d6;
|
||||
uint32_t dh_joint_count;
|
||||
double dh_a[SIM_KIN_MAX_JOINTS];
|
||||
double dh_alpha[SIM_KIN_MAX_JOINTS];
|
||||
double dh_d[SIM_KIN_MAX_JOINTS];
|
||||
double delta_radius;
|
||||
double delta_rod_length;
|
||||
double rotary_platform_radius;
|
||||
double rotary_thigh_length;
|
||||
double rotary_shin_length;
|
||||
double rotary_foot_radius;
|
||||
double tripod_bx;
|
||||
double tripod_cx;
|
||||
double tripod_cy;
|
||||
double genhex_base[SIM_KIN_GENHEX_STRUTS][3];
|
||||
double genhex_platform[SIM_KIN_GENHEX_STRUTS][3];
|
||||
double genhex_base_axis[SIM_KIN_GENHEX_STRUTS][3];
|
||||
double genhex_platform_axis[SIM_KIN_GENHEX_STRUTS][3];
|
||||
double genhex_screw_lead;
|
||||
double genhex_tool_offset;
|
||||
double genhex_spindle_offset;
|
||||
double genhex_max_error;
|
||||
double genhex_convergence_tolerance;
|
||||
uint32_t genhex_iteration_limit;
|
||||
double genhex_initial_pose[6];
|
||||
double penta_base[SIM_KIN_PENTA_STRUTS][3];
|
||||
double penta_effector_radius[SIM_KIN_PENTA_STRUTS];
|
||||
double penta_effector_z[SIM_KIN_PENTA_STRUTS];
|
||||
double penta_tool_offset;
|
||||
double penta_max_error;
|
||||
double penta_convergence_tolerance;
|
||||
uint32_t penta_iteration_limit;
|
||||
double penta_initial_pose[5];
|
||||
uint32_t max_iterations;
|
||||
double convergence_tolerance;
|
||||
uint8_t limit_enabled[SIM_KIN_MAX_JOINTS];
|
||||
double joint_min[SIM_KIN_MAX_JOINTS];
|
||||
double joint_max[SIM_KIN_MAX_JOINTS];
|
||||
} sim_kinematics_config;
|
||||
|
||||
typedef struct sim_kinematics {
|
||||
sim_kinematics_config config;
|
||||
int axis_joint[SIM_KIN_MAX_JOINTS];
|
||||
uint32_t configured;
|
||||
uint64_t forward_flags;
|
||||
uint64_t inverse_flags;
|
||||
sim_posemath_pose last_pose;
|
||||
double last_residual;
|
||||
uint32_t last_iterations;
|
||||
uint32_t branch_id;
|
||||
int32_t revolution_count;
|
||||
uint32_t previous_quadrant;
|
||||
} sim_kinematics;
|
||||
|
||||
typedef struct sim_kinematics_result_info {
|
||||
uint64_t forward_flags;
|
||||
uint64_t inverse_flags;
|
||||
double residual;
|
||||
uint32_t iterations;
|
||||
uint32_t branch_id;
|
||||
} sim_kinematics_result_info;
|
||||
|
||||
int sim_kinematics_init(sim_kinematics *kinematics, const sim_kinematics_config *config);
|
||||
int sim_kinematics_forward(const sim_kinematics *kinematics, const double *joints,
|
||||
uint32_t joint_count, sim_posemath_pose *pose);
|
||||
int sim_kinematics_forward_ex(const sim_kinematics *kinematics, const double *joints,
|
||||
uint32_t joint_count, uint64_t inverse_flags,
|
||||
sim_posemath_pose *pose, sim_kinematics_result_info *info);
|
||||
int sim_kinematics_inverse(sim_kinematics *kinematics, const sim_posemath_pose *pose,
|
||||
double *joints, uint32_t joint_count);
|
||||
int sim_kinematics_inverse_ex(sim_kinematics *kinematics, const sim_posemath_pose *pose,
|
||||
uint32_t joint_count, uint64_t forward_flags,
|
||||
double *joints, sim_kinematics_result_info *info);
|
||||
int sim_kinematics_home(const sim_kinematics *kinematics, double *joints, uint32_t joint_count,
|
||||
sim_posemath_pose *pose);
|
||||
int sim_kinematics_validate_pose(const sim_posemath_pose *pose);
|
||||
uint64_t sim_kinematics_state_hash(const sim_kinematics *kinematics,
|
||||
const double *joints, uint32_t joint_count,
|
||||
const sim_posemath_pose *pose);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
66
wasm-core/include/sim_motion_queue.h
Normal file
66
wasm-core/include/sim_motion_queue.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef LINUXCNC_WEB_WASM_SIM_MOTION_QUEUE_H
|
||||
#define LINUXCNC_WEB_WASM_SIM_MOTION_QUEUE_H
|
||||
|
||||
#include "sim_posemath.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum sim_motion_result {
|
||||
SIM_MOTION_OK = 0,
|
||||
SIM_MOTION_ERR_ARGUMENT = -600,
|
||||
SIM_MOTION_ERR_NONFINITE = -601,
|
||||
SIM_MOTION_ERR_RANGE = -602,
|
||||
SIM_MOTION_ERR_GEOMETRY = -603,
|
||||
SIM_MOTION_ERR_MOTION_TYPE = -604,
|
||||
SIM_MOTION_ERR_STATE = -605,
|
||||
SIM_MOTION_ERR_CAPACITY = -606,
|
||||
SIM_MOTION_ERR_BUFFER = -607,
|
||||
};
|
||||
|
||||
#define SIM_MOTION_QUEUE_CAPACITY 64u
|
||||
|
||||
typedef struct sim_motion_command {
|
||||
sim_posemath_segment segment;
|
||||
uint32_t id;
|
||||
uint32_t tag;
|
||||
} sim_motion_command;
|
||||
|
||||
typedef struct sim_motion_state {
|
||||
sim_posemath_pose position;
|
||||
double velocity;
|
||||
double progress;
|
||||
uint32_t tick;
|
||||
uint32_t queue_depth;
|
||||
uint32_t active_id;
|
||||
uint32_t active_tag;
|
||||
int motion_type;
|
||||
int status;
|
||||
} sim_motion_state;
|
||||
|
||||
typedef struct sim_motion_queue {
|
||||
sim_motion_command commands[SIM_MOTION_QUEUE_CAPACITY];
|
||||
uint32_t head;
|
||||
uint32_t count;
|
||||
uint32_t next_id;
|
||||
uint32_t tick;
|
||||
double cycle_time;
|
||||
double velocity_limit;
|
||||
sim_motion_state state;
|
||||
} sim_motion_queue;
|
||||
|
||||
int sim_motion_init(sim_motion_queue *queue, double cycle_time, double velocity_limit);
|
||||
int sim_motion_reset(sim_motion_queue *queue);
|
||||
int sim_motion_enqueue(sim_motion_queue *queue, const sim_motion_command *command, uint32_t *id_out);
|
||||
int sim_motion_step(sim_motion_queue *queue);
|
||||
int sim_motion_read_state(const sim_motion_queue *queue, sim_motion_state *state);
|
||||
uint32_t sim_motion_queue_depth(const sim_motion_queue *queue);
|
||||
uint64_t sim_motion_state_hash(const sim_motion_queue *queue);
|
||||
uint32_t sim_motion_canonical(const sim_motion_queue *queue, char *output, uint32_t capacity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -5,12 +5,25 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum sim_posemath_result {
|
||||
SIM_POSEMATH_OK = 0,
|
||||
SIM_POSEMATH_ERR_ARGUMENT = -400,
|
||||
SIM_POSEMATH_ERR_NONFINITE = -401,
|
||||
SIM_POSEMATH_ERR_DEGENERATE = -402,
|
||||
SIM_POSEMATH_ERR_RANGE = -403,
|
||||
SIM_POSEMATH_ERR_MOTION_TYPE = -404,
|
||||
SIM_POSEMATH_ERR_STATE = -405,
|
||||
SIM_POSEMATH_ERR_CAPACITY = -406,
|
||||
};
|
||||
|
||||
/* Values match LinuxCNC's tc_motion_type_t. */
|
||||
enum sim_posemath_motion_type {
|
||||
SIM_POSEMATH_LINEAR = 1,
|
||||
SIM_POSEMATH_CIRCULAR = 2,
|
||||
SIM_POSEMATH_RIGID_TAP = 3,
|
||||
SIM_POSEMATH_SPHERICAL = 4,
|
||||
};
|
||||
|
||||
typedef struct sim_posemath_cartesian {
|
||||
@@ -19,11 +32,77 @@ typedef struct sim_posemath_cartesian {
|
||||
double z;
|
||||
} sim_posemath_cartesian;
|
||||
|
||||
typedef struct sim_posemath_pose {
|
||||
sim_posemath_cartesian tran;
|
||||
double a;
|
||||
double b;
|
||||
double c;
|
||||
double u;
|
||||
double v;
|
||||
double w;
|
||||
} sim_posemath_pose;
|
||||
|
||||
typedef struct sim_posemath_segment {
|
||||
sim_posemath_pose start;
|
||||
sim_posemath_pose end;
|
||||
sim_posemath_cartesian center;
|
||||
sim_posemath_cartesian normal;
|
||||
double velocity;
|
||||
double acceleration;
|
||||
int motion_type;
|
||||
int turn;
|
||||
} sim_posemath_segment;
|
||||
|
||||
typedef struct sim_tp_state {
|
||||
sim_posemath_pose position;
|
||||
double velocity;
|
||||
double progress;
|
||||
uint32_t tick;
|
||||
uint32_t queue_depth;
|
||||
uint32_t active_id;
|
||||
int motion_type;
|
||||
int status;
|
||||
} sim_tp_state;
|
||||
|
||||
#define SIM_TP_QUEUE_CAPACITY 32u
|
||||
|
||||
typedef struct sim_tp {
|
||||
sim_posemath_segment queue[SIM_TP_QUEUE_CAPACITY];
|
||||
uint32_t ids[SIM_TP_QUEUE_CAPACITY];
|
||||
uint32_t head;
|
||||
uint32_t count;
|
||||
uint32_t next_id;
|
||||
uint32_t active_id;
|
||||
uint32_t tick;
|
||||
double cycle_time;
|
||||
double velocity_limit;
|
||||
double acceleration_limit;
|
||||
double progress;
|
||||
double current_velocity;
|
||||
sim_posemath_pose position;
|
||||
int motion_type;
|
||||
int status;
|
||||
} sim_tp;
|
||||
|
||||
int sim_posemath_normalize(const sim_posemath_cartesian *input, sim_posemath_cartesian *output);
|
||||
int sim_posemath_dot(const sim_posemath_cartesian *left, const sim_posemath_cartesian *right, double *output);
|
||||
int sim_posemath_line_point(const sim_posemath_cartesian *start, const sim_posemath_cartesian *end,
|
||||
double fraction, sim_posemath_cartesian *output);
|
||||
int sim_posemath_is_finite(const sim_posemath_cartesian *value);
|
||||
int sim_posemath_pose_is_finite(const sim_posemath_pose *value);
|
||||
int sim_posemath_pose_line_point(const sim_posemath_pose *start, const sim_posemath_pose *end,
|
||||
double fraction, sim_posemath_pose *output);
|
||||
int sim_posemath_segment_validate(const sim_posemath_segment *segment);
|
||||
int sim_posemath_segment_point(const sim_posemath_segment *segment, double fraction,
|
||||
sim_posemath_pose *output);
|
||||
uint64_t sim_posemath_hash_state(const sim_tp_state *state);
|
||||
|
||||
int sim_tp_init(sim_tp *tp, double cycle_time, double velocity_limit, double acceleration_limit);
|
||||
int sim_tp_reset(sim_tp *tp);
|
||||
int sim_tp_enqueue(sim_tp *tp, const sim_posemath_segment *segment, uint32_t *id_out);
|
||||
int sim_tp_step(sim_tp *tp);
|
||||
int sim_tp_read_state(const sim_tp *tp, sim_tp_state *state);
|
||||
uint64_t sim_tp_state_hash(const sim_tp *tp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user