/*
 * RCCL Version 1.0           Author :  Vincent Hayward
 *                                      School of Electrical Engineering
 *                                      Purdue University
 *      Dir     : src
 *      File    : shared.c
 *      Remarks : No code, only the global variables.
 *      Usage   : part of the library
 */

/*LINTLIBRARY*/

#include "../h/which.h"
#include "../h/switch.h"
#include "../h/rccl.h"
#include "../h/manip.h"
#include "../h/kine.h"
#include "../h/bio.h"

#define TIMEINC 28        /* default */

#ifndef REAL
/*
 *      option switches
 */

	OPSW    opsw_n = {
			NO,             /* graphics             */
			NO,             /* numerics             */
			NO,             /* angles               */
			NO,             /* t6butnotj6           */
			NO              /* encoders             */
		};

	FILE    *fpo = stderr;          /* output file option -d */

/*
 *      buffered io buffers for options -g -e
 */

	BIO     iobf_n[NBUF] = {
			{1, NULL}, {1, NULL}, {1, NULL},
			{1, NULL}, {1, NULL}, {1, NULL},
			{1, NULL}, {1, NULL}, {1, NULL},
			{1, NULL}, {1, NULL}, {1, NULL},
			{1, NULL}, {1, NULL}, {1, NULL}
		};
#endif

/*
 *      version independant section
 */

static  JNTS    j6j = {"          "},           /* storage for j6       */
		jdj = {"          "};           /* ....... ... jd       */

static  TRSF    t6t = {"T6", const},            /* ....... ... t6       */
		rst = {"REST", const},          /* ....... ... rest     */
		hrt = {"HERE", varb},           /* ....... ... here     */
		unt = {"UNIT", const,           /* ....... ... unitr    */
			1., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0.};

static  VECT    xun = {1., 0., 0.},             /* ....... ... xunit    */
		yun = {0., 1., 0.},             /* ....... ... yunit    */
		zun = {0., 0., 1.};             /* ....... ... zunit    */
/*
 *      global pointers
 */

	JNTS_PTR j6 = &j6j,             /* joints as computed by setpoint  */
		 jd = &jdj;             /* difference between two points   */

	TRSF_PTR t6 = &t6t,             /* t6 as compyted by setpoint      */
		 here = &hrt,           /* succesive t6 before transitions */
		 rest = &rst,           /* park t6                         */
		 unitr = &unt;          /* unit transform                  */

       VECT_PTR xunit = &xun,           /* unit X vector                   */
		yunit = &yun,           /* .... Y ......                   */
		zunit = &zun;           /* .... Z ......                   */

	POS_PTR lastpos = NULL,         /* last evaluated position equ.    */
		goalpos = NULL,         /* current ...................     */
		there,
		park;

	event   completed = 0;          /* queue empty                     */

	FILE    *fpi = stderr;          /* info file option -v             */

	bool    prints_out = NO,        /* prints switch                   */
		force_ctl = YES;        /* force stuff switch              */

	int     fddb = -1;              /* data base file des.             */

	int     rtime = 0,              /* time in ms                      */
		timeincrement = TIMEINC,        /* current sample          */
		requestnb = 0;          /* number non served requests      */
		nextmove = NO;          /* causes motion interrupt         */

	short   hdpos = 0;              /* shipped to the controller       */

/*
 *      math constants
 */

	real    pi_m = PI,
		pit2_m = PIT2,
		pib2_m = PIB2,
		dgtord_m = DEGTORAD,
		rdtodg_m = RADTODEG;


/*
 *      arm sin cos
 */

	SNCS  sncs_d;

/*
 *      arms constants
 */

#ifdef PUMA
#include "../h/pumadata.h"
#endif
#ifdef STAN
#include "../h/standata.h"
#endif

/*
 * park angles
 */

	JNTS    jcal_c = {"      ", JCAL1, JCAL2, JCAL3, JCAL4, JCAL5, JCAL6};


/*
 * angles -> range offsets
 */
	JNTS    jmin_c = {"      ", JMIN1, JMIN2, JMIN3, JMIN4, JMIN5, JMIN6};

/*
 * joint ranges
 */
	JNTS    jrng_c = {"      ", JRNG1, JRNG2, JRNG3, JRNG4, JRNG5, JRNG6};

/*
 * max joint velocities
 */
	JNTS    jmxv_c = {"",
			JMXV1 * DEF_SAMPLE / 1000.,
			JMXV2 * DEF_SAMPLE / 1000.,
			JMXV3 * DEF_SAMPLE / 1000.,
			JMXV4 * DEF_SAMPLE / 1000.,
			JMXV5 * DEF_SAMPLE / 1000.,
			JMXV6 * DEF_SAMPLE / 1000.
		};

/*
 * kinematics constants
 */

#ifdef PUMA
	KINDYN  armk_c = {
			A2,             /* A2                           */
			A3,             /* A3                           */
			D3,             /* D3                           */
			D4,             /* D4                           */
			D32,            /* D3 * D3                      */
			E432,           /* D4 * D4 + A3 * A3 + A2 * A2  */
			AA3D4,          /* atan2(A3, -D4)               */
			E4AA4AD,        /* 4. * A2 * A2 * A3 * A3 +     */
					/* 4. * A2 * A2 * D4 * D4       */

			CP21,           /* joint gravity loads          */
			CP31,
			CP32,
			CP50
		};
#endif


#ifdef STAN
	KINDYN  armk_c = {
			D2,
			D22
		};
#endif
