/*
 * RCCL Version 1.0           Author :  Vincent Hayward
 *                                      School of Electrical Engineering
 *                                      Purdue University
 *      Dir     : h
 *      File    : manip.h
 *      Remarks : All the structures and entry point declaration not
 *                known by the user
 *      Usage   : Included in the concerned files
 */

#define HARDCLOCK       7       /* basic sample time    */
#define MINSAMPLE       7       /* minimum sample time  */
#define MAXSAMPLE       112     /* maximum .....  ....  */
#define DEF_SAMPLE      28      /* default ...... ....  */
#define DEF_TRSV        10      /* default trs vel mm/s */
#define DEF_ROTV        10      /* default rot vel dg/s */

/*
 * bit definitions for set operations on directions and joints
 */

#define SELFX           01
#define SELFY           02
#define SELFZ           04
#define SELMX           010
#define SELMY           020
#define SELMZ           040

#define SELTX           01
#define SELTY           02
#define SELTZ           04
#define SELRX           010
#define SELRY           020
#define SELRZ           040

#define SELJ1           01
#define SELJ2           02
#define SELJ3           04
#define SELJ4           010
#define SELJ5           020
#define SELJ6           040



typedef int     ALIGN;                  /* basic machine word boundary  */

typedef union it {                      /* basic queue item aligned     */
		union it *next;
		ALIGN z;
} ITEM, *ITEM_PTR;

typedef struct rt {                     /* empty record head of queue   */
		ITEM_PTR put;
		ITEM_PTR get;
} ROOT, *ROOT_PTR;

typedef struct linkterm {               /* position equation term       */
		TRSF_PTR trsf;          /* user's transform             */
		TRSF_PTR altr;          /* alternate system's transform */
		TRSF_PTR oldt;          /* old value                    */
		bool rhs;               /* right hand side pred         */
		ROOT hd;                /* head of the hold trsf queue  */
		struct linkterm *next;  /* pointer to the next          */
		struct linkterm *prev;  /* pointer to the previous      */
} TERM, *TERM_PTR;

					/* internal position structure  */
					/* that maps exactly on user's  */
typedef struct position {               /* POS structure                */
		char *name;             /* name pointer                 */
		int code;               /* termination code             */
		real scal;              /* motion scalar 0 - 1          */
		event end;              /* signaled when done           */

					/* what follows is not known    */
		bool cfnsp, tfnsp;      /* coord fns , tool fns pred.   */
		bool coorp, toolp;      /* coord , tool pred.           */
		TERM_PTR t6ptr;         /* pointer to t6 term           */
		TERM_PTR tlptr;         /* pointer to tool term         */
		TERM_PTR pos;           /* pointer to pos term          */
} PST, *PST_PTR;

typedef struct drivepar {               /* drive parameters             */
		real dx, dy, dz;
		real dthe, dphi, dpsi;
} DRVP, *DRVP_PTR;


typedef struct mot {                    /* motion record                */
		int acct, sgt;          /* acc. time, segment time      */
		int velt, velr;         /* trans, rot velocities        */
		PST_PTR pst;            /* position requested           */
		int mod;                /* mode                         */
		char *cfg;              /* configuration                */
		TERM_PTR upd;           /* term to be updated           */
		TRFN fnt;               /* functions to be evaluated    */
		int smpl;               /* sample                       */
		real fmass;             /* mass of object               */
		int fsp;                /* force limit selection        */
		FORCE frc;              /* ..... ..... values           */
		int csp;                /* comply selection             */
		FORCE cpy;              /* ...... values                */
		int dsp;                /* diff motion selection        */
		DIFF dst;               /* ........... values           */
		int exp;                /* extra distance selection     */
		DIFF exd;               /* ..... ........ values        */
} MOT, *MOT_PTR;

typedef struct opsw {                   /* option switches              */
		bool graphics,          /* graphic files (unformated)   */
		     numerics,          /* numeric output (formated)    */
		     angles,            /* angles in solution frame     */
		     t6butnotj6,        /* t6 but not j6                */
		     encoders;          /* encoder values output        */
} OPSW, *OPSW_PTR;



extern  ROOT    mqueue_n;               /* motion queue head            */

/*
 * function's types
 */

extern ITEM_PTR dequeue_n();

extern  int     setpoint_n(),
		checkstate_n();

extern  char    *strsave();

extern  char    *mess;                  /* in rtc               */

/*
 * fake system with signals use this Unix unallocated signal
 */

#ifdef  FAKE
#define SIGCLCK 16
#endif

/*
 * extra entry points that only exist in the PLAN and FAKE version
 */

#ifndef REAL
extern  OPSW    opsw_n;

extern  FILE    *fpo;

#define release release_l
#define control control_l

extern  int     release_l(),
		control_l();
#endif
