From 8e2a8615dd8733a5338158afe93fda38475b8883 Mon Sep 17 00:00:00 2001 From: xtkuang <87661715@qq.com> Date: Fri, 9 Oct 2026 09:16:10 +0800 Subject: [PATCH] feat: update dexhand support and robot device configs --- cmvr-es/config/devices/camera/camera.pb.txt | 22 +++++++ cmvr-es/config/devices/dexhand/dexhand.pb.txt | 26 +++++++++ .../devices/microphone/microphone.pb.txt | 2 +- cmvr-es/config/manager/device_manager.pb.txt | 13 ++++- cmvr-es/config/manager/task_manager.pb.txt | 2 +- .../quic_edge_task/quic_edge_task.pb.txt | 2 +- cmvr-es/devices/dexhand/abstract_dexhand.h | 22 +++++++ cmvr-es/devices/dexhand/dexhand_factory.h | 24 ++++++-- .../oymotion_ap001/include/oymotion_ap001.h | 16 ++++- .../oymotion_ap001/src/oymotion_ap001.cpp | 58 +++++++++++++++---- .../service/grpc/src/grpc_dexhand_service.cpp | 53 +++++++++++++++++ protos/cmvr/api/dexhand_command.proto | 4 +- .../dexhand_config/dexhand_config.proto | 10 +++- 13 files changed, 225 insertions(+), 29 deletions(-) diff --git a/cmvr-es/config/devices/camera/camera.pb.txt b/cmvr-es/config/devices/camera/camera.pb.txt index 3aa02fed..8e55679b 100644 --- a/cmvr-es/config/devices/camera/camera.pb.txt +++ b/cmvr-es/config/devices/camera/camera.pb.txt @@ -262,4 +262,26 @@ camera { } } } + + cameras { + id: "usb_cam2" + uvc { + usb: "/dev/video2" + camera_mode: CAMERA_MODE_VIDEO + capture { + width: 640 + height: 480 + fps: 30 + stream_mode: STREAM_MODE_RGB + } + encoder { + width: 640 + height: 480 + fps: 30 + codec: "h265_qsv" + enable_stream_timestamp: true + buffer_size: 30 + } + } + } } diff --git a/cmvr-es/config/devices/dexhand/dexhand.pb.txt b/cmvr-es/config/devices/dexhand/dexhand.pb.txt index 8077edd6..ed9d980c 100644 --- a/cmvr-es/config/devices/dexhand/dexhand.pb.txt +++ b/cmvr-es/config/devices/dexhand/dexhand.pb.txt @@ -1,6 +1,24 @@ dexhand { dexhands { id: "right_hand_ap001" + model: "ROH-AP001" + has_tactile_feedback: true + oymotion_ap001 { + can_interface: "can0" + hand_id: 2 + master_id: 1 + command_timeout_ms: 255 + } + } + + # LiteS001 uses the same six-axis OYMotion CAN control protocol as AP001, + # but it has no tactile sensor matrix. Add this id to device_manager.pb.txt + # when the LiteS001 is installed; do not enable it together with AP001 when + # both entries address the same physical CAN hand id. + dexhands { + id: "right_hand_lites001" + model: "ROH-LiteS001" + has_tactile_feedback: false oymotion_ap001 { can_interface: "can0" hand_id: 2 @@ -11,6 +29,8 @@ dexhand { dexhands { id: "hand1" + model: "RH56D" + has_tactile_feedback: true rh56dftp { ip: "192.168.1.223" port: 6000 @@ -20,6 +40,8 @@ dexhand { dexhands { id: "hand2" + model: "RH56D" + has_tactile_feedback: true rh56dftp { ip: "192.168.1.224" port: 6000 @@ -29,6 +51,8 @@ dexhand { dexhands { id: "paxini_tip_1" + model: "PX-6AX Gen3" + has_tactile_feedback: true px_6ax_gen3 { serial_port: "/dev/ttyACM1" sensor_model: "S1813_core" @@ -53,6 +77,8 @@ dexhand { dexhands { id: "mujoco_zero_touch_dexhand" + model: "MuJoCo Zero Touch" + has_tactile_feedback: true zero_sim_touch {} } } diff --git a/cmvr-es/config/devices/microphone/microphone.pb.txt b/cmvr-es/config/devices/microphone/microphone.pb.txt index 90d71fa2..b75b2fd9 100644 --- a/cmvr-es/config/devices/microphone/microphone.pb.txt +++ b/cmvr-es/config/devices/microphone/microphone.pb.txt @@ -5,7 +5,7 @@ microphone { channels: 2 sampleRate: 48000 volume: 100 - input_device: "plughw:CARD=XFMDPV0018,DEV=0" + input_device: "plughw:CARD=Newmine,DEV=0" } } } diff --git a/cmvr-es/config/manager/device_manager.pb.txt b/cmvr-es/config/manager/device_manager.pb.txt index f3a7d654..0ce75676 100644 --- a/cmvr-es/config/manager/device_manager.pb.txt +++ b/cmvr-es/config/manager/device_manager.pb.txt @@ -63,7 +63,7 @@ device_manager { id: "right_hand_ap001" type: DEVICE_TYPE_DEXHAND config_file: "devices/dexhand/dexhand.pb.txt" - enable: true + enable: false } devices { @@ -175,7 +175,7 @@ device_manager { id: "mic1" type: DEVICE_TYPE_MICROPHONE config_file: "devices/microphone/microphone.pb.txt" - enable: false + enable: true } devices { @@ -196,7 +196,14 @@ device_manager { id: "usb_cam1" type: DEVICE_TYPE_CAMERA config_file: "devices/camera/camera.pb.txt" - enable: false + enable: true + } + + devices { + id: "usb_cam2" + type: DEVICE_TYPE_CAMERA + config_file: "devices/camera/camera.pb.txt" + enable: true } devices { diff --git a/cmvr-es/config/manager/task_manager.pb.txt b/cmvr-es/config/manager/task_manager.pb.txt index 3d507b94..d267306c 100644 --- a/cmvr-es/config/manager/task_manager.pb.txt +++ b/cmvr-es/config/manager/task_manager.pb.txt @@ -27,6 +27,6 @@ task_manager { type: TASK_TYPE_QUIC_EDGE run_mode: TASK_RUN_MODE_BLOCKING_SERVICE config_file: "tasks/quic_edge_task/quic_edge_task.pb.txt" - enable: false + enable: true } } diff --git a/cmvr-es/config/tasks/quic_edge_task/quic_edge_task.pb.txt b/cmvr-es/config/tasks/quic_edge_task/quic_edge_task.pb.txt index a886cfbf..20ec2e08 100644 --- a/cmvr-es/config/tasks/quic_edge_task/quic_edge_task.pb.txt +++ b/cmvr-es/config/tasks/quic_edge_task/quic_edge_task.pb.txt @@ -7,7 +7,7 @@ quic_edge { server_port: 4433 alpn: "cmvr-quic-edge/1" node_id: "cmvr-edge" - robot_id: "CN-CMVR-MBLRV1-AIMA-20260806-001" + robot_id: "CN-CMVR-MBLRV1-AIMA-20260806-002" software_version: "0.1" # The existing cmvr-es gRPC server remains the robot-control endpoint. "auto" diff --git a/cmvr-es/devices/dexhand/abstract_dexhand.h b/cmvr-es/devices/dexhand/abstract_dexhand.h index 3a21be43..1614bfbe 100644 --- a/cmvr-es/devices/dexhand/abstract_dexhand.h +++ b/cmvr-es/devices/dexhand/abstract_dexhand.h @@ -139,6 +139,18 @@ namespace cmvr::device { AbstractDexHand() = default; ~AbstractDexHand() override = default; + bool hasTactileFeedback() const noexcept { + return has_tactile_feedback_; + } + + void setTactileFeedbackCapability(bool supported) noexcept { + has_tactile_feedback_ = supported; + } + + const std::string& model() const noexcept { return model_; } + + void setModel(std::string model) { model_ = std::move(model); } + virtual Status state() const = 0; virtual std::string lastError() const = 0; @@ -156,6 +168,12 @@ namespace cmvr::device { } virtual void setTactilePollingRegions(const std::vector& regions) = 0; + // Streaming services acquire/release sensor acquisition explicitly so + // hardware polling does not outlive all connected clients. + virtual bool acquireSensorDataStream() { + return hasTactileFeedback(); + } + virtual void releaseSensorDataStream() {} virtual std::vector getSensorData() = 0; virtual TactileRegionData getSensorData(FingerType finger, TactileRegion region) = 0; virtual ResultantForce getResultantForce(FingerType finger, TactileRegion region) = 0; @@ -184,6 +202,10 @@ namespace cmvr::device { virtual void setForce(const std::vector&) { CMVR_LOG(ERROR) << "[AbstractDexHand] setForce is not supported by this dexhand abstraction."; } + + private: + bool has_tactile_feedback_{false}; + std::string model_; }; } diff --git a/cmvr-es/devices/dexhand/dexhand_factory.h b/cmvr-es/devices/dexhand/dexhand_factory.h index b9fb8c60..78fb1cc2 100644 --- a/cmvr-es/devices/dexhand/dexhand_factory.h +++ b/cmvr-es/devices/dexhand/dexhand_factory.h @@ -25,22 +25,27 @@ public: return nullptr; } + std::shared_ptr device; switch (cfg.backend_case()) { case config::DexHandDeviceConfig::kRh56Dftp: - return std::make_shared( + device = std::make_shared( backendWithId_(cfg.id(), cfg.rh56dftp())); + break; case config::DexHandDeviceConfig::kPx6AxGen3: - return std::make_shared( + device = std::make_shared( backendWithId_(cfg.id(), cfg.px_6ax_gen3())); + break; case config::DexHandDeviceConfig::kZeroSimTouch: - return std::make_shared( + device = std::make_shared( backendWithId_(cfg.id(), cfg.zero_sim_touch())); + break; case config::DexHandDeviceConfig::kOymotionAp001: - return std::make_shared( + device = std::make_shared( backendWithId_(cfg.id(), cfg.oymotion_ap001())); + break; case config::DexHandDeviceConfig::BACKEND_NOT_SET: default: @@ -51,6 +56,17 @@ public: return nullptr; } } + const bool default_tactile_capability = + cfg.backend_case() == config::DexHandDeviceConfig::kRh56Dftp || + cfg.backend_case() == config::DexHandDeviceConfig::kPx6AxGen3 || + cfg.backend_case() == config::DexHandDeviceConfig::kZeroSimTouch || + cfg.backend_case() == config::DexHandDeviceConfig::kOymotionAp001; + device->setTactileFeedbackCapability( + cfg.has_has_tactile_feedback() + ? cfg.has_tactile_feedback() + : default_tactile_capability); + device->setModel(cfg.model().empty() ? device->typeName() : cfg.model()); + return device; } private: diff --git a/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h b/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h index ca9bfaa2..ed886384 100644 --- a/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h +++ b/cmvr-es/devices/dexhand/oymotion_ap001/include/oymotion_ap001.h @@ -13,12 +13,12 @@ namespace cmvr::device { -class OYMotionAP001 final : public AbstractDexHand { +class OYMotionAP001 : public AbstractDexHand { public: static constexpr size_t MOTOR_COUNT = 6; explicit OYMotionAP001(const config::OYMotionAP001Config& config); ~OYMotionAP001() override; - std::string typeName() const override { return "OYMotionAP001"; } + std::string typeName() const override { return type_name_; } bool init() override; bool start() override; bool stop() override; @@ -30,11 +30,18 @@ public: void setVelocities(const std::vector& values) override; void setForce(const std::vector& values) override; void setTactilePollingRegions(const std::vector& regions) override; + bool acquireSensorDataStream() override; + void releaseSensorDataStream() override; std::vector getSensorData() override; TactileRegionData getSensorData(FingerType finger, TactileRegion region) override; ResultantForce getResultantForce(FingerType finger, TactileRegion region) override; ForceNewtons getResultantForceNewtons(FingerType finger, TactileRegion region) override; +protected: + OYMotionAP001(std::string id, std::string can_interface, + uint32_t hand_id, uint32_t master_id, + uint32_t command_timeout_ms, std::string type_name); + private: static uint32_t sdkMillis(); static void sdkDelay(uint32_t milliseconds); @@ -50,8 +57,9 @@ private: void setState(Status state); std::array normalizedPositions(const std::vector& values, int maximum) const; - config::OYMotionAP001Config config_; + std::string type_name_{"OYMotionAP001"}; std::string can_interface_; + uint32_t command_timeout_ms_{255}; uint8_t hand_id_{2}; uint8_t master_id_{1}; int socket_fd_{-1}; @@ -67,6 +75,8 @@ private: std::vector tactile_regions_; static constexpr size_t INDEX_TACTILE_COUNT = 60; std::atomic tactile_running_{false}; + std::mutex tactile_subscription_mutex_; + size_t tactile_subscriber_count_{0}; std::thread tactile_thread_; mutable std::mutex tactile_mutex_; std::array index_tactile_{}; diff --git a/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp b/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp index 4eb24162..e5c81780 100644 --- a/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp +++ b/cmvr-es/devices/dexhand/oymotion_ap001/src/oymotion_ap001.cpp @@ -60,11 +60,20 @@ struct TactileSnapshot { }; } -OYMotionAP001::OYMotionAP001(const config::OYMotionAP001Config& config) : config_(config) { - id_ = config.id(); - can_interface_ = config.can_interface().empty() ? "can0" : config.can_interface(); - if (config.hand_id() > 0 && config.hand_id() <= 0xff) hand_id_ = static_cast(config.hand_id()); - if (config.master_id() > 0 && config.master_id() <= 0xff) master_id_ = static_cast(config.master_id()); +OYMotionAP001::OYMotionAP001(const config::OYMotionAP001Config& config) + : OYMotionAP001(config.id(), config.can_interface(), config.hand_id(), + config.master_id(), config.command_timeout_ms(), + "OYMotionAP001") {} + +OYMotionAP001::OYMotionAP001(std::string id, std::string can_interface, + uint32_t hand_id, uint32_t master_id, + uint32_t command_timeout_ms, std::string type_name) + : type_name_(std::move(type_name)), + can_interface_(can_interface.empty() ? "can0" : std::move(can_interface)), + command_timeout_ms_(command_timeout_ms == 0 ? 255 : command_timeout_ms) { + id_ = std::move(id); + if (hand_id > 0 && hand_id <= 0xff) hand_id_ = static_cast(hand_id); + if (master_id > 0 && master_id <= 0xff) master_id_ = static_cast(master_id); } OYMotionAP001::~OYMotionAP001() { stop(); } @@ -121,26 +130,27 @@ bool OYMotionAP001::init() { HAND_SetTimerFunction(sdkMillis, sdkDelay); sdk_context_ = HAND_CreateContext(this, HAND_PROTOCOL_UART, master_id_, sdkSend, sdkReceive); if (!sdk_context_) { setFault("[OYMotionAP001] HAND_CreateContext failed"); return false; } - HAND_SetCommandTimeOut(sdk_context_, static_cast(config_.command_timeout_ms() > 0 ? std::min(config_.command_timeout_ms(), 65535) : 255)); + HAND_SetCommandTimeOut(sdk_context_, static_cast( + std::min(command_timeout_ms_, 65535))); uint8_t major = 0, minor = 0, remote_error = 0; if (!checkSdkResult(HAND_GetProtocolVersion(sdk_context_, hand_id_, &major, &minor, &remote_error), remote_error, "HAND_GetProtocolVersion")) return false; CMVR_LOG(INFO) << "[OYMotionAP001] connected: id=" << id_ << ", interface=" << can_interface_ << ", hand_id=" << static_cast(hand_id_) << ", protocol=" << static_cast(major) << "." << static_cast(minor); setState(Status::INITIALIZED); - // DeviceManager constructs and initializes devices during startup, but the - // application does not call DeviceManager::start(). Start the independent - // tactile sampler as soon as the AP001 connection is ready. - startTactilePolling(); return true; } bool OYMotionAP001::start() { if (!init()) return false; setState(Status::STREAMING); - startTactilePolling(); return true; } bool OYMotionAP001::stop() { - stopTactilePolling(); + { + std::lock_guard subscription_lock( + tactile_subscription_mutex_); + tactile_subscriber_count_ = 0; + stopTactilePolling(); + } std::lock_guard io_lock(io_mutex_); if (sdk_context_) { HAND_FreeContext(sdk_context_); sdk_context_ = nullptr; } if (socket_fd_ >= 0) { close(socket_fd_); socket_fd_ = -1; } @@ -253,11 +263,34 @@ void OYMotionAP001::setForce(const std::vector& values) { void OYMotionAP001::setTactilePollingRegions( const std::vector& regions) { + if (!hasTactileFeedback()) return; std::lock_guard lock(io_mutex_); tactile_regions_ = regions; } +bool OYMotionAP001::acquireSensorDataStream() { + if (!hasTactileFeedback()) return false; + std::lock_guard lock(tactile_subscription_mutex_); + ++tactile_subscriber_count_; + if (tactile_subscriber_count_ == 1) { + { + std::lock_guard tactile_lock(tactile_mutex_); + index_tactile_valid_ = false; + } + startTactilePolling(); + } + return true; +} + +void OYMotionAP001::releaseSensorDataStream() { + std::lock_guard lock(tactile_subscription_mutex_); + if (tactile_subscriber_count_ == 0) return; + --tactile_subscriber_count_; + if (tactile_subscriber_count_ == 0) stopTactilePolling(); +} + void OYMotionAP001::startTactilePolling() { + if (!hasTactileFeedback()) return; bool expected = false; if (!tactile_running_.compare_exchange_strong(expected, true)) return; tactile_thread_ = std::thread(&OYMotionAP001::tactilePollingLoop, this); @@ -324,6 +357,7 @@ void OYMotionAP001::tactilePollingLoop() { } std::vector OYMotionAP001::getSensorData() { + if (!hasTactileFeedback()) return {}; auto snapshot = std::make_shared(); { std::lock_guard lock(tactile_mutex_); diff --git a/cmvr-es/service/grpc/src/grpc_dexhand_service.cpp b/cmvr-es/service/grpc/src/grpc_dexhand_service.cpp index dfe59861..e4582fb9 100644 --- a/cmvr-es/service/grpc/src/grpc_dexhand_service.cpp +++ b/cmvr-es/service/grpc/src/grpc_dexhand_service.cpp @@ -26,6 +26,24 @@ using namespace cmvr::device; #define DEXHAND_MAX_SPEED 1000 namespace { +class SensorDataStreamLease { +public: + explicit SensorDataStreamLease( + std::shared_ptr device) + : device_(std::move(device)), + acquired_(device_ && device_->acquireSensorDataStream()) {} + + ~SensorDataStreamLease() { + if (acquired_) device_->releaseSensorDataStream(); + } + + bool acquired() const noexcept { return acquired_; } + +private: + std::shared_ptr device_; + bool acquired_{false}; +}; + constexpr int kDexHandDofCount = 6; @@ -198,6 +216,9 @@ grpc::Status gRPCDexHandServiceImpl::GetStatus(grpc::ServerContext* context, DexHandState state{}; dev->getState(state); response->mutable_state()->set_is_initialized(state.is_initialized); + response->mutable_state()->set_has_tactile_feedback( + dev->hasTactileFeedback()); + response->mutable_state()->set_model(dev->model()); for (int i = 0; i < kDexHandDofCount; i++) { auto hand = response->mutable_state()->add_hands(); hand->set_dof_id(i); @@ -433,6 +454,17 @@ grpc::Status gRPCDexHandServiceImpl::GetSensorData(grpc::ServerContext* context if (!dev) { return failResponse(response, "DexHand device not found: " + dev_id); } + if (!dev->hasTactileFeedback()) { + return failResponse(response, + "DexHand device does not support tactile feedback: " + dev_id); + } + SensorDataStreamLease sensor_lease(dev); + if (!sensor_lease.acquired()) { + return failResponse(response, + "Failed to start tactile acquisition: " + dev_id); + } + if (std::dynamic_pointer_cast(dev)) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); maybeConfigureRh56FullTactilePolling(dev); appendSensorData(dev->getSensorData(), response); response->mutable_header()->set_success(true); @@ -469,6 +501,27 @@ grpc::Status gRPCDexHandServiceImpl::GetSensorDataStream(grpc::ServerContext* co stream->Write(response); return grpc::Status::OK; } + if (!dev->hasTactileFeedback()) { + api::GetSensorDataStreamCommand_Feedback response; + response.mutable_header()->set_success(false); + response.mutable_header()->set_error_message( + "DexHand device does not support tactile feedback: " + dev_id); + setCurrentTimestamp(response.mutable_header()->mutable_timestamp()); + stream->Write(response); + return grpc::Status::OK; + } + SensorDataStreamLease sensor_lease(dev); + if (!sensor_lease.acquired()) { + api::GetSensorDataStreamCommand_Feedback response; + response.mutable_header()->set_success(false); + response.mutable_header()->set_error_message( + "Failed to start tactile acquisition: " + dev_id); + setCurrentTimestamp(response.mutable_header()->mutable_timestamp()); + stream->Write(response); + return grpc::Status::OK; + } + if (std::dynamic_pointer_cast(dev)) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); maybeConfigureRh56FullTactilePolling(dev); CMVR_LOG(DEBUG) << "[gRPCDexHandServiceImpl] (GetSensorDataStream): streaming success, id=" << dev_id; const auto stream_interval = diff --git a/protos/cmvr/api/dexhand_command.proto b/protos/cmvr/api/dexhand_command.proto index 9d65a7f8..8ff1bb35 100644 --- a/protos/cmvr/api/dexhand_command.proto +++ b/protos/cmvr/api/dexhand_command.proto @@ -58,6 +58,8 @@ message SensorData { message DexHandState { bool is_initialized = 1; // 是否初始化 repeated FreedomState hands = 2; // 包含多个自由度状态 + bool has_tactile_feedback = 3; // 是否具备真实触觉传感器反馈能力 + string model = 4; // 设备型号,仅作为描述信息 } message GetDexHandStateCommand { @@ -146,4 +148,4 @@ message GetSensorDataStreamCommand { CommandHeader.Feedback header = 1; repeated SensorData sensor = 2;//所有传感器的数据 } -} \ No newline at end of file +} diff --git a/protos/cmvr/config/dexhand_config/dexhand_config.proto b/protos/cmvr/config/dexhand_config/dexhand_config.proto index 210d1801..3f6f6c79 100644 --- a/protos/cmvr/config/dexhand_config/dexhand_config.proto +++ b/protos/cmvr/config/dexhand_config/dexhand_config.proto @@ -53,16 +53,20 @@ message OYMotionAP001Config { uint32 command_timeout_ms = 5; } - - message DexHandDeviceConfig { string id = 1; - reserved 2; + // Human-readable hardware model. This is metadata only and must not drive + // device behavior. + string model = 2; + // Whether this device provides real tactile sensor feedback. Motor-current + // estimates do not count as tactile feedback. + optional bool has_tactile_feedback = 3; oneof backend { RH56DFTPDexHandConfig rh56dftp = 10; PX6AXGen3 px_6ax_gen3 = 11; ZeroSimTouchDexHand zero_sim_touch = 12; + // Shared OYMotion backend for AP001, LiteS001 and compatible hands. OYMotionAP001Config oymotion_ap001 = 13; } }