////////////////////////////////////////////////////////////////////
//
// PURPOSE: List of vehicle parameters, such as mass properties.
//
// DATE:    2009/12/08
//
// NOTES:   All values (except "strings") must be followed by
//          a unit abbreviation (or one of the unit-like
//          abbreviations: n/a, bool, enum, count). 
//
//          The control gains are adjusted for an Easy-Servo sampling 
//          period of 2 seconds.
//
//
////////////////////////////////////////////////////////////////////
//
   name                  = "Tethys"; 
   keyText               = "TethysEncryption"; //A 16-byte encryption key. Up to 32 bytes are more secure.

   id                    = 0 enum;
   Ts                    = .2 s;              //Control system sampling prd.

// propPitch             = 0.02987 m/rad;     //This is the water advance in the wake. Not vehicle speed through water
   propPitch             = 0.0318309 m/rad;   //Corrected value to achieve 300rpm/150rpm for high/low speed. Units are Meters/rad
   tau                   = 2.5 s;             //Command generator time const.
//
// Heading (Sway/Yaw):
   kpHeading             = 0.4 n/a;           //Position gain, 
   kdHeading             = 0.05 s;            //Rate gain           
   kwpHeading            = .05 rad/m;         //Cross-track error gain
   kiHeading             = 0.001 1/s;         //Integral gain     
// kiwp                  = 0.002 rad/s/m;     //crs trk intgrl gain
   maxHdgRate            = 0.2094395 rad/s;   //Max turn rate
   maxHdgInt             = 0.0872664 rad;     //max cmded rudder from hdg int
   maxXteInt             = 10. arcdeg;        //Max heading trim
   maxXteOff             = 10. m;             //xte int off above this error

// Pitch:
   maxPitchElevatorInt   = 0.1745329 rad;     // max cmded elev from pitch int
   pitchLimit            = 30.0 arcdeg;       // Max pitch
   kpPitchElevator       = 0.25 n/a;          // Proportional gain  
   kiPitchElevator       = 0.008 1/s;         // Integral gain     
   kdPitchElevator       = 0.05 s;            // Derivative gain           

   maxPitchMassInt       = 20 mm;             // max cmded mass posn from pitch int
   kpPitchMass           = 0.100 n/a;         // Proportional gain  
   kiPitchMass           = 0.002 1/s;         // Integral gain     
   kdPitchMass           = 0.200 s;           // Derivative gain           

   buoyancyOverrideDelay = 300 s;             // If we are requesting upwards motion,
                                              // and haven't achieved it within this time
                                              // maximize the buoyancy to go up. 
   dropWtOverrideDelay   = 15 min;            // If we are requesting upwards motion,
                                              // and haven't achieved it within this time
                                              // drop the drop weight to go up.
   depthRateSamples      = 20 count;          // Number of depth rate samples to average. 
   depthRateDeadband     = 0.02 m/s;          // Values less than this value are 
                                              // considered to be zero. 

   GPSFailTimeout        = 15 min;            // Time to wait for GPS prior to throwing a failure

//
// Depth control:
   kpDepth               = 0.07 rad/m;        //Dive loop pos'n gain  // was 0.09
   kiDepth               = 0.002 rad/s/m;     //Dive loop int. gain  // was 0.0008
   kdDepth               = 0.0 rad-s/m;       //Dive loop deriv. gain // was 0.12
   kiDepthOff            = 0.10 m/s;          //Integrator shut-off
   maxDepthInt           = 20. arcdeg;        //max cmded pitch frm depth int
//
// Buoyancy control:
   kpDepthBuoy           = 30. ratio;         //Buoyancy loop pos'n gain cc/m
   kiDepthBuoy           = 1.0 1/s;           //Buoyancy loop int. gain 
   kdDepthBuoy           = 5000.0 s;          //B loop deriv. gain cc/(m/s)
   maxBuoyInt            = 200.0 cc;          //Maximum buoyancy int. value
   depthDeadband         = .01 m;             //Buoy loop off within deadband
//
   maxDiveRate           = 0.5 m/s;           

//
// Flags:
   sendDataToShore       = 1 bool;           // If true, radio data to shore over Iridium
   decouple              = 0 bool;           // Decouple heading and depth control
   altimeterInstrument   = 0 enum;           // 0 => DVL, 1 => PSA
   useLbl                = 0 bool;           // 0 => log only; 1 => Use for control
   useIns                = 0 bool;
//
// Not used?
   kiHeadingLimit        = 5. arcdeg;         //Limit on integral term
   kiPitchLimit          = 10. arcdeg;        //Limit on integral term

