////////////////////////////////////////////////////////////////////
//
// 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"; 
   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             = 1.0 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
   rudLimit              = 12. arcdeg; //15. arcdeg;        //Max rudder angle
   rudDeadband           = .1  arcdeg;        //Degree of rounding in output values
   maxXteInt             = 10. arcdeg;        //Max heading trim
   maxXteOff             = 10. m;             //xte int off above this error

// Pitch:
   maxPitchInt           = 0.1745329 rad;     // max cmded elev from pitch int
   pitchLimit            = 0.523598 rad;      // Max pitch
   kpPitchElevator       = 0.25 n/a;          // Proportional gain  
   kiPitchElevator       = 0.0 1/s;           // Integral gain     
   kdPitchElevator       = 0.05 s;            // Derivative gain           
   elevLimit             = 12. arcdeg;        // max elevator angle
   elevRequired          = 15 arcdeg;         // If the change in pitch is greater
                                              // than this value, use the elevator
   kpPitchMass           = 0.200 n/a;         // Proportional gain  
   kiPitchMass           = 0.010 1/s;         // Integral gain     
   kdPitchMass           = 0.000 s;           // Derivative gain           
   massPositionLimit     = 35 mm; // changed BCK 12/01/2009 34 mm;     // max offset forward or aft of center
   massPositionDelay     = 7.0 s;             // Time (in seconds) after pitch setting change
                                              // to use elevator control.  After this time,
                                              // the elevator is zeroed, and mass control takes over.
   buoyancyOverrideDelay = 300.0 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. 
//
// Depth (Heave/Pitch):
   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.00 rad-s/m;      //Dive loop deriv. gain // was 0.12
// kpDepth               = 0.04 rad/m;        //Dive loop pos'n gain  // was 0.09
// kiDepth               = 0.0008 rad/s/m;    //Dive loop int. gain  // was 0.0008
// kdDepth               = 0.08 rad-s/m;      //Dive loop deriv. gain // was 0.12
   kiDepthOff            = 0.50 m/s;          //Integrator shut-off
   maxDiveRate           = 0.5 m/s;           //was .5 m/s
   maxDepthInt           = 0.0872664 rad;     //max cmded pitch frm depth int


//
// 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
   rudActLimit           = 10000 count;       //Max actuator excursion
   rudActRateLimit       = 1200. count/s;     //
   elevActLimit          = 10000 count;       //Max actuator excursion
   elevActRateLimit      = 1200. count/s;     //
//
// 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  
//
// 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
//

   // Elevator motor controller values
   elevCountsPerDeg      = 454.666 count/arcdeg; //195; //motor "ticks" per degree of control surface motion
   elevMtrCenter         = 8184 count;           //0 degrees "centered" control surface
   elevPIDw              = 1000 count;           // Proportional gain
   elevPIDx              = 250 count;            // Integral gain
   elevPIDy              = 2500 count;           // Differential gain
   elevCurrLimit         = 75 %;                 // Percent of current allowed
   elevMargin            = 1 arcdeg;             // Degrees difference allowed between commanded and actual control surface position
   elevCtrlAddress       = 1 enum;               // Address of the physical motor controller unit on the 485 bus
   elevDeviation         = .25 arcdeg;          // Number of degrees deviation allowed between expected and actual

   // Rudder motor controller values
   ruddCountsPerDeg      = 454.666 count/arcdeg;  //130; 65; // motor "ticks" per degree of control surface motion
   ruddMtrCenter         = 8184 count;            // 0 degrees "centered" control surface
   ruddPIDw              = 1000 count;            // Proportional gain
   ruddPIDx              = 250 count;             // Integral gain
   ruddPIDy              = 2500 count;            // Differential gain
   ruddCurrLimit         = 75 %;                  // Percent of current allowed
   ruddCtrlAddress       = 2 enum;                // Address of the physical motor controller unit on the 485 bus
   ruddDeviation         = .25 arcdeg;            // Number of degrees deviation allowed between expected and actual
