load("//tools/install:install_data.bzl", "install_data")
load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_binary",
    "drake_cc_googletest",
    "drake_cc_library",
)
load("//tools/skylark:drake_data.bzl", "models_filegroup")

package(default_visibility = ["//visibility:private"])

models_filegroup(
    name = "glob_models",
)

install_data(
    name = "install_data",
    data = [":glob_models"],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "models",
    srcs = [
        ":glob_models",
        "@drake_models//:skydio_2",
    ],
    visibility = ["//visibility:public"],
)

drake_cc_library(
    name = "quadrotor_plant",
    srcs = ["quadrotor_plant.cc"],
    hdrs = ["quadrotor_plant.h"],
    visibility = ["//visibility:public"],
    deps = [
        "//common:default_scalars",
        "//math:geometric_transform",
        "//systems/controllers:linear_quadratic_regulator",
        "//systems/framework:leaf_system",
        "//systems/primitives:affine_system",
    ],
)

drake_cc_library(
    name = "quadrotor_geometry",
    srcs = ["quadrotor_geometry.cc"],
    hdrs = ["quadrotor_geometry.h"],
    data = [":models"],
    visibility = ["//visibility:public"],
    deps = [
        "//geometry:scene_graph",
        "//math:geometric_transform",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/framework:diagram_builder",
        "//systems/framework:leaf_system",
    ],
)

drake_cc_binary(
    name = "run_quadrotor_dynamics",
    srcs = ["run_quadrotor_dynamics.cc"],
    add_test_rule = 1,
    data = [":models"],
    test_rule_args = [
        "--duration=0.1",
        "--initial_height=0.051",
    ],
    deps = [
        ":quadrotor_plant",
        "//common:add_text_logging_gflags",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/analysis:simulator",
        "//systems/analysis:simulator_gflags",
        "//systems/framework:diagram",
        "//systems/primitives:constant_vector_source",
        "//visualization:visualization_config_functions",
        "@gflags",
    ],
)

drake_cc_binary(
    name = "run_quadrotor_lqr",
    srcs = ["run_quadrotor_lqr.cc"],
    add_test_rule = 1,
    test_rule_args = [
        "-simulation_trials=2",
        "-simulation_real_time_rate=0.0",
    ],
    deps = [
        ":quadrotor_geometry",
        ":quadrotor_plant",
        "//common:is_approx_equal_abstol",
        "//geometry:drake_visualizer",
        "//lcm",
        "//systems/analysis:simulator",
        "//systems/framework:diagram",
        "@gflags",
    ],
)

drake_cc_googletest(
    name = "quadrotor_plant_test",
    deps = [
        ":quadrotor_plant",
        "//common/test_utilities:expect_no_throw",
        "//systems/framework/test_utilities",
    ],
)

drake_cc_googletest(
    name = "quadrotor_dynamics_test",
    data = [":models"],
    deps = [
        ":quadrotor_plant",
        "//common/test_utilities:eigen_matrix_compare",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/analysis:simulator",
        "//systems/framework:diagram",
        "//systems/primitives:constant_vector_source",
    ],
)

drake_cc_googletest(
    name = "quadrotor_geometry_test",
    deps = [
        ":quadrotor_geometry",
        ":quadrotor_plant",
    ],
)

add_lint_tests(enable_clang_format_lint = False)
