/* 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 CMVANECAL       45.5
#define CMVANE_OFFSET   180     /* Vane pot mid-point faces rear of Rover */
#define AUXANACAL       6552
#define ODOCAL          36.5    /* 36.5 cm/tick */
#define CMROTOR_CAL     20      /* 200 mm/sec at 1 RPM */


/* Timers */

#define TICK_RATE                  10   /* 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 CURRMET_UP_POS            528           /* 4 ticks per shaft rev. */
#define CMMOT_DATA_RATE           500           /* Tens of milliseconds */
#define CMMOT_TIMEOUT           60000           /* 60000 = 10 min. */
#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         LEADSCREW2      3
#define         LEADSCREW1      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		AUX		0
#define		BENCHAM1	1
#define		BENCHAM2	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         LIMITPAD1       0x2
#define         LIMITPAD2       0x4
#define         LIMITUP         0x8
#define         LIMITDWN        0x10
#define         CMLIMIT         0x20

/********************** Rover Activity Codes *************/

#define TRANSIT                 1
#define TURN_RIGHT              2
#define TURN_LEFT               3
#define RACK_DOWN               10
#define RACK_UP                 11
#define CURRMET_UP              20
#define CURRMET_DOWN            21
#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
#define CMMOT_TIMEOUT_ERR               1025
#define CMMOT_JAM_ERR                   1026





/********************  GLOBAL VARIABLES *********************/

/* In ROVINT.C */
extern int g_odometer_ticks, g_leadscrew1_ticks, g_leadscrew2_ticks;
extern int g_cmmot_shaft_ticks;

/* In ROVLIB.C */
extern int g_cmrotor_ticks, g_program_level;

/* In ROVFILE.C */
extern short g_curr_speed, g_curr_dir, g_heading;
#endif
