# Copyright 2020 Makani Technologies LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Automatically generated hover controllers.

This file was generated by:
  analysis/control/generate_hover_controllers.m
"""

from makani.control import control_types as m


def GetHoverControllers(wing_serial):
  """Returns the hover controller gains."""
  if wing_serial == m.kWingSerial01:
    low_altitude = {
        'kp': 1.79e+03,
        'ki': 127.,
        'kd': 6.33e+03
    }
    high_altitude = {
        'kp': 687.,
        'ki': 40.6,
        'kd': 2.91e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.52e+04,
        'ki': 1.07e+03,
        'kd': 2.06e+04
    }
    pitch = {
        'kp': 5.23e+04,
        'ki': 3.31e+03,
        'kd': 3.09e+04
    }
    yaw = {
        'kp': 3.42e+05,
        'ki': 2.70e+04,
        'kd': 1.73e+05
    }
    tangential_short_tether = {
        'kp': 0.0115,
        'ki': 0.000166,
        'kd': 0.0870
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0469,
        'ki': 0.00169,
        'kd': 0.193
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00713,
        'ki': 4.56e-05,
        'kd': 0.0331
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0581
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.08e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.08e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.06e+04,
        'ki': 536.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.65e+04,
        'ki': 9.25e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial04Hover:
    low_altitude = {
        'kp': 1.90e+03,
        'ki': 134.,
        'kd': 6.68e+03
    }
    high_altitude = {
        'kp': 729.,
        'ki': 43.1,
        'kd': 3.08e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.74e+04,
        'ki': 1.16e+03,
        'kd': 2.23e+04
    }
    pitch = {
        'kp': 5.71e+04,
        'ki': 3.62e+03,
        'kd': 3.38e+04
    }
    yaw = {
        'kp': 3.33e+05,
        'ki': 2.63e+04,
        'kd': 1.69e+05
    }
    tangential_short_tether = {
        'kp': 0.0115,
        'ki': 0.000166,
        'kd': 0.0870
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0469,
        'ki': 0.00169,
        'kd': 0.193
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00713,
        'ki': 4.56e-05,
        'kd': 0.0331
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0574
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.04e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.04e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.46e+04,
        'ki': 588.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.52e+04,
        'ki': 9.01e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial04Crosswind:
    low_altitude = {
        'kp': 1.81e+03,
        'ki': 128.,
        'kd': 6.39e+03
    }
    high_altitude = {
        'kp': 694.,
        'ki': 41.0,
        'kd': 2.94e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.84e+04,
        'ki': 1.21e+03,
        'kd': 2.32e+04
    }
    pitch = {
        'kp': 5.91e+04,
        'ki': 3.75e+03,
        'kd': 3.50e+04
    }
    yaw = {
        'kp': 3.45e+05,
        'ki': 2.72e+04,
        'kd': 1.75e+05
    }
    tangential_short_tether = {
        'kp': 0.00937,
        'ki': 0.000135,
        'kd': 0.0710
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0382,
        'ki': 0.00138,
        'kd': 0.157
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00582,
        'ki': 3.72e-05,
        'kd': 0.0270
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0498
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.08e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.08e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.59e+04,
        'ki': 606.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.68e+04,
        'ki': 9.32e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial05Hover:
    low_altitude = {
        'kp': 1.86e+03,
        'ki': 132.,
        'kd': 6.55e+03
    }
    high_altitude = {
        'kp': 713.,
        'ki': 42.2,
        'kd': 3.02e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.69e+04,
        'ki': 1.14e+03,
        'kd': 2.19e+04
    }
    pitch = {
        'kp': 5.60e+04,
        'ki': 3.55e+03,
        'kd': 3.31e+04
    }
    yaw = {
        'kp': 3.27e+05,
        'ki': 2.58e+04,
        'kd': 1.65e+05
    }
    tangential_short_tether = {
        'kp': 0.0115,
        'ki': 0.000166,
        'kd': 0.0870
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0469,
        'ki': 0.00169,
        'kd': 0.193
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00713,
        'ki': 4.56e-05,
        'kd': 0.0331
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0577
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.06e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.06e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.38e+04,
        'ki': 577.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.44e+04,
        'ki': 8.83e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial05Crosswind:
    low_altitude = {
        'kp': 1.77e+03,
        'ki': 126.,
        'kd': 6.24e+03
    }
    high_altitude = {
        'kp': 677.,
        'ki': 40.0,
        'kd': 2.86e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.78e+04,
        'ki': 1.18e+03,
        'kd': 2.27e+04
    }
    pitch = {
        'kp': 5.78e+04,
        'ki': 3.67e+03,
        'kd': 3.42e+04
    }
    yaw = {
        'kp': 3.37e+05,
        'ki': 2.66e+04,
        'kd': 1.71e+05
    }
    tangential_short_tether = {
        'kp': 0.00933,
        'ki': 0.000135,
        'kd': 0.0707
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0381,
        'ki': 0.00137,
        'kd': 0.157
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00579,
        'ki': 3.71e-05,
        'kd': 0.0269
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0500
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.10e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.10e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.49e+04,
        'ki': 593.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.58e+04,
        'ki': 9.11e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial06Hover:
    low_altitude = {
        'kp': 1.90e+03,
        'ki': 135.,
        'kd': 6.70e+03
    }
    high_altitude = {
        'kp': 730.,
        'ki': 43.2,
        'kd': 3.09e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.74e+04,
        'ki': 1.16e+03,
        'kd': 2.24e+04
    }
    pitch = {
        'kp': 5.71e+04,
        'ki': 3.62e+03,
        'kd': 3.38e+04
    }
    yaw = {
        'kp': 3.34e+05,
        'ki': 2.64e+04,
        'kd': 1.69e+05
    }
    tangential_short_tether = {
        'kp': 0.0115,
        'ki': 0.000166,
        'kd': 0.0870
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0469,
        'ki': 0.00169,
        'kd': 0.193
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00713,
        'ki': 4.56e-05,
        'kd': 0.0331
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0574
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.04e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.04e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.47e+04,
        'ki': 590.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.53e+04,
        'ki': 9.02e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial06Crosswind:
    low_altitude = {
        'kp': 1.81e+03,
        'ki': 128.,
        'kd': 6.39e+03
    }
    high_altitude = {
        'kp': 694.,
        'ki': 41.0,
        'kd': 2.94e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.84e+04,
        'ki': 1.21e+03,
        'kd': 2.32e+04
    }
    pitch = {
        'kp': 5.91e+04,
        'ki': 3.75e+03,
        'kd': 3.50e+04
    }
    yaw = {
        'kp': 3.45e+05,
        'ki': 2.72e+04,
        'kd': 1.75e+05
    }
    tangential_short_tether = {
        'kp': 0.00937,
        'ki': 0.000135,
        'kd': 0.0709
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0382,
        'ki': 0.00138,
        'kd': 0.157
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00582,
        'ki': 3.72e-05,
        'kd': 0.0270
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0498
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.08e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.08e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.59e+04,
        'ki': 606.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.68e+04,
        'ki': 9.32e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial07Hover:
    low_altitude = {
        'kp': 1.90e+03,
        'ki': 134.,
        'kd': 6.68e+03
    }
    high_altitude = {
        'kp': 729.,
        'ki': 43.1,
        'kd': 3.08e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.74e+04,
        'ki': 1.16e+03,
        'kd': 2.23e+04
    }
    pitch = {
        'kp': 5.71e+04,
        'ki': 3.62e+03,
        'kd': 3.38e+04
    }
    yaw = {
        'kp': 3.33e+05,
        'ki': 2.63e+04,
        'kd': 1.69e+05
    }
    tangential_short_tether = {
        'kp': 0.0115,
        'ki': 0.000166,
        'kd': 0.0870
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0469,
        'ki': 0.00169,
        'kd': 0.193
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00713,
        'ki': 4.56e-05,
        'kd': 0.0331
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0574
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.04e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.04e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.46e+04,
        'ki': 588.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.52e+04,
        'ki': 9.01e+03,
        'kd': 0.00
    }
  elif wing_serial == m.kWingSerial07Crosswind:
    low_altitude = {
        'kp': 1.81e+03,
        'ki': 128.,
        'kd': 6.39e+03
    }
    high_altitude = {
        'kp': 694.,
        'ki': 41.0,
        'kd': 2.94e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 2.84e+04,
        'ki': 1.21e+03,
        'kd': 2.32e+04
    }
    pitch = {
        'kp': 5.91e+04,
        'ki': 3.75e+03,
        'kd': 3.50e+04
    }
    yaw = {
        'kp': 3.45e+05,
        'ki': 2.72e+04,
        'kd': 1.75e+05
    }
    tangential_short_tether = {
        'kp': 0.00937,
        'ki': 0.000135,
        'kd': 0.0710
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0382,
        'ki': 0.00138,
        'kd': 0.157
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00582,
        'ki': 3.72e-05,
        'kd': 0.0270
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0498
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.08e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.08e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 4.59e+04,
        'ki': 606.,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 4.68e+04,
        'ki': 9.32e+03,
        'kd': 0.00
    }
  else:
    assert False, 'wing_serial %d was not recognized' % wing_serial

  return {
      'low_altitude': low_altitude,
      'high_altitude': high_altitude,
      'transform_tether_elevation': transform_tether_elevation,
      'reel_tether_elevation': reel_tether_elevation,
      'roll': roll,
      'low_thrust_pitch': low_thrust_pitch,
      'pitch': pitch,
      'yaw': yaw,
      'tangential_short_tether': tangential_short_tether,
      'tangential_low_altitude_long_tether': (
          tangential_low_altitude_long_tether),
      'tangential_high_altitude_long_tether': (
          tangential_high_altitude_long_tether),
      'radial': radial,
      'tension_hard': tension_hard,
      'tension_soft': tension_soft,
      'int_pitch': int_pitch,
      'int_yaw': int_yaw,
  }
