/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#ifndef _ROBOT_JLS_H_
#define _ROBOT_JLS_H_

/* ---- Definition for Joint Level Stuff ---- */

#include "../h/maxjnts.h"

#define MAXC	 3	/* maximun number of joint couplings */

typedef struct _JLS {	

	/* What sort of robot it is */

	    int class;	/** field not used yet **/
	    int type;	/** field not used yet **/

	/* Basic stuff */

	    int	numJ;			/* number of joints */
	    int	numFC;			/* number of forward couplings */
	    int	numIC;			/* number of forward couplings */
	    int forCouplings [MAXC][2]; /* forward coupling indices */
	    int invCouplings [MAXC][2]; /* inverse coupling indices */
	  float forGearRatios [MAXJNTS+MAXC]; /* forward gear ratios */
	  float invGearRatios [MAXJNTS+MAXC]; /* inverse gear ratios */

	/* Position stuff */

	  float	angtoenc [MAXJNTS+MAXC]; /* encoder to angle ratios */
	  float enctoang [MAXJNTS+MAXC]; /* angle to encoder ratios */
	    int	encOffset [MAXJNTS];	/* angle to encoder offsets */

	/* Torque stuff */

	  float mtorqueToCurrent [MAXJNTS]; /* motor tor. to output DAC ratios */
	  float	currentToMtorque [MAXJNTS]; /* ADC input to motor tor. ratios */
	  int currentBias [MAXJNTS];	    /* 'zero-torque' values, if */
					    /* current output is biased */

	/* calibration stuff */

	    int	encWheelSize [MAXJNTS];	/* encoder counts per shaft rev. */
	    int	encCalvec [MAXJNTS];	/* encoder calibration offsets */
	    int	encHome [MAXJNTS];	/* encoder counts at home/nest pos. */
	  float	potSlope [MAXJNTS];	/* coefficients for potentiometer */
	  float potIntercept [MAXJNTS];	/*    encoder estimates */

	/* Joint and range information */

	   char jtype [MAXJNTS+1];	/* revolute, prismatic */
	  float	jmin [MAXJNTS];		/* minimun joint position (rad) */
	  float jmax [MAXJNTS];		/* maximum joint position (rad) */
	  float jrng [MAXJNTS];		/* joint range (rad) */
	  float maxVel [MAXJNTS];	/* maximum velocity (rad/sec) */
	  float	maxAcc [MAXJNTS];	/* maximum acceleration (rad/sec^2) */
	  float maxJerk[MAXJNTS];	/* maximum jerk (rad/sec^3) */

	  float	maxMtorque [MAXJNTS];	/* maximum motor torque */
	  float	maxJtorque [MAXJNTS];	/* maximum joint torque */

	/* Utility information */

	  float	parkAngles [MAXJNTS];	/* angles in the park position */
	  float	bestAngles [MAXJNTS];	/* well conditioned angles */
	  float	averageGearRatio;	/* average value of the gear ratios */
	  float	averageAngtoenc;	/* average value of angtoenc */
	  float	nominalVel [MAXJNTS];	/* nominal value for speed */
	  float nominalAcc [MAXJNTS];	/* nominal value for acceleration */
	  float nominalJerk[MAXJNTS];	/* nominal value for jerk */
	  float averageVel;		/* average of nominalVel field */
	  float averageAcc;		/* average of nominalVel field */
	  float averageJerk;		/* average of nominalVel field */
	   long	flags;			/* field for special flags */

	/* Conversion functions */

	    int	(*encoderToAngle)();	/* encoder to angle conversion */
	    int	(*angleToEncoder)();	/* angle to encoder conversion */
	    int	(*encoderToJoint)();	/* encoder to joint conversion */
	    int	(*jointToEncoder)();	/* joint to encoder conversion */
	    int	(*mtorqueToJtorque)();	/* motor torque to joint torque */
	    int	(*jtorqueToMtorque)();	/* joint torque to motor torque */
} JLS;

typedef struct {
	struct _GEN_KYN *gen;
	void *ext;
} KYN;

#ifndef PROTO
#ifndef NO_PROTOTYPES
#define PROTO(x) x
#else
#define PROTO(x) ()
#endif
#endif

extern JLS *getJls PROTO((const char*));
extern KYN *getKyn PROTO((const char*, int*));
extern find_robot PROTO((const char*));
extern robot_class PROTO((const char*));
extern int getVarSize PROTO((const char*));
extern char *getDefaultRobot PROTO(());
extern getRobotPosition PROTO((float*, const char*, const char*));

#endif
