155 lines
4.4 KiB
C
155 lines
4.4 KiB
C
#ifndef LINUXCNC_WEB_WASM_SIM_IO_H
|
|
#define LINUXCNC_WEB_WASM_SIM_IO_H
|
|
|
|
#include "sim_posemath.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define SIM_IO_MAX_SPINDLES 8u
|
|
#define SIM_IO_MAX_TOOLS 1001u
|
|
|
|
enum sim_io_result {
|
|
SIM_IO_OK = 0,
|
|
SIM_IO_ERR_ARGUMENT = -900,
|
|
SIM_IO_ERR_RANGE = -901,
|
|
SIM_IO_ERR_STATE = -902,
|
|
SIM_IO_ERR_NOT_READY = -903,
|
|
SIM_IO_ERR_ESTOP = -904,
|
|
SIM_IO_ERR_FAULT = -905,
|
|
SIM_IO_ERR_LIMIT = -906,
|
|
SIM_IO_ERR_NONFINITE = -907,
|
|
SIM_IO_ERR_PIN = -908,
|
|
SIM_IO_ERR_CAPACITY = -909,
|
|
SIM_IO_ERR_BUSY = -910,
|
|
SIM_IO_ERR_PROBE = -911,
|
|
SIM_IO_ERR_TIMEOUT = -912,
|
|
SIM_IO_ERR_RECOVERY = -913,
|
|
};
|
|
|
|
enum sim_io_tool_state {
|
|
SIM_IO_TOOL_IDLE = 0,
|
|
SIM_IO_TOOL_PREPARING = 1,
|
|
SIM_IO_TOOL_PREPARED = 2,
|
|
SIM_IO_TOOL_CHANGING = 3,
|
|
SIM_IO_TOOL_READY = 4,
|
|
SIM_IO_TOOL_ABORTED = 5,
|
|
SIM_IO_TOOL_FAULT = 6,
|
|
};
|
|
|
|
enum sim_io_probe_status {
|
|
SIM_IO_PROBE_IDLE = 0,
|
|
SIM_IO_PROBE_ARMED = 1,
|
|
SIM_IO_PROBE_TRIPPED = 2,
|
|
SIM_IO_PROBE_FAILED = 3,
|
|
};
|
|
|
|
typedef struct sim_io_spindle_state {
|
|
uint32_t registered;
|
|
uint32_t enabled;
|
|
uint32_t inhibit;
|
|
uint32_t amp_fault;
|
|
uint32_t at_speed;
|
|
uint32_t brake;
|
|
uint32_t forward;
|
|
uint32_t reverse;
|
|
uint32_t index_enable;
|
|
uint32_t orient;
|
|
uint32_t locked;
|
|
uint32_t is_oriented;
|
|
int32_t orient_mode;
|
|
int32_t orient_fault;
|
|
double command_rpm;
|
|
double speed_rpm;
|
|
double max_rpm;
|
|
double accel_rpm_s;
|
|
double tolerance_rpm;
|
|
double orient_angle;
|
|
double revs;
|
|
uint32_t tick;
|
|
} sim_io_spindle_state;
|
|
|
|
typedef struct sim_io_probe_state {
|
|
uint32_t input;
|
|
uint32_t probe_type;
|
|
uint32_t state;
|
|
uint32_t tripped;
|
|
uint32_t tick;
|
|
sim_posemath_pose position;
|
|
} sim_io_probe_state;
|
|
|
|
typedef struct sim_io_state {
|
|
uint32_t ready;
|
|
uint32_t estop;
|
|
uint32_t fault;
|
|
int32_t fault_reason;
|
|
uint32_t tick;
|
|
uint32_t recovery_epoch;
|
|
uint32_t spindle_count;
|
|
uint32_t tool_capacity;
|
|
sim_io_spindle_state spindles[SIM_IO_MAX_SPINDLES];
|
|
uint32_t tool_state;
|
|
int32_t current_tool;
|
|
int32_t prepared_tool;
|
|
int32_t prepared_pocket;
|
|
uint32_t tool_prepare;
|
|
uint32_t tool_prepared;
|
|
uint32_t tool_change;
|
|
uint32_t tool_changed;
|
|
uint32_t toolchanger_fault;
|
|
int32_t toolchanger_reason;
|
|
sim_io_probe_state probe;
|
|
int32_t last_error;
|
|
} sim_io_state;
|
|
|
|
typedef struct sim_io {
|
|
sim_io_state state;
|
|
double cycle_time;
|
|
uint32_t pins_registered;
|
|
} sim_io;
|
|
|
|
uint32_t sim_io_size(void);
|
|
|
|
int sim_io_init(sim_io *io, uint32_t spindle_count, uint32_t tool_capacity,
|
|
double cycle_time, double spindle_accel_rpm_s,
|
|
double spindle_tolerance_rpm);
|
|
int sim_io_reset(sim_io *io);
|
|
int sim_io_register_pins(sim_io *io);
|
|
int sim_io_spindle_command(sim_io *io, uint32_t spindle, double rpm,
|
|
uint32_t enabled);
|
|
int sim_io_spindle_set_inhibit(sim_io *io, uint32_t spindle, uint32_t inhibit);
|
|
int sim_io_spindle_set_fault(sim_io *io, uint32_t spindle, uint32_t fault);
|
|
int sim_io_spindle_set_index_enable(sim_io *io, uint32_t spindle, uint32_t enable);
|
|
int sim_io_spindle_set_feedback(sim_io *io, uint32_t spindle, double rpm);
|
|
int sim_io_spindle_orient(sim_io *io, uint32_t spindle, double angle,
|
|
int32_t mode);
|
|
int sim_io_spindle_set_oriented(sim_io *io, uint32_t spindle,
|
|
uint32_t oriented, int32_t fault);
|
|
int sim_io_tool_prepare(sim_io *io, int32_t tool, int32_t pocket);
|
|
int sim_io_tool_set_prepared(sim_io *io, uint32_t prepared);
|
|
int sim_io_tool_change(sim_io *io);
|
|
int sim_io_tool_set_changed(sim_io *io, uint32_t changed);
|
|
int sim_io_tool_abort(sim_io *io, int32_t reason);
|
|
int sim_io_tool_set_fault(sim_io *io, uint32_t fault, int32_t reason);
|
|
int sim_io_tool_clear_fault(sim_io *io);
|
|
int sim_io_probe_arm(sim_io *io, uint32_t probe_type);
|
|
int sim_io_probe_update(sim_io *io, const sim_posemath_pose *pose,
|
|
uint32_t input);
|
|
int sim_io_probe_disarm(sim_io *io);
|
|
int sim_io_set_estop(sim_io *io, uint32_t estop);
|
|
int sim_io_set_power(sim_io *io, uint32_t active);
|
|
int sim_io_recover(sim_io *io);
|
|
int sim_io_step(sim_io *io, uint32_t ticks);
|
|
int sim_io_read_state(const sim_io *io, sim_io_state *state);
|
|
uint64_t sim_io_state_hash(const sim_io *io);
|
|
uint32_t sim_io_canonical(const sim_io *io, char *output, uint32_t capacity);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|