syntax = "proto2";
package machinetalk;

// see README.msgid
// msgid base: 600

import "machinetalk/protobuf/emcclass.proto";
import "machinetalk/protobuf/nanopb.proto";

// an uncleaned first transliteration

// add _ to avoid collision with macros in emc/nml_intf/motion_typesh
enum MotionType {
    _EMC_MOTION_TYPE_NONE = 0; // sometimes also 0 is reported
    _EMC_MOTION_TYPE_TRAVERSE = 1;
    _EMC_MOTION_TYPE_FEED = 2;
    _EMC_MOTION_TYPE_ARC = 3;
    _EMC_MOTION_TYPE_TOOLCHANGE = 4;
    _EMC_MOTION_TYPE_PROBING = 5;
    _EMC_MOTION_TYPE_INDEXROTARY = 6;
};

enum  cmd_code_t  {
    // motion commands. enum cmd_code_t from src/emc/motion.h

    EMCMOT_ABORT = 4000;	/* abort all motion */
    EMCMOT_AXIS_ABORT = 4001;	/* abort one axis */ //FIXME-AJ: replace command name to EMCMOT_JOINT_ABORT
    EMCMOT_ENABLE = 4002;		/* enable servos for active joints */
    EMCMOT_DISABLE = 4003;		/* disable servos for active joints */
    EMCMOT_ENABLE_AMPLIFIER = 4004;	/* enable amp outputs */
    EMCMOT_DISABLE_AMPLIFIER = 4005;	/* disable amp outputs */
    EMCMOT_ENABLE_WATCHDOG = 4006;	/* enable watchdog sound = 4000; parport */
    EMCMOT_DISABLE_WATCHDOG = 4007;	/* enable watchdog sound = 4000; parport */
    EMCMOT_ACTIVATE_JOINT = 4008;	/* make joint active */
    EMCMOT_DEACTIVATE_JOINT = 4009;	/* make joint inactive */

    EMCMOT_PAUSE = 4010;		/* pause motion */
    EMCMOT_RESUME = 4011;		/* resume motion */
    EMCMOT_STEP = 4012;		/* resume motion until id encountered */
    EMCMOT_FREE = 4013;		/* set mode to free (joint) motion */
    EMCMOT_COORD = 4014;		/* set mode to coordinated motion */
    EMCMOT_TELEOP = 4015;		/* set mode to teleop */

    EMCMOT_SPINDLE_SCALE = 4016;	/* set scale factor for spindle speed */
    EMCMOT_SS_ENABLE = 4017;	/* enable/disable scaling the spindle speed */
    EMCMOT_FEED_SCALE = 4018;	/* set scale factor for feedrate */
    EMCMOT_FS_ENABLE = 4019;	/* enable/disable scaling feedrate */
    EMCMOT_FH_ENABLE = 4020;	/* enable/disable feed_hold */
    EMCMOT_AF_ENABLE = 4021;	/* enable/disable adaptive feedrate */
    EMCMOT_OVERRIDE_LIMITS = 4022;	/* temporarily ignore limits until jog done */

    EMCMOT_HOME = 4023;		/* home a joint or all joints */
    EMCMOT_UNHOME = 4024;		/* unhome a joint or all joints*/
    EMCMOT_JOG_CONT = 4025;	/* continuous jog */
    EMCMOT_JOG_INCR = 4026;	/* incremental jog */
    EMCMOT_JOG_ABS = 4027;		/* absolute jog */
    EMCMOT_SET_LINE = 4028;	/* queue up a linear move */
    EMCMOT_SET_CIRCLE = 4029;	/* queue up a circular move */
    EMCMOT_SET_TELEOP_VECTOR = 4030;	/* Move at a given velocity but in
					   world cartesian coordinates = 4000; not
					   in joint space like EMCMOT_JOG_* */

    EMCMOT_CLEAR_PROBE_FLAGS = 4031;	/* clears probeTripped flag */
    EMCMOT_PROBE = 4032;		/* go to pos = 4000; stop if probe trips = 4000; record
					   trip pos */
    EMCMOT_RIGID_TAP = 4033;	/* go to pos = 4000; with sync to spindle speed = 4000;
				   then return to initial pos */

    EMCMOT_SET_POSITION_LIMITS = 4034;	/* set the joint position +/- limits */
    EMCMOT_SET_BACKLASH = 4035;	/* set the joint backlash */
    EMCMOT_SET_MIN_FERROR = 4036;	/* minimum following error = 4000; input units */
    EMCMOT_SET_MAX_FERROR = 4037;	/* maximum following error = 4000; input units */
    EMCMOT_SET_VEL = 4038;		/* set the velocity for subsequent moves */
    EMCMOT_SET_VEL_LIMIT = 4039;	/* set the max vel for all moves (tooltip) */
    EMCMOT_SET_JOINT_VEL_LIMIT = 4040;	/* set the max joint vel */
    EMCMOT_SET_JOINT_ACC_LIMIT = 4041;	/* set the max joint accel */
    EMCMOT_SET_ACC = 4042;		/* set the max accel for moves (tooltip) */
    EMCMOT_SET_TERM_COND = 4043;	/* set termination condition (stop = 4000; blend) */
    EMCMOT_SET_NUM_AXES = 4044;	/* set the number of joints */ //FIXME-AJ: function needs to get renamed
    EMCMOT_SET_WORLD_HOME = 4045;	/* set pose for world home */
    EMCMOT_SET_HOMING_PARAMS = 4046;	/* sets joint homing parameters */
    EMCMOT_SET_DEBUG = 4047;       /* sets the debug level */
    EMCMOT_SET_DOUT = 4048;        /* sets or unsets a DIO = 4000; this can be imediate or synched with motion */
    EMCMOT_SET_AOUT = 4049;	/* sets or unsets a AIO = 4000; this can be imediate or synched with motion */
    EMCMOT_SET_SPINDLESYNC = 4050;      /* syncronize motion to spindle encoder */

