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_py.bzl",
    "drake_py_binary",
    "drake_py_library",
)
load("//tools/skylark:test_tags.bzl", "vtk_test_tags")

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

drake_cc_library(
    name = "manipulation_station",
    srcs = [
        "manipulation_station.cc",
    ],
    hdrs = [
        "manipulation_station.h",
    ],
    data = [
        "//examples/kuka_iiwa_arm:models",
        "@drake_models//:iiwa_description",
        "@drake_models//:manipulation_station",
        "@drake_models//:realsense2_description",
        "@drake_models//:wsg_50_description",
        "@drake_models//:ycb",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//common:find_resource",
        "//geometry:scene_graph",
        "//geometry/render_vtk",
        "//manipulation/schunk_wsg:schunk_wsg_constants",
        "//manipulation/schunk_wsg:schunk_wsg_position_controller",
        "//math:geometric_transform",
        "//multibody/parsing",
        "//multibody/plant",
        "//perception:depth_image_to_point_cloud",
        "//systems/controllers:inverse_dynamics_controller",
        "//systems/framework",
        "//systems/primitives",
        "//systems/sensors:rgbd_sensor",
    ],
)

drake_cc_library(
    name = "manipulation_station_hardware_interface",
    srcs = [
        "manipulation_station_hardware_interface.cc",
    ],
    hdrs = [
        "manipulation_station_hardware_interface.h",
    ],
    data = [
        "@drake_models//:iiwa_description",
        "@drake_models//:wsg_50_description",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//lcm",
        "//manipulation/kuka_iiwa:iiwa_command_sender",
        "//manipulation/kuka_iiwa:iiwa_status_receiver",
        "//manipulation/schunk_wsg:schunk_wsg_lcm",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/framework",
        "//systems/lcm",
        "//systems/primitives",
        "//systems/sensors:lcm_image_array_to_images",
    ],
)

drake_cc_binary(
    name = "mock_station_simulation",
    srcs = [
        "mock_station_simulation.cc",
    ],
    add_test_rule = 1,
    test_rule_args = [
        "--target_realtime_rate=0.0",
        "--duration=0.1",
    ],
    test_rule_tags = vtk_test_tags(),
    deps = [
        ":manipulation_station",
        "//geometry:drake_visualizer",
        "//lcm",
        "//manipulation/kuka_iiwa:iiwa_command_receiver",
        "//manipulation/kuka_iiwa:iiwa_status_sender",
        "//manipulation/schunk_wsg:schunk_wsg_lcm",
        "//perception:point_cloud_to_lcm",
        "//systems/analysis:simulator",
        "//systems/lcm",
        "//systems/sensors:image_to_lcm_image_array_t",
        "@gflags",
    ],
)

drake_cc_binary(
    name = "proof_of_life",
    srcs = [
        "proof_of_life.cc",
    ],
    add_test_rule = 1,
    test_rule_args = [
        "--target_realtime_rate=0.0",
        "--duration=0.1",
        "--test",
    ],
    test_rule_tags = vtk_test_tags(),
    test_rule_timeout = "moderate",
    deps = [
        ":manipulation_station",
        "//geometry:drake_visualizer",
        "//multibody/plant:contact_results_to_lcm",
        "//systems/analysis:simulator",
        "//systems/sensors:image_to_lcm_image_array_t",
        "@gflags",
    ],
)

# Tests

drake_cc_googletest(
    name = "manipulation_station_test",
    # Frequently exceeds short timeout in coverage builds.
    timeout = "moderate",
    tags = vtk_test_tags(),
    deps = [
        ":manipulation_station",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_no_throw",
        "//geometry/test_utilities:dummy_render_engine",
    ],
)

drake_cc_googletest(
    name = "manipulation_station_hardware_interface_test",
    deps = [
        ":manipulation_station_hardware_interface",
        "//systems/sensors:image",
    ],
)

# Python examples

drake_py_library(
    name = "schunk_wsg_buttons",
    srcs = ["schunk_wsg_buttons.py"],
    deps = [
        "//bindings/pydrake",
    ],
)

drake_py_binary(
    name = "joint_teleop",
    srcs = ["joint_teleop.py"],
    add_test_rule = 1,
    test_rule_args = [
        "--target_realtime_rate=0.0",
        "--duration=0.1",
        "--test",
    ],
    test_rule_tags = vtk_test_tags(),
    test_rule_timeout = "moderate",  # Frequently exceeds short timeout in dbg.
    deps = [
        ":schunk_wsg_buttons",
        "//bindings/pydrake",
    ],
)

drake_py_binary(
    name = "end_effector_teleop_dualshock4",
    srcs = ["end_effector_teleop_dualshock4.py"],
    add_test_rule = 1,
    test_rule_args = [
        "--target_realtime_rate=0.0",
        "--duration=0.1",
        "--test",
    ],
    # Disable testing for this module since it will fail on CI
    # because it assumes that dualshock4 controller is connected.
    test_rule_tags = vtk_test_tags() + ["manual"],
    test_rule_timeout = "moderate",  # Frequently exceeds short timeout in dbg.
    deps = [
        "//bindings/pydrake",
    ],
)

drake_py_binary(
    name = "end_effector_teleop_mouse",
    srcs = ["end_effector_teleop_mouse.py"],
    add_test_rule = 1,
    test_rule_args = [
        "--target_realtime_rate=0.0",
        "--duration=0.1",
        "--test",
    ],
    test_rule_tags = vtk_test_tags(),
    test_rule_timeout = "moderate",  # Frequently exceeds short timeout in dbg.
    deps = [
        "//bindings/pydrake",
    ],
)

drake_py_binary(
    name = "end_effector_teleop_sliders",
    srcs = ["end_effector_teleop_sliders.py"],
    add_test_rule = 1,
    test_rule_args = [
        "--target_realtime_rate=0.0",
        "--duration=0.1",
        "--test",
    ],
    test_rule_tags = vtk_test_tags(),
    test_rule_timeout = "moderate",  # Frequently exceeds short timeout in dbg.
    deps = [
        ":schunk_wsg_buttons",
        "//bindings/pydrake",
    ],
)

drake_py_binary(
    name = "print_station_context",
    srcs = ["print_station_context.py"],
    add_test_rule = 1,
    deps = [
        "//bindings/pydrake",
    ],
)

add_lint_tests(enable_clang_format_lint = False)
