/* ROVSYS.H  Rover System Parameters and Global Variables
*            (and stuff I have no idea where to put)
*/

#ifndef __rovsys_H
#define __rovsys_H

/*  Calibration Coeficients  */

#define BATTCAL         1512
#define HPCURRCAL       569
#define LPCURRCAL       5635
#define GFVOLTCAL       3276
#define TILTX_CAL       364
#define TILTX_OFFSET    45      /* Tilt outputs 2.5V when level */
#define TILTY_CAL       364
#define TILTY_OFFSET    45
#define AUXANACAL       6552
#define ODOCAL          36.5    /* 36.5 cm/tick */


/* Timers */

#define NOW			    0   /* For time() function */
#define TICK_RATE                1000   /* For Sleep function */
#define TURN_TIMEOUT             6000   /* Tens of milliseconds */
#define TURN_DATA_RATE            100
#define TRANSIT_TIMEOUT         18000   /* 18000 is 3 min. */
#define TRANSIT_DATA_RATE         100   /* 100 is 1 sec. */
#define TRANSPOND_LOCK_TIME       500

/*  Misc. Rack Stuff */

#define RACK_TIMEOUT            60000      /* Tens of milliseconds */
#define RACK_DATA_RATE            500
#define LEADSCREW_DIFF_MAX      2


/* Current Meter */

#define CURRENT_THRESHOLD          20           /* mm/sec */

/* FILMCAM PARAMETERS */

#define FILMCAM_RATE              500           /* Tens of milliseconds */
#define TRIGGERTIME		  200             /* msec */


/* Analog Channel Assignments */

#define BATTCHAN        0
#define HPCURRCHAN      1
#define LPCURRCHAN      2
#define GFVOLTCHAN      3
#define TILTX_CHAN      4
#define TILTY_CHAN      5
#define CMVANECHAN      6
#define AUXANACHAN      7


/* TPU Channel Assignments */

#define         FILMCAM         1
#define         AUXOUT          2
#define         PORT_LEADSCREW  3
#define         STBD_LEADSCREW  4
#define         ODOMETER        5
#define         CMMOT_SHAFT     6
#define         TRANSPOND_IN    7
#define         TRANSPOND_OUT   8
#define         CMROTOR         9
#define         CMROTOR_PWR     10
#define         CMVANE_PWR      11
#define         TPUSERTX        12
#define         TPUSERRX        13


/* TPU RS-232 Channel Assignments */

#define		CURRMET			0
#define		STBD_BENCHAM		1
#define		PORT_BENCHAM		2
#define		MICPROF			3
#define		COMPASS			7


/* Power Relay Board Definitions */

#define         MOT1A   0x1   /* Sets pin 1 of output port */
#define         MOT1B   0x2
#define         MOT2A   0x4
#define         MOT2B   0x8
#define         AUX1    0x10
#define         AUX2    0x20
#define         AUX3    0x40  /* Sets pin 7 of output port */


/* Power Control Board Definitions */

#define         POWER1          0x1
#define         POWER2          0x2
#define         POWER3          0x4
#define         POWER4          0x8
#define         POWER5          0x10
#define         POWER6          0x20
#define         POWER7          0x40
#define         POWER8          0x80


/* Input Port Definitions */

#define         RACKUP          0x1
#define         STBD_LIMITPAD   0x2
#define         PORT_LIMITPAD   0x4
#define         LIMITUP         0x8
#define         LIMITDWN        0x10

/********************** Rover Activity Codes *************/

#define TRANSIT                 1
#define TURN_RIGHT              2
#define TURN_LEFT               3
#define RACK_DOWN               10
#define RACK_UP                 11
#define CURRMET_DATA            22

/********************** Rover Error Codes **************/

#define TRANSIT_TIMEOUT_ERR             1000
#define TURN_TIMEOUT_ERR                1010
#define RACK_LIMITUP_ERR                1020
#define RACK_LIMITDWN_ERR               1021
#define RACK_LEADSCREW_ERR              1022
#define RACK_TIMEOUT_ERR                1023
#define RACK_JAM_ERR                    1024




/********************  GLOBAL VARIABLES *********************/

/* In ROVINT.C */
extern int g_odometer_ticks, g_stbd_leadscrew_ticks, g_port_leadscrew_ticks;

/* In ROVLIB.C */
extern int g_program_level;

/* In ROVFILE.C */
extern short g_curr_speed, g_curr_dir, g_heading;
#endif
