Extend simulation runtime coverage and kinematics support

This commit is contained in:
2026-08-21 10:57:10 +08:00
parent 554b72dae8
commit 2ef2d82db3
71 changed files with 24232 additions and 1867 deletions

View File

@@ -16,6 +16,12 @@ enum sim_kinematics_result {
SIM_KIN_ERR_SINGULAR = -704,
SIM_KIN_ERR_UNKNOWN_TYPE = -705,
SIM_KIN_ERR_UNSUPPORTED = -706,
SIM_KIN_ERR_INVALID_MODE = -707,
SIM_KIN_ERR_MISSING_MODULE = -708,
SIM_KIN_ERR_SWITCH_INTERRUPTED = -709,
SIM_KIN_ERR_ABI_VERSION = -710,
SIM_KIN_ERR_CAPABILITY = -711,
SIM_KIN_ERR_DYNAMIC_MODULE = -712,
};
enum sim_kinematics_type {
@@ -60,6 +66,34 @@ enum sim_kinematics_mode {
#define SIM_KIN_MAX_JOINTS 9u
#define SIM_KIN_GENHEX_STRUTS 6u
#define SIM_KIN_PENTA_STRUTS 5u
#define SIM_KIN_SWITCH_MAX_TYPES 3u
#define SIM_KIN_USER_ABI_VERSION 1u
#define SIM_KIN_USER_CAP_FORWARD UINT32_C(1)
#define SIM_KIN_USER_CAP_INVERSE UINT32_C(2)
#define SIM_KIN_USER_CAP_STATIC UINT32_C(4)
#define SIM_KIN_USER_NAME_CAPACITY 32u
#define SIM_KIN_REGISTRY_ABI_VERSION 1u
#define SIM_KIN_REGISTRY_NAME_CAPACITY 32u
#define SIM_KIN_CAP_FORWARD UINT32_C(1)
#define SIM_KIN_CAP_INVERSE UINT32_C(2)
#define SIM_KIN_CAP_IDENTITY UINT32_C(4)
#define SIM_KIN_CAP_ITERATIVE UINT32_C(8)
#define SIM_KIN_CAP_SWITCHABLE UINT32_C(16)
#define SIM_KIN_CAP_EXTRA_JOINTS UINT32_C(32)
#define SIM_KIN_CAP_DUPLICATE_COORDINATES UINT32_C(64)
#define SIM_KIN_PARAM_MAPPING UINT64_C(1)
#define SIM_KIN_PARAM_LIMITS UINT64_C(2)
#define SIM_KIN_PARAM_OFFSETS UINT64_C(4)
#define SIM_KIN_PARAM_TOOL UINT64_C(8)
#define SIM_KIN_PARAM_PIVOT UINT64_C(16)
#define SIM_KIN_PARAM_GEOMETRY UINT64_C(32)
#define SIM_KIN_PARAM_DH UINT64_C(64)
#define SIM_KIN_PARAM_SOLVER UINT64_C(128)
enum sim_kinematics_user_implementation {
SIM_KIN_USER_IDENTITY = 1,
SIM_KIN_USER_GENSER = 2,
};
typedef struct sim_kinematics_config {
int type;
@@ -149,6 +183,52 @@ typedef struct sim_kinematics_result_info {
uint32_t branch_id;
} sim_kinematics_result_info;
/* A bounded switchkins container matching LinuxCNC's three registered
* kinematics slots. The container owns switching state, not the modules. */
typedef struct sim_kinematics_switch {
sim_kinematics *modules[SIM_KIN_SWITCH_MAX_TYPES];
uint8_t registered[SIM_KIN_SWITCH_MAX_TYPES];
uint8_t fwd_iterates_mask;
uint8_t switching;
int active_mode;
int pending_mode;
uint32_t generation;
uint32_t switch_count;
uint32_t abort_count;
sim_posemath_pose last_pose[SIM_KIN_SWITCH_MAX_TYPES];
uint8_t have_last_pose[SIM_KIN_SWITCH_MAX_TYPES];
} sim_kinematics_switch;
/* User kinematics are selected from implementations already linked into the
* WASM module. No function pointers, host paths, or dynamic libraries enter
* this descriptor. */
typedef struct sim_kinematics_user_descriptor {
uint32_t abi_version;
uint32_t capabilities;
int implementation;
char name[SIM_KIN_USER_NAME_CAPACITY];
sim_kinematics_config config;
} sim_kinematics_user_descriptor;
typedef struct sim_kinematics_user {
sim_kinematics_user_descriptor descriptor;
sim_kinematics module;
uint32_t initialized;
uint32_t forward_calls;
uint32_t inverse_calls;
} sim_kinematics_user;
typedef struct sim_kinematics_capability {
uint32_t abi_version;
int type;
char name[SIM_KIN_REGISTRY_NAME_CAPACITY];
char required_coordinates[16];
uint32_t min_joints;
uint32_t max_joints;
uint32_t capabilities;
uint64_t parameter_mask;
} sim_kinematics_capability;
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);
@@ -167,6 +247,60 @@ uint64_t sim_kinematics_state_hash(const sim_kinematics *kinematics,
const double *joints, uint32_t joint_count,
const sim_posemath_pose *pose);
int sim_kinematics_switch_init(sim_kinematics_switch *switcher, int default_mode,
uint8_t fwd_iterates_mask);
int sim_kinematics_switch_register(sim_kinematics_switch *switcher, int mode,
sim_kinematics *module, uint8_t fwd_iterates);
int sim_kinematics_switch_begin(sim_kinematics_switch *switcher, int mode);
int sim_kinematics_switch_abort(sim_kinematics_switch *switcher);
int sim_kinematics_switch_commit(sim_kinematics_switch *switcher, double *joints,
uint32_t joint_count, sim_posemath_pose *pose,
sim_kinematics_result_info *info);
int sim_kinematics_switch_select(sim_kinematics_switch *switcher, int mode,
double *joints, uint32_t joint_count,
sim_posemath_pose *pose,
sim_kinematics_result_info *info);
int sim_kinematics_switch_forward(sim_kinematics_switch *switcher,
const double *joints, uint32_t joint_count,
sim_posemath_pose *pose,
sim_kinematics_result_info *info);
int sim_kinematics_switch_inverse(sim_kinematics_switch *switcher,
const sim_posemath_pose *pose, double *joints,
uint32_t joint_count,
sim_kinematics_result_info *info);
int sim_kinematics_switch_active(const sim_kinematics_switch *switcher);
uint64_t sim_kinematics_switch_state_hash(const sim_kinematics_switch *switcher,
const double *joints, uint32_t joint_count,
const sim_posemath_pose *pose);
int sim_kinematics_user_init(sim_kinematics_user *user,
const sim_kinematics_user_descriptor *descriptor);
int sim_kinematics_user_bind_switch(sim_kinematics_user *user,
sim_kinematics_switch *switcher, int mode,
uint8_t fwd_iterates);
int sim_kinematics_user_forward(sim_kinematics_user *user, const double *joints,
uint32_t joint_count, sim_posemath_pose *pose,
sim_kinematics_result_info *info);
int sim_kinematics_user_inverse(sim_kinematics_user *user,
const sim_posemath_pose *pose, double *joints,
uint32_t joint_count,
sim_kinematics_result_info *info);
int sim_kinematics_user_reject_dynamic(const char *module_path);
uint64_t sim_kinematics_user_state_hash(const sim_kinematics_user *user,
const double *joints, uint32_t joint_count,
const sim_posemath_pose *pose);
uint32_t sim_kinematics_registry_count(void);
int sim_kinematics_registry_get(uint32_t index,
sim_kinematics_capability *capability);
int sim_kinematics_registry_find(const char *name,
sim_kinematics_capability *capability);
int sim_kinematics_registry_require(const char *name, uint32_t capabilities,
uint64_t parameter_mask,
sim_kinematics_capability *capability);
int sim_kinematics_registry_validate_config(const char *name,
const sim_kinematics_config *config,
sim_kinematics_capability *capability);
uint64_t sim_kinematics_registry_state_hash(void);
#ifdef __cplusplus
}
#endif