//
// Mass Properties:
// mass                  = 136.0 kg;          //Flooded Vehicle mass ( x 9.80665 m/s2 = 1333.7044 N)
// volume                = 0.1330 m3;         //m3 (equals 1337 N buoyancy in 1025 kg/m3 water)
                                              //excludes buoyancy bladder at default setting  
   mass                  = 147.8671 kg;       //Flooded Vehicle mass ( x 9.80665 m/s2 = 1450.0 N)
//
   volume                = 0.144260585365854 m3; //m3 (equals 1450 N buoyancy in 1025 kg/m3 water)
                                                 //excludes buoyancy bladder at default setting  
//
// Stability Derivatives:
   effDragCoef           = .21 n/a;           //veh drag in x; related to Xuu
   Xuabu                 = -6.2282 kg/m;      //Force Derivative, > -6.98 kg/m because fin drag added separately

//
// Geometric Parameters (Used only by the simulation)
//
// The following y & z CG values were measured on 1 June, for the 1st Octans
// test.  The x value is computed.
//
   centerOfMassX         = 0.1181 m;
   centerOfMassY         = -0.000236 m;
   centerOfMassZ         = 0.006794 m;

   centerOfBuoyX         = 0.1181 m;
   centerOfBuoyY         = 0.0 m;
   centerOfBuoyZ         = 0.0 m;

// Simple geometric model of vehicle (Used at the surface)
   cylinderLength        = 2 m;
   cylinderRadius        = 6 in;

//
// We still have the 4 fin Odyssey tailcone model here.  The X displacement has
// been adjusted for the 389 vehicle.
//
   lowerRudX             = -1.973 m;
   lowerRudY             = 0.012 m;
   lowerRudZ             = -0.152 m;

   upperRudX             = -1.973 m;
   upperRudY             = 0.012 m;
   upperRudZ             = 0.152 m;

   portElevX             = -1.973 m;
   portElevY             = -0.152 m;
   portElevZ             = 0.0 m;

   stbdElevX             = -1.973 m;
   stbdElevY             = 0.152 m;
   stbdElevZ             = 0.0 m;
   
   // Thruster parameters 
   designSpeed           = 1.0 m/s;           //Nominal speed
   designPropEff         = 0.86 n/a;          //Nominal prop efficiency
   designOmega           = 300 rpm;           //Nominal prop rotation rate
   designThrust          = 6.98 N;            //Thrust at nominal omega
   designTorque          = 0.23 N-m;          //Thrust at nominal thrust

   // Dropweight1 parameters
   dropWt1Volume         = 0.0000881 m3;       //Volume of the drop weight #1, m3
   dropWt1Mass           = 1.0 kg;            //Mass of the drop weight #1, kg
   dropWt1X              = 0.1655 m;          //X location of the drop weight #1, m
   dropWt1Y              = 0.0 m;             //Y location of the drop weight #1, m
   dropWt1Z              = -0.20 m;           //Z location of the drop weight #1, m

//
// TEST AREA FOR USER LEVEL DRIVERS
//

   // Mass shift control values
   movableMass           = 26 kg;             // Kilograms of movable mass (~ 1/3 of vehicle mass )

   centerOfMovableMassX = 0.1181 m;
   centerOfMovableMassY = -0.000236 m;
   centerOfMovableMassZ = 0.006794 m;
   
   surfaceThreshold      = 0.5 m;            // Depth at which we consider ourselves on the "surface"
   batteryCapacityThreshold  = 30 Ah;        // Amount of charge left at which we return to the surface
   batteryVoltageThreshold  = 12.8 V;        // Amount of voltage left at which we return to the surface
   
   BITHumidityThreshold  = 55 %;             // relative humidity
   BITPressureThreshold  = 14 psi;           // Onboard Pressure
   CBITAbortDepthTimeout = 10 s;             // If this time has elapsed and we're still below abort depth, drop the weight, end the mission.
   CBITBattFailTimeout   = 10 s;             // If this time has elapsed and we still don't have main battery discrete, drop the weight, end the mission.
   CBITEnvTimeout        = 10 s;             // If this time has elapsed and pressure or humidity are still above threshold, end the mission. 

   abortDepth            = 450 m;            // Depth at which we drop the weight. Should be greater than all depth envelopes
      