    EMCMOT_SPINDLE_ON = 4051;	        /* start the spindle */
    EMCMOT_SPINDLE_OFF = 4052;	        /* stop the spindle */
    EMCMOT_SPINDLE_INCREASE = 4053;	/* spindle faster */
    EMCMOT_SPINDLE_DECREASE = 4054;	/* spindle slower */
    EMCMOT_SPINDLE_BRAKE_ENGAGE = 4055;	/* engage the spindle brake */
    EMCMOT_SPINDLE_BRAKE_RELEASE = 4056;/* release the spindle brake */
    EMCMOT_SET_MOTOR_OFFSET = 4057;	/* set the offset between joint and motor */
    EMCMOT_SET_JOINT_COMP = 4058;	/* set a compensation triplet for a joint (nominal, forw., rev.) */
    EMCMOT_SET_OFFSET = 4059;           /* set tool offsets */
};

enum cmd_status_t {
    EMCMOT_COMMAND_OK = 0;	        /* cmd honored */
    EMCMOT_COMMAND_UNKNOWN_COMMAND = 1;	/* cmd not understood */
    EMCMOT_COMMAND_INVALID_COMMAND = 2;	/* cmd can't be handled now */
    EMCMOT_COMMAND_INVALID_PARAMS = 3;	/* bad cmd params */
    EMCMOT_COMMAND_BAD_EXEC	= 4;    /* error trying to initiate */
};


message MotionCommand {

    option (nanopb_msgopt).msgid = 600; // see README.msgid

    required cmd_code_t command  = 10;
    required fixed32 commandNum = 20;	/* increment this for new command */
    optional double motor_offset = 30;  /* offset from joint to motor position */
    optional double maxLimit = 40;	/* pos value for position limit, output */
    optional double minLimit = 50;	/* neg value for position limit, output */
    optional EmcPose pos = 60;		/* line/circle endpt, or teleop vector */
    optional PmCartesian center = 70;	/* center for circle */
    optional PmCartesian normal = 80;	/* normal vec for circle */
    optional fixed32 turn = 90;		/* turns for circle or which rotary to unlock for a line */
    optional double vel = 100;		/* max velocity */
    optional double ini_maxvel = 110;   // max velocity allowed by machine
					// optional constraints (the ini file)
    optional MotionType motion_type = 120;    // this move is because of traverse, feed, arc, or toolchange
    optional double spindlesync = 130;        /* user units per spindle revolution, 0 = no sync */
    optional double acc = 140;		/* max acceleration */
    optional double backlash = 150;	        /* amount of backlash */
    optional fixed32 id = 160;		/* id for motion */
    optional fixed32 termCond = 170;		/* termination condition */
    optional double tolerance = 180;	        /* tolerance for path deviation in CONTINUOUS mode */
    optional fixed32 axis = 190;		/* which index to use for below */ //FIXME-AJ: replace with joint
    optional double scale = 200;		/* velocity scale or spindle_speed scale arg */
    optional double offset = 210;		/* input, output, or home offset arg */
    optional double home = 220;		/* joint home position */
    optional double home_final_vel = 230;	/* joint velocity for moving from OFFSET to HOME */
    optional double search_vel = 240;	        /* home search velocity */
    optional double latch_vel = 250;	        /* home latch velocity */
    optional fixed32 flags = 260;		/* homing config flags, other boolean args */
    optional fixed32 home_sequence = 270;     /* order in homing sequence */
    optional fixed32 volatile_home = 280;     // joint should get unhomed when we get unhome -2
					// optional  (generated by task upon estop, etc)
    optional double minFerror = 290;	        /* min following error */
    optional double maxFerror = 300;	        /* max following error */
    optional fixed32 wdWait = 310;		/* cycle to wait before toggling wd */
    optional fixed32 debug = 320;		/* debug level, from DEBUG in .ini file */
    optional int32 now = 330;
    optional int32 out = 340;
    optional int32 start = 350;
    optional int32 end = 360;            // these are related to synched AOUT/DOUT
                                        // now=wether now or synched, out = which gets set,
                                        // start=start value, end=end value
    optional int32 mode = 370;	                /* used for turning overrides etc. on/off */
    optional double comp_nominal = 380; /* compensation triplet, nominal, forward, reverse */
    optional double comp_forward = 390; /* compensation triplet, nominal, forward, reverse */
    optional double comp_reverse = 400; /* compensation triplet, nominal, forward, reverse */
    optional int32 probe_type = 410;           /* ~1 = error if probe operation is unsuccessful (ngc default)
					 |1 = suppress error, report in # instead
					 ~2 = move until probe trips (ngc default)
					 |2 = move until probe clears */
    optional EmcPose tool_offset = 420;        /* TLO */
};


message MotionStatus {

    option (nanopb_msgopt).msgid = 601;

    required cmd_code_t     commandEcho = 10;	/* echo of input command */
    required fixed32        commandNumEcho = 20;	/* increment this for new command */
    required cmd_status_t commandStatus = 30;	/* result of most recent command */
    optional EmcPose         carte_pos_fb = 40;	/* actual Cartesian position */
};
