/****************************************************************************/
/* Copyright 1994 to 1996 MBARI                                             */
/****************************************************************************/
/* Summary  : Pan and Tilt Application definitions                          */
/* Filename : panTilt.h                                                     */
/* Author   : Andrew Pearce                                                 */
/* Project  : Tiburon ROV                                                   */
/* Version  : Version 1.0                                                   */
/* Created  : 02/07/94                                                      */
/* Modified : 04/01/96                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header: /usr/tiburon/.cvsroot/micro/h/pantilt.h,v 1.2 1997/09/09 17:30:35 pean Exp $
 * $Log: pantilt.h,v $
 * Revision 1.2  1997/09/09 17:30:35  pean
 * *** empty log message ***
 *
 * Revision 1.1.1.1  1997/05/02 17:15:39  pean
 * Initial release of the microcontroller software after Tiburon
 * Moolpool Dive to test IView, Lapboxes, modified Power can
 * GF/5V using bus capacitance mode.
 *
*/
/****************************************************************************/

#define TEMP_WARN_THRESH           45   /* Temperature Warn Threshold degs  */
#define TEMP_ALARM_THRESH          50   /* Temperature Alarm Threshold degs */
#define TEMPERATURE_HYSTERESIS      5   /* Temeprature Alarm Hystesis degs  */
#define MAX_TEMP_VALUE            120   /* Maximum temperature measurement  */

#define STEPPER_TEMP_WARN_THRESH   75   /* Stepper Temp Warn Threshold degs */
#define STEPPER_TEMP_ALARM_THRESH  85   /* Stepper Temp Alarm Threshold degs*/

#define HUMIDITY_WARN_THRESH       10   /* Set humidity warning to 10% RH   */
#define HUMIDITY_ALARM_THRESH      20   /* Set humidity alarm to 20% RH     */
#define HUMIDITY_HYSTERESIS         2   /* Humidity sensor hysteresis 2%    */

#define LIGHT_PAN                   0   /* Light Pan Index                  */
#define LIGHT_TILT                  1   /* Light Tilt Index                 */
#define CAMERA_PAN                  2   /* Camera Pan Index                 */
#define CAMERA_TILT                 3   /* Camera Tilt Index                */

#define PT_LIGHT_PAN_SERIAL_CHAN    0   /* Light Pan Serial Channel         */
#define PT_LIGHT_TILT_SERIAL_CHAN   1   /* Light Tilt Serial Channel        */
#define PT_CAMERA_PAN_SERIAL_CHAN   2   /* Camera Pan Serial Channel        */
#define PT_CAMERA_TILT_SERIAL_CHAN  3   /* Camera Tilt Serial Channel       */

#define PT_BUFFER_SIZE            128   /* Transmit & Receive Buffer Sizes  */

                                        /* Macro for extracting limit status*/
#define PT_CW_LIMIT(limitSw)    (limitSw & 0x01)
#define PT_CCW_LIMIT(limitSw)   (limitSw & 0x02)

                                        /* Gets P/T Move and Fault bits     */
#define PT_MOVE_BIT(pt)         (0x01 << (pt + pt))
#define PT_FAULT_BIT(pt)        (0x01 << (pt + pt + 1))

                                        /* Macros for identifying the axis  */
#define PT_IS_PAN_AXIS(pt)   ((pt == LIGHT_PAN) || (pt == CAMERA_PAN))
#define PT_IS_PT10(pt)       ((pt == LIGHT_PAN) || (pt == LIGHT_TILT))

#define PT_GEAR_RATIO(pt)    \
            ( PT_IS_PT10(pt) ? PT_10_GEAR_RATIO : PT_25_GEAR_RATIO )

#define PT_MAX_VEL_CMD          5000    /* Maximum value of velocity command*/
#define PT_MOVE_START_TIME         5    /* P/T starts moving in 50 msec     */
#define PT_POSITION_TIMEOUT        8    /* Worst case position data 80 msec */


#define PT_CAL_TABLE_SIZE          74
#define PT_CAL_ENTRIES_PER_PACKET 100

