#define STRUCTS_IN_SHMEM
#ifndef MOTION_H
#define MOTION_H
#include "posemath.h"
#include "emcpos.h"
#include "cubic.h"
#include "emcmotcfg.h"
#include "kinematics.h"
#include "simple_tp.h"
#include "rtapi_limits.h"
#include <stdarg.h>
#include "rtapi_bool.h"
#define MOTION_INVALID_ID INT_MIN
#define MOTION_ID_VALID(x) ((x) != MOTION_INVALID_ID)
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _EMC_TELEOP_DATA {
EmcPose currentVel;
EmcPose currentAccel;
EmcPose desiredVel;
EmcPose desiredAccel;
} EMC_TELEOP_DATA;
typedef enum {
EMCMOT_ABORT = 1,
EMCMOT_ENABLE,
EMCMOT_DISABLE,
EMCMOT_PAUSE,
EMCMOT_REVERSE,
EMCMOT_FORWARD,
EMCMOT_RESUME,
EMCMOT_STEP,
EMCMOT_FREE,
EMCMOT_COORD,
EMCMOT_TELEOP,
EMCMOT_SPINDLE_SCALE,
EMCMOT_SS_ENABLE,
EMCMOT_FEED_SCALE,
EMCMOT_RAPID_SCALE,
EMCMOT_FS_ENABLE,
EMCMOT_FH_ENABLE,
EMCMOT_AF_ENABLE,
EMCMOT_OVERRIDE_LIMITS,
EMCMOT_SET_LINE,
EMCMOT_SET_CIRCLE,
EMCMOT_SET_TELEOP_VECTOR,
EMCMOT_CLEAR_PROBE_FLAGS,
EMCMOT_PROBE,
EMCMOT_RIGID_TAP,
EMCMOT_SET_VEL,
EMCMOT_SET_VEL_LIMIT,
EMCMOT_SET_ACC,
EMCMOT_SET_TERM_COND,
EMCMOT_SET_NUM_JOINTS,
EMCMOT_SET_NUM_SPINDLES,
EMCMOT_SET_WORLD_HOME,
EMCMOT_SET_DEBUG,
EMCMOT_SET_DOUT,
EMCMOT_SET_AOUT,
EMCMOT_SET_SPINDLESYNC,
EMCMOT_SPINDLE_ON,
EMCMOT_SPINDLE_OFF,
EMCMOT_SPINDLE_INCREASE,
EMCMOT_SPINDLE_DECREASE,
EMCMOT_SPINDLE_BRAKE_ENGAGE,
EMCMOT_SPINDLE_BRAKE_RELEASE,
EMCMOT_SPINDLE_ORIENT,
EMCMOT_SET_OFFSET,
EMCMOT_SET_MAX_FEED_OVERRIDE,
EMCMOT_SETUP_ARC_BLENDS,
EMCMOT_SET_PROBE_ERR_INHIBIT,
EMCMOT_ENABLE_WATCHDOG,
EMCMOT_DISABLE_WATCHDOG,
EMCMOT_JOG_CONT,
EMCMOT_JOG_INCR,
EMCMOT_JOG_ABS,
EMCMOT_JOINT_ABORT,
EMCMOT_JOINT_ACTIVATE,
EMCMOT_JOINT_DEACTIVATE,
EMCMOT_JOINT_ENABLE_AMPLIFIER,
EMCMOT_JOINT_DISABLE_AMPLIFIER,
EMCMOT_JOINT_HOME,
EMCMOT_JOINT_UNHOME,
EMCMOT_SET_JOINT_POSITION_LIMITS,
EMCMOT_SET_JOINT_BACKLASH,
EMCMOT_SET_JOINT_MIN_FERROR,
EMCMOT_SET_JOINT_MAX_FERROR,
EMCMOT_SET_JOINT_VEL_LIMIT,
EMCMOT_SET_JOINT_ACC_LIMIT,
EMCMOT_SET_JOINT_HOMING_PARAMS,
EMCMOT_UPDATE_JOINT_HOMING_PARAMS,
EMCMOT_SET_JOINT_MOTOR_OFFSET,
EMCMOT_SET_JOINT_COMP,
EMCMOT_SET_AXIS_POSITION_LIMITS,
EMCMOT_SET_AXIS_VEL_LIMIT,
EMCMOT_SET_AXIS_ACC_LIMIT,
EMCMOT_SET_AXIS_LOCKING_JOINT,
} cmd_code_t;
typedef enum {
EMCMOT_COMMAND_OK = 0,
EMCMOT_COMMAND_UNKNOWN_COMMAND,
EMCMOT_COMMAND_INVALID_COMMAND,
EMCMOT_COMMAND_INVALID_PARAMS,
EMCMOT_COMMAND_BAD_EXEC
} cmd_status_t;
#define EMCMOT_TERM_COND_STOP 1
#define EMCMOT_TERM_COND_BLEND 2
#define EMCMOT_TERM_COND_TANGENT 3
typedef struct emcmot_command_t {
unsigned char head;
cmd_code_t command;
int commandNum;
double motor_offset;
double maxLimit;
double minLimit;
EmcPose pos;
PmCartesian center;
PmCartesian normal;
int turn;
double vel;
double ini_maxvel;
int motion_type;
double spindlesync;
double acc;
double backlash;
int id;
int termCond;
double tolerance;
int joint;
int axis;
int spindle;
double scale;
double offset;
double home;
double home_final_vel;
double search_vel;
double latch_vel;
int flags;
int home_sequence;
int volatile_home;
double minFerror;
double maxFerror;
int wdWait;
int debug;
unsigned char now, out, start, end;
unsigned char mode;
double comp_nominal, comp_forward, comp_reverse;
unsigned char probe_type;
int probe_jog_err_inhibit; int probe_home_err_inhibit; EmcPose tool_offset;
double orientation;
char direction;
double timeout;
unsigned char wait_for_spindle_at_speed; unsigned char tail;
int arcBlendOptDepth;
int arcBlendEnable;
int arcBlendFallbackEnable;
int arcBlendGapCycles;
double arcBlendRampFreq;
double arcBlendTangentKinkRatio;
double maxFeedScale;
double ext_offset_vel;
double ext_offset_acc;
} emcmot_command_t;
typedef unsigned short EMCMOT_MOTION_FLAG;
#define EMCMOT_MOTION_ENABLE_BIT 0x0001
#define EMCMOT_MOTION_INPOS_BIT 0x0002
#define EMCMOT_MOTION_COORD_BIT 0x0004
#define EMCMOT_MOTION_ERROR_BIT 0x0008
#define EMCMOT_MOTION_TELEOP_BIT 0x0010
typedef unsigned short EMCMOT_JOINT_FLAG;
#define EMCMOT_JOINT_ENABLE_BIT 0x0001
#define EMCMOT_JOINT_ACTIVE_BIT 0x0002
#define EMCMOT_JOINT_INPOS_BIT 0x0004
#define EMCMOT_JOINT_ERROR_BIT 0x0008
#define EMCMOT_JOINT_MAX_HARD_LIMIT_BIT 0x0010
#define EMCMOT_JOINT_MIN_HARD_LIMIT_BIT 0x0020
#define EMCMOT_JOINT_FERROR_BIT 0x0040
#define EMCMOT_JOINT_FAULT_BIT 0x0080
typedef struct {
double nominal;
float fwd_trim;
float rev_trim;
float fwd_slope;
float rev_slope;
} emcmot_comp_entry_t;
#define EMCMOT_COMP_SIZE 256
typedef struct {
int entries;
emcmot_comp_entry_t *entry;
emcmot_comp_entry_t array[EMCMOT_COMP_SIZE+2];
} emcmot_comp_t;
typedef enum {
EMCMOT_MOTION_DISABLED = 0,
EMCMOT_MOTION_FREE,
EMCMOT_MOTION_TELEOP,
EMCMOT_MOTION_COORD
} motion_state_t;
typedef enum {
EMCMOT_ORIENT_NONE = 0,
EMCMOT_ORIENT_COMPLETE,
EMCMOT_ORIENT_IN_PROGRESS,
EMCMOT_ORIENT_FAULTED,
} orient_state_t;
#define HOME_IGNORE_LIMITS 1
#define HOME_USE_INDEX 2
#define HOME_IS_SHARED 4
#define HOME_UNLOCK_FIRST 8
#define HOME_ABSOLUTE_ENCODER 16
#define HOME_NO_REHOME 32
#define HOME_NO_FINAL_MOVE 64
#define HOME_INDEX_NO_ENCODER_RESET 128
#define SS_ENABLED 0x01
#define FS_ENABLED 0x02
#define AF_ENABLED 0x04
#define FH_ENABLED 0x08
typedef struct {
int type;
double max_pos_limit;
double min_pos_limit;
double max_jog_limit;
double min_jog_limit;
double vel_limit;
double acc_limit;
double min_ferror;
double max_ferror;
double backlash;
emcmot_comp_t comp;
EMCMOT_JOINT_FLAG flag;
double coarse_pos;
double pos_cmd;
double vel_cmd;
double acc_cmd;
double backlash_corr;
double backlash_filt;
double backlash_vel;
double motor_pos_cmd;
double motor_pos_fb;
double pos_fb;
double ferror;
double ferror_limit;
double ferror_high_mark;
simple_tp_t free_tp;
int kb_jjog_active;
int wheel_jjog_active;
CUBIC_STRUCT cubic;
int on_pos_limit;
int on_neg_limit;
double motor_offset;
int old_jjog_counts;
double big_vel;
} emcmot_joint_t;
typedef struct {
EMCMOT_JOINT_FLAG flag;
bool homed;
bool homing;
double pos_cmd;
double pos_fb;
double vel_cmd;
double acc_cmd;
double ferror;
double ferror_high_mark;
double backlash;
double max_pos_limit;
double min_pos_limit;
double min_ferror;
double max_ferror;
} emcmot_joint_status_t;
typedef struct {
double speed; double scale; double net_scale; double css_factor;
double xoffset;
int direction; int brake; int locked; int orient_fault; int orient_state; int spindle_index_enable;
double spindleRevs;
double spindleSpeedIn;
int at_speed;
int fault;
} spindle_status_t;
typedef struct {
double pos_cmd;
double teleop_vel_cmd;
double max_pos_limit;
double min_pos_limit;
double vel_limit;
double acc_limit;
simple_tp_t teleop_tp;
int old_ajog_counts;
int kb_ajog_active;
int wheel_ajog_active;
int locking_joint;
double ext_offset_vel_limit;
double ext_offset_acc_limit;
int old_eoffset_counts;
simple_tp_t ext_offset_tp;
} emcmot_axis_t;
typedef struct {
double teleop_vel_cmd;
double max_pos_limit;
double min_pos_limit;
} emcmot_axis_status_t;
typedef struct emcmot_status_t {
unsigned char head;
cmd_code_t commandEcho;
int commandNumEcho;
cmd_status_t commandStatus;
double feed_scale;
double rapid_scale;
unsigned char enables_new;
double net_feed_scale;
unsigned char enables_queued;
motion_state_t motion_state;
EMCMOT_MOTION_FLAG motionFlag;
EmcPose carte_pos_cmd;
int carte_pos_cmd_ok;
EmcPose carte_pos_fb;
int carte_pos_fb_ok;
EmcPose world_home;
emcmot_joint_status_t joint_status[EMCMOT_MAX_JOINTS];
emcmot_axis_status_t axis_status[EMCMOT_MAX_AXIS];
int spindleSync;
spindle_status_t spindle_status[EMCMOT_MAX_SPINDLES];
int on_soft_limit;
int probeVal;
int probeTripped;
int probing;
unsigned char probe_type;
EmcPose probedPos;
int synch_di[EMCMOT_MAX_DIO];
int synch_do[EMCMOT_MAX_DIO];
double analog_input[EMCMOT_MAX_AIO];
double analog_output[EMCMOT_MAX_AIO];
unsigned int heartbeat;
int config_num;
int id;
int depth;
int activeDepth;
int queueFull;
int paused;
int overrideLimitMask;
int reverse_run;
double vel;
double acc;
int motionType;
double distance_to_go;
EmcPose dtg;
double current_vel;
double requested_vel;
unsigned int tcqlen;
EmcPose tool_offset;
int atspeed_next_feed;
unsigned char tail;
int external_offsets_applied;
EmcPose eoffset_pose;
int numExtraJoints;
} emcmot_status_t;
typedef struct emcmot_config_t {
unsigned char head;
int config_num;
int numJoints;
int numExtraJoints;
int numSpindles;
KINEMATICS_TYPE kinType;
int numDIO;
int numAIO;
double trajCycleTime;
double servoCycleTime;
int interpolationRate;
double limitVel;
int debug;
unsigned char tail;
int arcBlendOptDepth;
int arcBlendEnable;
int arcBlendFallbackEnable;
int arcBlendGapCycles;
double arcBlendRampFreq;
double arcBlendTangentKinkRatio;
double maxFeedScale;
int inhibit_probe_jog_error;
int inhibit_probe_home_error;
} emcmot_config_t;
typedef struct emcmot_internal_t {
unsigned char head;
int probe_debounce_cntr;
unsigned char tail;
} emcmot_internal_t;
typedef struct emcmot_error_t {
unsigned char head;
char error[EMCMOT_ERROR_NUM][EMCMOT_ERROR_LEN];
int start;
int end;
int num;
unsigned char tail;
} emcmot_error_t;
extern int emcmotErrorInit(emcmot_error_t * errlog);
extern int emcmotErrorPut(emcmot_error_t * errlog, const char *error);
extern int emcmotErrorPutfv(emcmot_error_t * errlog, const char *fmt, va_list ap);
extern int emcmotErrorPutf(emcmot_error_t * errlog, const char *fmt, ...);
extern int emcmotErrorGet(emcmot_error_t * errlog, char *error);
#ifdef __cplusplus
}
#endif
#endif