//   
// Data and Load Controller Settings
// 
// ("NAME" should match the name specified in component interface header)
//
// NAME-card: 
//     Load Controller device, if any -- something like /dev/loadcontrol_#
// NAME-uart:  
//     Uart device, if any -- something like /dev/ttyS#, ttyTX# or ttyMAX#
// NAME-ad: 
//     A/D device, if any -- something like /sys/class/hwmon/hwmon0/device/? 
// NAME-baud:
//    Baud rate for uart
// NAME-address: 
//    Address for RS-485 buses  
// NAME-vref: 
//    VRef for for A/D devices  
//     

   // Depth_MSI_US300 uses Load Controller 0 A/D and switch
   Depth_MSI_US300_card       = "/dev/loadcontrol_0";
   Depth_MSI_US300_ad         = "/dev/mcp3553_0";
   Depth_MSI_US300_timeout    = 70 ms;
   Depth_MSI_US300_vref       = 5.0 V;
   Depth_MSI_US300_res        = 21 bit;

   // AHRS_sp3003D uses Load Controller 1 switch, Onboard UART 2 (ttyTX1).
   AHRS_sp3003D_card          = "/dev/loadcontrol_1";
   AHRS_sp3003D_uart          = "/dev/ttyTX1"; 
   AHRS_sp3003D_baud          = 9600 bps; 

   // DVL_NavQuest600 uses Load Controller 2 switch, Onboard UART 3 (ttyS1).
   DVL_NavQuest600_card       = "/dev/loadcontrol_3";
   DVL_NavQuest600_uart       = "/dev/ttyS1"; 
   DVL_NavQuest600_baud       = 115200 bps;
   
   // NAL9601 uses Load Controller 3 switch, Onboard UART 4 (ttyS2).
   NAL9601_card               = "/dev/loadcontrol_2";
   NAL9601_uart               = "/dev/ttyS2"; 
   NAL9601_baud               = 19200 bps;
   
   // Console & Radio_Freewave uses Load Controller 10 switch, Onboard UART 5  (ttyS0).
   Radio_Freewave_card        = "/dev/loadcontrol_10";
   Radio_Freewave_uart        = "/dev/ttyS0"; 
   Radio_Freewave_baud        = 115200 bps;
   
   // Elevator uses Load Controller 5 switch, Onboard UART 6 (ttyS3), RS-4853 1.
   ElevatorServo_card    = "/dev/loadcontrol_5";
   ElevatorServo_uart    = "/dev/ttyS3"; 
   ElevatorServo_baud    = 115200 bps; //*** THIS IS TEMPORARILY HARDCODED IN EZServoServo UNTIL LOAD CONTROLLERS ARRIVE
   ElevatorServo_address = 1 enum;
   
   // Rudder uses Load Controller 6 switch, Onboard UART 6 (ttyS3), RS-485# 2.
   RudderServo_card      = "/dev/loadcontrol_6"; 
   RudderServo_uart      = "/dev/ttyS3"
   RudderServo_baud      = 115200 bps; //*** THIS IS TEMPORARILY HARDCODED IN EZServoServo UNTIL LOAD CONTROLLERS ARRIVE
   RudderServo_address   = 2 enum;
   
   // Thruster uses Load Controller 7 switch, Onboard UART 6 (ttyS3), RS-485# 3.
   ThrusterServo_card    = "/dev/loadcontrol_7";
   ThrusterServo_uart    = "/dev/ttyS3"
   ThrusterServo_baud    = 115200 bps; //*** THIS IS TEMPORARILY HARDCODED IN EZServoServo UNTIL LOAD CONTROLLERS ARRIVE
   ThrusterServo_address = 3 enum;
   
   // Movable Mass uses Load Controller 8 switch, Onboard UART 6 (ttyS3), RS-485# 4.
   MassServo_card        = "/dev/loadcontrol_8";
   MassServo_uart        = "/dev/ttyS3"
   MassServo_baud        = 115200 bps; //*** THIS IS TEMPORARILY HARDCODED IN EZServoServo UNTIL LOAD CONTROLLERS ARRIVE
   MassServo_address     = 4 enum;
   
   // Buoyancy uses Load Controller 8 switch, Onboard UART 6 (ttyS3), RS-485# 5.
   BuoyancyServo_card    = "/dev/loadcontrol_9";
   BuoyancyServo_uart    = "/dev/ttyS3"
   BuoyancyServo_baud    = 115200 bps; //*** THIS IS TEMPORARILY HARDCODED IN EZServoServo UNTIL LOAD CONTROLLERS ARRIVE
   BuoyancyServo_address = 6 enum;
   
   // AHRS_3DMGX3 uses Load Controller 10 switch and UART.
   AHRS_3DMGX3_card          = "/dev/loadcontrol_10";
   AHRS_3DMGX3_uart          = "/dev/ttyMAX5";
   AHRS_3DMGX3_baud          = 115200 bps; 
   
   // CTD_NeilBrown uses Load Controller 12 switch and UART.
   CTD_NeilBrown_card         = "/dev/loadcontrol_12";
   CTD_NeilBrown_uart         = "/dev/ttyMAX4";
   CTD_NeilBrown_baud         = 9600 bps;
   
   // WetLabsBB2FL uses Load Controller 5 switch and UART.
   WetLabsBB2FL_card          = "/dev/loadcontrol_5";
   WetLabsBB2FL_uart          = "/dev/ttyMAX5";
   WetLabsBB2FL_baud          = 19200 bps;
   
   // Oxygen_Optode_4330 uses Load Controller 13 switch and UART.
   Oxygen_Optode_4330_card    = "/dev/loadcontrol_13";
   Oxygen_Optode_4330_uart    = "/dev/ttyMAX13";
   Oxygen_Optode_4330_baud    = 9600 bps;
   
   // ISUS uses Load Controller 11 switch and UART.
   ISUS_card       = "/dev/loadcontrol_11";
   ISUS_uart       = "/dev/ttyMAX11";
   ISUS_baud       = 38400 bps;

   // USB_80211B uses Load Controller 15 switch, onboard USB.
   USB_80211B_card            = "/dev/loadcontrol_15";

   // BatteryManagementA uses Onboard UART 1 (ttyTX0).
   BatteryManagementA_uart    = "/dev/ttyTX0"
   BatteryManagementA_baud    = 19200 bps;

   // BatteryManagementA uses Onboard UART 7 (ttyTX2).
   BatteryManagementB_uart    = "/dev/ttyTX2"
   BatteryManagementB_baud    = 19200 bps;

   // Onboard Humidity uses Processor A/D 0.
   OnboardHumidity_ad         = "/dev/adlpc32xx_0";
   OnboardHumidity_vref       = 3.15 V;
   OnboardHumidity_res        = 10 bit;
      
   // Onboard Temperature uses Processor A/D 1.
   OnboardTemperature_ad      = "/dev/adlpc32xx_1";
   OnboardTemperature_vref    = 3.15 V;
   OnboardTemperature_res     = 10 bit;

   // Onboard Pressure uses Processor A/D 2.
   OnboardPressure_ad         = "/dev/adlpc32xx_2";
   OnboardPressure_vref       = 3.15 V;
   OnboardPressure_res        = 10 bit;


   // MainGroundfault uses Motherboard SPI A/D 0.
   MainGroundfault_ad         = "/dev/ad7888_0";
   MainGroundfault_vref       = 3.15 V;
   MainGroundfault_res        = 12 bit;

   // Battery current uses Motherboard SPI A/D 1.
   secondaryBatteryCurrent_ad     = "/dev/ad7888_1";
   secondaryBatteryCurrent_vref   = 3.15 V;
   secondaryBatteryCurrent_res    = 12 bit;

   // Battery current uses Motherboard SPI A/D 1.
   emergencyBatteryCurrent_ad     = "/dev/ad7888_2";
   emergencyBatteryCurrent_vref   = 3.15 V;
   emergencyBatteryCurrent_res    = 12 bit;
      
   // Motherboard 5V current uses Motherboard SPI A/D 3.
   motherboard5VCurrent_ad     = "/dev/ad7888_3";
   motherboard5VCurrent_vref   = 3.15 V;
   motherboard5VCurrent_res    = 12 bit;

   // Motherboard 3.15V current uses Motherboard SPI A/D 4.
   motherboard3_15VCurrent_ad   = "/dev/ad7888_4";
   motherboard3_15VCurrent_vref = 3.15 V;
   motherboard3_15VCurrent_res  = 12 bit;
   
   // Motherboard 3.3V current uses Motherboard SPI A/D 5.
   motherboard3_3VCurrent_ad   = "/dev/ad7888_5";
   motherboard3_3VCurrent_vref = 3.15 V;
   motherboard3_3VCurrent_res  = 12 bit;

   // Motherboard 1.8V current uses Motherboard SPI A/D 6.
   motherboard1_8VCurrent_ad   = "/dev/ad7888_6";
   motherboard1_8VCurrent_vref = 3.15 V;
   motherboard1_8VCurrent_res  = 12 bit;

   // Solder pad V45 uses Motherboard SPI A/D 7.
//   ElevatorCompensatorLow_ad   = "/dev/ad7888_7";
//   ElevatorCompensatorLow_vref = 3.15 V;
//   ElevatorCompensatorLow_res  = 12 bit;
         
