diff --git a/cmvr-es/config/manager/device_manager.pb.txt b/cmvr-es/config/manager/device_manager.pb.txt index 0b50890a..05ed01c5 100644 --- a/cmvr-es/config/manager/device_manager.pb.txt +++ b/cmvr-es/config/manager/device_manager.pb.txt @@ -6,42 +6,42 @@ device_manager { id: "mujoco_world" type: DEVICE_TYPE_MUJOCO_WORLD config_file: "devices/mujoco/right_arm_eye_to_hand_world.pb.txt" - enable: false + enable: true } devices { id: "right_arm_mujoco_motors" type: DEVICE_TYPE_MOTOR_SYSTEM config_file: "devices/motor/mujoco_motors.pb.txt" - enable: false + enable: true } devices { id: "mujoco_right_arm" type: DEVICE_TYPE_ROBOT_ARM config_file: "devices/arm/arm_mujoco_qp.pb.txt" - enable: false + enable: true } devices { id: "mujoco_viewer" type: DEVICE_TYPE_MUJOCO_VIEWER config_file: "devices/mujoco/mujoco_viewer.pb.txt" - enable: false + enable: true } devices { id: "mujoco_hand_cam" type: DEVICE_TYPE_CAMERA config_file: "devices/camera/camera.pb.txt" - enable: false + enable: true } devices { id: "mujoco_external_touch_cam" type: DEVICE_TYPE_CAMERA config_file: "devices/camera/camera.pb.txt" - enable: false + enable: true } devices { @@ -77,7 +77,7 @@ device_manager { id: "mujoco_zero_touch" type: DEVICE_TYPE_TOUCH config_file: "devices/touch/touch.pb.txt" - enable: false + enable: true } devices { @@ -217,14 +217,14 @@ device_manager { id: "tchl_joint_motors" type: DEVICE_TYPE_MOTOR_SYSTEM config_file: "devices/motor/tchl_multi_motors.pb.txt" - enable: true + enable: false } devices { id: "tchl_arm" type: DEVICE_TYPE_ROBOT_ARM config_file: "devices/arm/tchl_arm.pb.txt" - enable: true + enable: false } } diff --git a/cmvr-es/config/manager/task_manager.pb.txt b/cmvr-es/config/manager/task_manager.pb.txt index e892f6a8..1cc961c0 100644 --- a/cmvr-es/config/manager/task_manager.pb.txt +++ b/cmvr-es/config/manager/task_manager.pb.txt @@ -5,7 +5,7 @@ task_manager { run_mode: TASK_RUN_MODE_PERIODIC_STEP control_period_s: 0.001 config_file: "tasks/touch_screen_task/touch_screen_task_mujoco.pb.txt" - enable: false + enable: true } tasks { id: "grpc_server" diff --git a/cmvr-es/config/tasks/touch_screen_task/touch_screen_task.pb.txt b/cmvr-es/config/tasks/touch_screen_task/touch_screen_task.pb.txt index be02729b..23d6d5e1 100644 --- a/cmvr-es/config/tasks/touch_screen_task/touch_screen_task.pb.txt +++ b/cmvr-es/config/tasks/touch_screen_task/touch_screen_task.pb.txt @@ -7,6 +7,7 @@ touch_screen_task { devices { arm_id: "right_arm" + # devices/touch/touch.pb.txt 中的 PX6AXGenXCan,使用 CAN 合力数据,单位为 N。 touch_id: "paxini_tip_1" # 手部相机和外部相机的 DeviceManager ID。 camera_id: "right_hand_cam" diff --git a/cmvr-es/config/tasks/touch_screen_task/touch_screen_task_mujoco.pb.txt b/cmvr-es/config/tasks/touch_screen_task/touch_screen_task_mujoco.pb.txt index 5b561e2e..e254553f 100644 --- a/cmvr-es/config/tasks/touch_screen_task/touch_screen_task_mujoco.pb.txt +++ b/cmvr-es/config/tasks/touch_screen_task/touch_screen_task_mujoco.pb.txt @@ -7,6 +7,7 @@ touch_screen_task { devices { arm_id: "mujoco_right_arm" + # ZeroSimTouch 始终返回零力,用于测试无接触时的前进限距和回撤流程。 touch_id: "mujoco_zero_touch" # 手部相机和外部相机的 DeviceManager ID。 camera_id: "mujoco_hand_cam" @@ -120,6 +121,7 @@ touch_screen_task { twist_tool { x: 0.0 y: -0.02 z: 0.0 rx: 0.0 ry: 0.0 rz: 0.0 } acceleration: 10.0 linear_jerk: 100.0 # m/s^3,接近阶段请求值,受机械臂 linear_jerk_max 限制。 + # 零力不会触发接触;达到此距离后回撤,最终状态为 TOUCH_FORWARD_TIMEOUT。 max_distance_m: 0.02 } tactile { diff --git a/cmvr-es/task/touch_screen_task/src/touch_screen_task.cpp b/cmvr-es/task/touch_screen_task/src/touch_screen_task.cpp index 41feef9c..3abf5a1a 100644 --- a/cmvr-es/task/touch_screen_task/src/touch_screen_task.cpp +++ b/cmvr-es/task/touch_screen_task/src/touch_screen_task.cpp @@ -254,6 +254,12 @@ bool TouchScreenTask::init(const std::shared_ptr& arm, last_status_ = Status::INVALID_CONFIG; return false; } + if (touch_ && !touch_->start()) { + CMVR_LOG(ERROR) << "[TouchScreenTask] Failed to start touch sensor: " + << config_.devices().touch_id() << ", " << touch_->lastError(); + last_status_ = Status::TACTILE_UNAVAILABLE; + return false; + } perception_ = std::make_shared(camera_); external_perception_ = diff --git a/cmvr-es/task/touch_screen_task/src/touch_screen_task_test.cpp b/cmvr-es/task/touch_screen_task/src/touch_screen_task_test.cpp index e194ffc2..5339b2c4 100644 --- a/cmvr-es/task/touch_screen_task/src/touch_screen_task_test.cpp +++ b/cmvr-es/task/touch_screen_task/src/touch_screen_task_test.cpp @@ -168,14 +168,19 @@ public: class ScriptedTouch final : public cmvr::device::AbstractTouch { public: std::string typeName() const override { return "ScriptedTouch"; } - Status state() const override { return Status::STREAMING; } - std::string lastError() const override { return {}; } + bool start() override { return started = start_succeeds; } + Status state() const override { return started ? Status::STREAMING : Status::INITIALIZED; } + std::string lastError() const override { return start_succeeds ? "" : "Touch start failed"; } bool readForce(cmvr::device::ForceSample& sample) override { + sample = {}; + if (!started || !available) return false; sample.force = {0.0, 0.0, 2.5}; sample.sample_time = std::chrono::steady_clock::now(); - return available; + return true; } bool readTactile(cmvr::device::TactileSample&) override { return false; } + bool start_succeeds{true}; + bool started{false}; bool available{true}; }; @@ -490,11 +495,12 @@ TEST(TouchSensorIntegrationTest, FactoryAndGrpcUseIndependentTouchDevice) { EXPECT_EQ(response.sensor_size(), 0); } -TEST_F(TouchScreenFailureReturnTest, ReadsTouchForceAndDiscardsFailedSample) { +TEST_F(TouchScreenFailureReturnTest, StartsTouchAndDiscardsFailedSample) { const auto sensor = std::make_shared(); const auto camera = std::make_shared(); cmvr::task::TouchScreenTask task(config); ASSERT_TRUE(task.init(arm, sensor, camera, camera)); + EXPECT_TRUE(sensor->started); ASSERT_TRUE(task.step(0.02)); EXPECT_DOUBLE_EQ(task.lastTouchPressureSum(), 2.5); EXPECT_EQ(task.lastTouchNonzeroCount(), 1); @@ -505,6 +511,16 @@ TEST_F(TouchScreenFailureReturnTest, ReadsTouchForceAndDiscardsFailedSample) { EXPECT_EQ(task.lastTouchNonzeroCount(), 0); } +TEST_F(TouchScreenFailureReturnTest, ReportsTouchStartupFailure) { + const auto sensor = std::make_shared(); + sensor->start_succeeds = false; + const auto camera = std::make_shared(); + cmvr::task::TouchScreenTask task(config); + EXPECT_FALSE(task.init(arm, sensor, camera, camera)); + EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::TACTILE_UNAVAILABLE); + EXPECT_TRUE(arm->calls.empty()); +} + TEST_F(TouchScreenFailureReturnTest, FailureReturnIsOptionalAndIndependentOfSuccessReturn) { for (const bool explicitly_disabled : {false, true}) { SCOPED_TRACE(explicitly_disabled);