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

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

drake_cc_library(
    name = "populate_cylinder_plant",
    srcs = [
        "populate_cylinder_plant.cc",
    ],
    hdrs = [
        "populate_cylinder_plant.h",
    ],
    deps = [
        "//common:default_scalars",
        "//geometry:geometry_ids",
        "//geometry:scene_graph",
        "//math:geometric_transform",
        "//multibody/plant",
    ],
)

drake_cc_googletest(
    name = "populate_cylinder_plant_test",
    deps = [
        ":populate_cylinder_plant",
        "//common/test_utilities:eigen_matrix_compare",
        "//multibody/plant",
        "//systems/framework:diagram_builder",
    ],
)

drake_cc_binary(
    name = "cylinder_run_dynamics",
    srcs = ["cylinder_run_dynamics.cc"],
    # Running this example with the default parameters incurs in a case with
    # a violent collision between the cylinder and the ground. MultibodyPlant
    # must use sub-stepping in order to handle this situation. Otherwise the
    # contact solver aborts with a non-convergence error.
    # Therefore the success of this test indicates MultibodyPlant correctly
    # identified this event and used sub-stepping.
    add_test_rule = 1,
    test_rule_args = [
        # If MultibodyPlant does not use sub-stepping, i.e attempts to handle
        # the collision with the default time step of 1.0e-3 seconds, the
        # simulation will abort at t = 0.514 seconds due to non-convergence of
        # the contact solver. Therefore we run this example as a test past that
        # time in order to test that MultibodyPlant correctly handled this case
        # using sub-stepping.
        "--simulation_time=0.6",
        "--target_realtime_rate=0.0",
    ],
    test_rule_timeout = "long",
    deps = [
        ":populate_cylinder_plant",
        "//common:add_text_logging_gflags",
        "//lcm",
        "//systems/analysis:simulator",
        "//systems/framework:diagram",
        "//systems/lcm:lcm_pubsub_system",
        "//visualization:visualization_config_functions",
        "@gflags",
    ],
)

add_lint_tests(enable_clang_format_lint = False)