// NOTE: For rudder/elevator velocity can currently be set as high as 2000000 with acceleration at 4000. 08/11/209 - Kieft

   // General control surface limits
   mtrLimitHi            = 16369 count;       // High physical limit for motor controllers
   mtrLimitLo            = 0 count;           // Low physical limit for motor controllers
   massLimitHi           = 144180 count;      // High physical limit for mass motor controller
   massLimitLo           = -157965 count;     // Low physical limit for mass motor controller
   
   
   // Thruster motor controller values
   thrustCtrlAddress     = 3 enum;            // Address of the physical motor controller unit on the 485 bus
   thrustCurrLimit       = 100 %;             // Percent of current allowed
   thrustPIDw            = 8000 count;
   thrustPIDx            = 100 count;
   thrustPIDy            = 60000 count;
   thrustTimeout         = 5000 ms;           // Timeout in ms to wait before throwing overload error
   thrustEncoderTks      = 32.768 count/s;    // encoder tick/second multiplier
   tksPerRev             = 32 count/rev;      // encoder ticks/revolution as seen by the controller
                                              // when feeding back HALL A&B to the encoder inputs
   thrustDeviation       = 25 count;          // Number of encoder ticks deviation allowed between expected and actual
   // NOTE: 10" prop = .187706 m per revolution in wake
   // 300 rpm == 1m/sec and 150 rpm == .5m/sec. See propPitch

   // Mass shift motor controller values
   massCtrlAddress       = 4 enum;            // Address of the physical motor controller unit on the 485 bus
   massCurrLimit         = 100 %;             // Percent of current allowed
   massOvrloadTmout      = 1000 ms;           // ms until an overload is reported
   massTks               = 250015 count;      // Total encoder ticks for full mass shift travel
   massTksPerMm          = 2465.8859 count/mm;// Number of ticks for one rotation (1 mm of travel)
   massAccel             = 20000 n/a;         // Encoder ticks / 32.768 per second squared
   massVelocity          = 60000 n/a;         // Encoder ticks / 32.768 per scond 
   massDeviation         = 0.5 mm;            // Deviation allowed between expected and actual
   massDefault           = 0.0 cm;          // Position of mass at pitch=0 at neutral buoyancy

   // 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;

   buoyancyCtrlAddress   = 6 enum;           // Address of the physical motor controller unit on the 485 bus
   buoyancyCurrLimit     = 100 %;            // Percent of current allowed
   buoyancyOvrloadTmout  = 2000 ms;          // ms until an overload is reported   
   buoyancyPIDw          = 1500 count;
   buoyancyPIDx          = 0 count;
   buoyancyPIDy          = 3000 count;
   buoyancyVelocity      = 800 n/a;
   buoyancyAccel         = 800 n/a;
   buoyancyDefault       = 945.0 cc;         // default amount of oil to be stored in the bladder
   buoyancyNeutral       = 300.0 cc;         // amount of oil stored in the bladder when the vehicle is neutral
   buoyancyCountsPerCC   = 7.446016 count/cc;// counts on the A/D per ml of fluid pumped
   buoyancyLimitHi       = 7841 count;       // High physical limit for motor controllers
   buoyancyLimitLo       = 350  count;       // Low physical limit for motor controller  
   buoyancyLimitHiCC     = 955 cc;           // High limit for oil. Should be less than the above physical limit for motor controller
   buoyancyLimitLoCC     = 80  cc;           // Low limit for oil. Should be less than the above physical limit for motor controller
   buoyancyPumpDepth     = 100.0 m;          // Depth must be <= this value in order to safely pump
   buoyancyDeviation     = 10.0 cc;          // Number of ml deviation allowed between expected and actual   
   buoyancyCheckingTimeout = 5.0 min;        // If the buoyancy is idling, this is how often to check for actual position. If there's a leak. This is when we'll find it. 
   
   surfaceThreshold      = 0.2 m;            // Depth at which we consider ourselves on the "surface"
   batteryThreshold      = 20 Ah;            // Amount of charge left at which we return to the surface
   
   BITHumidityThreshold  = 30 %;             // relative humidity
   BITPressureThreshold  = 12 psi;           // Onboard Pressure
   CBITAbortDepthTimeout = 10 s;             // If this time has elapsed and we're still below abort depth, drop the weight

   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; 
   AHRS_sp3003D_deviation     = 0 arcdeg;

   // DVL_NavQuest600 uses Load Controller 2 switch, Onboard UART 3 (ttyS1).
   DVL_NavQuest600_card       = "/dev/loadcontrol_2";
   DVL_NavQuest600_uart       = "/dev/ttyS1"; 
   DVL_NavQuest600_baud       = 115200 bps;
   
   // NAL9601 uses Load Controller 3 switch, Onboard UART 4 (ttyS2).
   NAL9601_card               = "/dev/loadcontrol_3";
   NAL9601_uart               = "/dev/ttyS2"; 
   NAL9601_baud               = 19200 bps;
   
   // Console & Radio_Freewave uses Load Controller 4 switch, Onboard UART 5  (ttyS0).
   Radio_Freewave_card        = "/dev/loadcontrol_4";
   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    = 9600 bps; 
   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      = 9600 bps; 
   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    = 9600 bps; 
   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        = 9600 bps; 
   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    = 9600 bps; 
   BuoyancyServo_address = 5 enum;
   
   // AHRS_3DMGX1 uses Load Controller 10 switch and UART.
   AHRS_3DMGX1_card          = "/dev/loadcontrol_10";
   AHRS_3DMGX1_uart          = "/dev/ttyMAX5";
   AHRS_3DMGX1_baud          = 115200 bps; 
   AHRS_3DMGX1_deviation     = 0 arcdeg;
   
   // CTD_NeilBrown uses Load Controller 11 switch and UART.
   CTD_NeilBrown_card         = "/dev/loadcontrol_11";
   CTD_NeilBrown_uart         = "/dev/ttyMAX4";
   CTD_NeilBrown_baud         = 9600 bps;
   CTD_NeilBrown_offset       = 0.755 decibar;
   
   // Optical_BBFL2 uses Load Controller 12 switch and UART.
   Optical_BBFL2_card         = "/dev/loadcontrol_12";
   Optical_BBFL2_uart         = "/dev/ttyMAX12";
   Optical_BBFL2_baud         = 9600 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;
   
   // Nitrate_ISUS uses Load Controller 14 switch and UART.
   Nitrate_ISUS_LR_card       = "/dev/loadcontrol_14";
   Nitrate_ISUS_LR_uart       = "/dev/ttyMAX14";
   Nitrate_ISUS_baud          = 57600 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       = 2.5 V;
   MainGroundfault_res        = 12 bit;
      
   // RudderCompensatorLow uses Motherboard SPI A/D 3.
   RudderCompensatorLow_ad     = "/dev/ad7888_3";
   RudderCompensatorLow_vref   = 2.5 V;
   RudderCompensatorLow_res    = 12 bit;

   // ElevatorCompensatorLow uses Motherboard SPI A/D 4.
   ElevatorCompensatorLow_ad   = "/dev/ad7888_4";
   ElevatorCompensatorLow_vref = 2.5 V;
   ElevatorCompensatorLow_res  = 12 bit;
   
