#ifndef _TAILCONE_H
#define _TAILCONE_H

/****************************************************************************/
/* Copyright (c) 2000 MBARI.                                                */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  : Tailcone Controller                                           */
/* Filename : tailcone.h                                                    */
/* Author   : Andrew Pearce                                                 */
/* Project  : Dorado AUV Tailcone                                           */
/* Version  : 1.0                                                           */
/* Created  : 01/19/00                                                      */
/* Modified : 01/19/00                                                      */
/* Archived :                                                               */
/****************************************************************************/


/* Maximum number of short words in a reply (after converting from string) */
#define MAX_PARAM_WORDS         8

/* Characters in each field of serial ascii buffer */
#define BUFFER_FIELD_WIDTH      4

/* Maximum number of words in Tailcone Message */
#define MAX_NUM_OF_WORDS       22

/* Motor Control Constants */
#define MOTOR_OFFSET           121

/*************** Tailcone Device Serial Channel assignments *****************/

#define RUDDER_SER_CHAN         0
#define ELEVATOR_SER_CHAN       1
#define PROP_MOTOR_SER_CHAN     2

/************ Tailcone Low Power Switch Board Channel assignments **********/

#define RUDDER_LPS_CHAN         0
#define ELEVATOR_LPS_CHAN       1
#define PROP_MOTOR_LPS_CHAN     2

/****************************** Tailcone Commands from MVC *****************/
#define SET_MOTOR_SPEED         0x31
#define SET_ELEVATOR_POS        0x32
#define SET_RUDDER_POS          0x33
#define SET_CONTROL_VALUES      0x34
#define INITIALIZE_TAILCONE     0x35
#define SET_DEADMAN_TIMEOUT     0x36
#define SAVE_CONFIG_TO_NVRAM    0x37

#define GET_MOTOR_RPM           0x38
#define GET_ACTUATOR_POS        0x39
#define GET_CONTROL_STATUS      0x3A
#define GET_HEALTH_STATUS       0x3B
#define GET_ENG_TELEMETRY       0x3C
#define GET_TEMPERATURE         0x3D
#define GET_CURRENT_READINGS    0x3E
#define GET_GND_FAULT_CURRENT   0x3F
#define GET_CONFIGURATION       0x40
#define DEBUG                   0x41
#define ERR_INVLD_PKT           0x42    /* malformed packet recieved */
#define ERR_UNKN_CMD            0x43    /* unknown command sent */ 

/****************************** Internal Constants *************************/

#define CTRL_SURFACE_CTRL_PERIOD 2      /* 50Hz control rate               */

#define LIN_ACT_POT_TURNS_PER_INCH  12  /* Linear actuator pot turns/inch  */
#define LIN_ACT_STEPS_PER_TURN     200  /* Linear actuator steps/turn      */

#define LIN_ACT_STEPS_PER_INCH  \
    (LIN_ACT_STEPS_PER_TURN * LIN_ACT_POT_TURNS_PER_INCH)

                                        /* 25.4 mm per inch                */
#define LIN_ACT_STEPS_PER_MM ((LIN_ACT_STEPS_PER_INCH * 254) / 10)

     /* 8 bit A/D. 2 inches of travel = 5v = 4800 (ie 12 * 200 * 2) steps  */
#define LIN_ACT_BITS_TO_STEPS  ((Int16) ((((Int32) bits) * 4800L) / 256))

#define LIN_ACT_BITS_TO_MM     \
    (LIN_ACT_BITS_TO_STEPS(bits) * LIN_ACT_STEPS_PER_MM)



     /*************************************************************/
     /**   Coefficients for 2nd order linear approximation of    **/
     /**   the functions that describe number of steps required  **/
     /**   to achieve a given change in angle of the 'elevator'  **/ 
     /**   and 'rudder'                                          **/   

           #define Elv1  1.0
           #define Elv2  0.25
    
           #define Rud1  1.0
           #define Rud2  0.25
             
     /***************************************************************

#define LINK_TIMEOUT 100           /* 10 Seconds                     */


#if 0
     /** function defs **/

Int16 initializePropMotor(sv203Struct *propMotor, Nat16 serialChan);

Int16 initializeControlSurface(stpStruct *ctrlSurface, Nat16 serialChan);
#endif




#endif







