syntax = "proto2";

import "goby/middleware/protobuf/app_config.proto";
import "goby/zeromq/protobuf/interprocess_config.proto";
import "goby/middleware/protobuf/transporter_config.proto";
import "dccl/option_extensions.proto";
import "jaiabot/messages/health.proto";
import "jaiabot/messages/mission.proto";
import "jaiabot/messages/camera_driver.proto";

package jaiabot.config;

message MissionManager
{
    option (dccl.msg) = {
        unit_system: "si"
    };
    optional goby.middleware.protobuf.AppConfig app = 1;
    optional goby.zeromq.protobuf.InterProcessPortalConfig interprocess = 2;

    required int32 fleet_id = 9;
    required int32 bot_id = 10;
    required goby.middleware.protobuf.TransporterConfig command_sub_cfg = 11;
    optional goby.middleware.protobuf.TransporterConfig contact_update_sub_cfg =
        13;

    // timeout to allow all applications to report HEALTH__OK
    optional double startup_timeout = 12
        [default = 120, (dccl.field).units = { base_dimensions: "T" }];

    // powered ascent motor on timeout
    optional int32 powered_ascent_motor_on_timeout = 25
        [default = 5, (dccl.field).units = { base_dimensions: "T" }];

    // powered ascent motor off timeout
    optional int32 powered_ascent_motor_off_timeout = 26
        [default = 2, (dccl.field).units = { base_dimensions: "T" }];

    // timeout on dive prep to then transition to powered descent
    optional int32 dive_prep_timeout = 27
        [default = 10, (dccl.field).units = { base_dimensions: "T" }];

    // safety timeout on powered descent to then transition to unpowered descent
    optional int32 powered_descent_timeout = 28
        [default = 100, (dccl.field).units = { base_dimensions: "T" }];

    // detect bottom logic initial timeout in seconds. Used to determine
    // when we should start determining we reached bottom in powered descent
    // logic. (this gives the vehicle time to begin diving)
    optional double detect_bottom_logic_init_timeout = 29
        [default = 15, (dccl.field).units = { base_dimensions: "T" }];

    // detect bottom logic timeout in seconds. Used to determine
    // when we should start determining we reached bottom in powered descent
    // logic. (this gives the vehicle time to begin diving after a hold)
    optional double detect_bottom_logic_after_hold_timeout = 30
        [default = 5, (dccl.field).units = { base_dimensions: "T" }];

    // acceptable eps when dive depth is considered reached (in meters)
    optional double dive_depth_eps = 31
        [default = 0.1, (dccl.field).units = { base_dimensions: "L" }];

    // bottoming timeout in seconds without depth change greater than
    // dive_depth_eps before assuming the bottom has been hit
    optional double bottoming_timeout = 32
        [default = 3, (dccl.field).units = { base_dimensions: "T" }];

    // acceptable eps when dive surface is considered reached (in meters)
    optional double dive_surface_eps = 33
        [default = 0.75, (dccl.field).units = { base_dimensions: "L" }];

    // number of times to check the gps hdop and pdop
    // when in reacquiring gps state
    optional uint32 total_gps_fix_checks = 34 [default = 10];

    // number of times to check the gps hdop and pdop
    // while in transit to go into reacquiring gps state
    optional uint32 total_gps_degraded_fix_checks = 35 [default = 2];

    // The hdop value to check against to determine gps fix
    optional double gps_hdop_fix = 36 [default = 1.3];

    // The pdop value to check against to determine gps fix
    optional double gps_pdop_fix = 37 [default = 2.2];

    // number of times to check the gps hdop and pdop
    // when in reacquiring gps state after a dive
    optional uint32 total_after_dive_gps_fix_checks = 38 [default = 15];

    // The hdop value to check against to determine gps fix after a dive
    optional double gps_after_dive_hdop_fix = 39 [default = 1.3];

    // The pdop value to check against to determine gps fix after a dive
    optional double gps_after_dive_pdop_fix = 40 [default = 2.2];

    // Min depth safety behavior
    optional double min_depth_safety = 41 [default = -1];

    // Time factor used to increase/decrease time to travel to goal
    optional double goal_timeout_buffer_factor = 44 [default = 1];

    // The number of reacquire attempts used to calculate goal timeout
    optional uint32 goal_timeout_reacquire_gps_attempts = 45 [default = 2];

    // Number of good gps locations to keep
    optional uint32 tpv_history_max = 46 [default = 15];

    // Used to indicate to use goal timeout
    optional bool use_goal_timeout = 47 [default = false];

    // Skip goal task if the bot timeouts trying to get to the goal
    optional bool skip_goal_task = 48 [default = false];

    // States to detect goal timeout
    repeated jaiabot.protobuf.MissionState include_goal_timeout_states = 49;

    enum RemoteControlSetpointEnd
    {
        RC_SETPOINT_ENDS_IN_STATIONKEEP = 1;
        RC_SETPOINT_ENDS_IN_SURFACE_DRIFT = 2;
    }
    optional RemoteControlSetpointEnd rc_setpoint_end = 50
        [default = RC_SETPOINT_ENDS_IN_STATIONKEEP];

    optional uint32 imu_restart_seconds = 51 [default = 15];

    // Bot not rising timeout in seconds without depth change greater than
    // dive_depth_eps before assuming the bot is stuck and is not rising
    optional double bot_not_rising_timeout = 52
        [default = 6, (dccl.field).units = { base_dimensions: "T" }];

    // If the bot is not rising then increment the motor on time
    optional int32 motor_on_time_increment = 53
        [default = 1, (dccl.field).units = { base_dimensions: "T" }];

    // The max the motor should be on for powered ascent
    optional int32 motor_on_time_max = 54
        [default = 10, (dccl.field).units = { base_dimensions: "T" }];

    // The power ascent throttle
    optional double powered_ascent_throttle = 55 [default = 25];

    // The power ascent throttle increment
    optional double powered_ascent_throttle_increment = 56 [default = 5];

    // The power ascent max thottle
    optional double powered_ascent_throttle_max = 57 [default = 60];

    optional double pitch_to_determine_powered_ascent_vertical = 58
        [default = 30];

    optional double pitch_to_determine_dive_prep_vertical = 59 [default = 70];

    optional int32 pitch_angle_checks = 60 [default = 3];

    // The min amount of time to trigger a EvBotNotVertical event
    optional double pitch_angle_min_check_time = 61
        [default = 1, (dccl.field).units = { base_dimensions: "T" }];

    // acceptable eps when we consider the bot diving (in meters)
    optional double dive_eps_to_determine_diving = 62
        [default = 0.3, (dccl.field).units = { base_dimensions: "L" }];

    required string data_preoffload_script = 70;
    required string data_postoffload_script = 71;

    // e.g. /var/log/jaiabot/bot/*/
    required string log_dir = 72;

    optional string log_staging_dir = 73 [
        default = "/var/log/jaiabot/staging"
    ];  // dir on bot with data to be offloaded

    optional string log_archive_dir = 74
        [default = "/var/log/jaiabot/archive"];  // archived bot data

    enum DownloadFileTypes
    {
        NONE = 1;
        GOBY = 2;
        TASKPACKET = 3;
    }
    optional DownloadFileTypes data_offload_exclude = 75;

    enum EngineeringTestMode
    {
        ENGINEERING_TEST__ALWAYS_LOG_EVEN_WHEN_IDLE = 1;
        ENGINEERING_TEST__IGNORE_SOME_ERRORS = 2;
        ENGINEERING_TEST__INDOOR_MODE__NO_GPS = 3;
    }
    repeated EngineeringTestMode test_mode = 80;

    // errors to ignore,
    // only when test_mode: ENGINEERING_TEST__IGNORE_SOME_ERRORS
    repeated jaiabot.protobuf.Error ignore_error = 81;

    optional bool is_sim = 82 [default = false];
    
    // Determines if the acceleration is hard or soft
    optional double hard_bottom_type_acceleration = 84 [default = 100];

    // timeout for when to stop logging if in failed state
    optional int32 failed_startup_log_timeout = 85
        [default = 300, (dccl.field).units = { base_dimensions: "T" }];

    // used to update transitting to waypoint to allow more overshoot
    optional int32 waypoint_with_no_task_slip_radius = 86 [default = 15];

    // used to update transitting to waypoint to allow less overshoot
    optional int32 waypoint_with_task_slip_radius = 87 [default = 5];

    message ResolveNoForwardProgress
    {
        // time after going into ResolveNoForwardProgress to resume attempting
        // to move
        optional int32 resume_timeout = 1
            [default = 10, (dccl.field).units = { base_dimensions: "T" }];

        // angle above which the vehicle is assumed to not be making forward
        // progress, below which it is
        optional int32 pitch_threshold = 2 [
            default = 30,
            (dccl.field).units = {
                derived_dimensions: "plane_angle"
                system: "angle::degree"
            }
        ];

        // desired speed above which the vehicle is expected to be making
        // forward progress
        optional int32 desired_speed_threshold = 3
            [default = 0, (dccl.field).units = { base_dimensions: "LT^-1" }];

        // time after desired speed > desired_speed_threshold but pitch
        // > pitch_threshold that triggers EvNoForwardProgress
        optional int32 trigger_timeout = 4
            [default = 15, (dccl.field).units = { base_dimensions: "T" }];
    }

    optional ResolveNoForwardProgress resolve_no_forward_progress = 88;

    required uint32 subnet_mask = 89;

    optional jaiabot.protobuf.CameraCommand start_camera_command = 90;
    optional jaiabot.protobuf.CameraCommand stop_camera_command = 91;

    optional bool camera_available = 92 [default = false];
    
    // The distance from the pressure sensor to the waterline
    optional double pressure_sensor_to_waterline = 93 
        [default = 0.4572, (dccl.field).units = { base_dimensions: "L" }];

    // The distance from the pressure sensor to the end of the tail
    optional double pressure_sensor_to_tail = 94
        [default = 0.3683, (dccl.field).units = { base_dimensions: "L" }];
        
    optional int32 min_subsurface_current_vector_hold_time = 95 [default = 10];
    optional int32 min_subsurface_current_vector_drift_time = 96 [default = 15];
}