#define GET_TEMPERATURE         0x01    /* Get Temperature Sensor Value     */
#define GET_TEMP_ALARM_STATUS   0x02    /* Get Temperature Alarm Status     */
#define GET_TEMP_ALARM_THRESH   0x03    /* Get Temperature Alarm Threshold  */
#define SET_TEMP_ALARM_THRESH   0x04    /* Set Temperature Alarm Threshold  */

#define GET_HUMIDITY            0x05    /* Get Humidity Sensor Reading      */
#define GET_HUMIDITY_ALARM      0x06    /* Get Humidity Alarm Status        */
#define GET_HUMIDITY_THRESH     0x07    /* Get Humidity Alarm Threshold     */
#define SET_HUMIDITY_THRESH     0x08    /* Set Humidity Alarm Threshold     */

#define GET_WATER_ALARM         0x09    /* Get water alarm status word      */

#define GET_STEPPER_TEMP               0x0a /* Get Stepper Temperature      */
#define GET_STEPPER_TEMP_ALARM         0x0b /* Get Stepper Temp Alarm       */
#define GET_STEPPER_TEMP_ALARM_THRESH  0x0c /* Get Stepper Temp Thresholds  */
#define SET_STEPPER_TEMP_ALARM_THRESH  0x0d /* Set Stepper Temp Thresholds  */

#define SEND_INTERP_TABLE       0x0e   /* Send interpolation table     */
#define INTERP_TABLE_LOADED     0x0f   /* Interpolation table loaded   */

#define INITIALIZE_PT_CTRL      0x10   /* Initialize Pan/Tilt Controller    */
#define GET_PAN_TILT_PARAMS     0x12   /* Get all Pan/Tilt Parameters       */
#define SEND_PAN_TILT_COMMAND   0x13   /* Send command string to pan/tilt   */
#define READ_PAN_TILT_DATA      0x14   /* Read data from pan/tilt           */
#define SET_PT_SETTLING_TIME    0x15   /* Set Pan/Tilt settling time        */
#define CLEAR_PT_FAULT          0x16   /* Clear Pan/Tilt Fault Condition    */
#define HOME_PT_TO_ZERO_POS     0x17   /* Home Pan/Tilt to Zero position    */
#define WRITE_PT_NVRAM          0x18   /* Store Params in Non-volatile RAM  */
#define VELOCITY_MOVE           0x19   /* Move Pan/Tilt to a new position   */
#define POSITION_MOVE           0x1a   /* Move Pan/Tilt to a new position   */
#define GET_PT_LIMIT_SWITCHES   0x1b   /* Get Pan/Tilt limit switch status  */
#define GET_PT_LIMIT_POS        0x1c   /* Get Pan/Tilt limit positions      */
#define SET_PT_LIMIT_POS        0x1d   /* Set Pan/Tilt limit positions      */
#define RESET_PT_CTRL           0x21   /* Reset Stepper Motor Controller    */
#define SET_PAN_TILT_AUTO_CTRL  0x22   /* Set Pan/Tilt automatic control    */
#define CONTROLLER_STRING       0x23   /* Send String to stepper ctrl       */
#define VELOCITY_MOVE_ALL       0x24   /* Move All Pan/Tilts velocity mode  */
#define VELOCITY_MOVE_WITH_FB   0x25   /* Velocity move all with feedback   */

#define GET_PT_STEPPER_POSITIONS 0x26  /* Get all Pan/Tilt Positions        */
#define GET_PT_ANALOG_POSITIONS  0x27  /* Get all Analog Pan/Tilt Positions */
#define CALIBRATE_ATOD           0x28  /* Calibrate A/D Convertor           */

                                  /* Pan & Tilt Application Service Requests*/
#define HUMIDITY_ALARM_SRQ               APPLIC_SRQ_BASE | 0x01
#define TEMPERATURE_ALARM_SRQ            APPLIC_SRQ_BASE | 0x02
#define STEPPER_TEMP_ALARM_SRQ           APPLIC_SRQ_BASE | 0x03
#define PT_FAULT_SRQ                     APPLIC_SRQ_BASE | 0x04
#define PT_MOVE_ERROR_SRQ                APPLIC_SRQ_BASE | 0x05
#define PT_ZERO_POS_ERROR_SRQ            APPLIC_SRQ_BASE | 0x06
#define PT_LIMIT_SWITCH_SRQ              APPLIC_SRQ_BASE | 0x07
