feat: update dexhand support and robot device configs

This commit is contained in:
xtkuang 2026-10-09 09:16:10 +08:00
parent 69b06d80c6
commit 8e2a8615dd
13 changed files with 225 additions and 29 deletions

View File

@ -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
}
}
}
}

View File

@ -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 {}
}
}

View File

@ -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"
}
}
}

View File

@ -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 {

View File

@ -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
}
}

View File

@ -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"

View File

@ -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<TactileRegionKey>& 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<TactileRegionData> 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<int>&) {
CMVR_LOG(ERROR) << "[AbstractDexHand] setForce is not supported by this dexhand abstraction.";
}
private:
bool has_tactile_feedback_{false};
std::string model_;
};
}

View File

@ -25,22 +25,27 @@ public:
return nullptr;
}
std::shared_ptr<AbstractDexHand> device;
switch (cfg.backend_case()) {
case config::DexHandDeviceConfig::kRh56Dftp:
return std::make_shared<RH56DFTPDexhand>(
device = std::make_shared<RH56DFTPDexhand>(
backendWithId_(cfg.id(), cfg.rh56dftp()));
break;
case config::DexHandDeviceConfig::kPx6AxGen3:
return std::make_shared<PX6AXGen3>(
device = std::make_shared<PX6AXGen3>(
backendWithId_(cfg.id(), cfg.px_6ax_gen3()));
break;
case config::DexHandDeviceConfig::kZeroSimTouch:
return std::make_shared<ZeroSimTouchDexHand>(
device = std::make_shared<ZeroSimTouchDexHand>(
backendWithId_(cfg.id(), cfg.zero_sim_touch()));
break;
case config::DexHandDeviceConfig::kOymotionAp001:
return std::make_shared<OYMotionAP001>(
device = std::make_shared<OYMotionAP001>(
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:

View File

@ -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<int>& values) override;
void setForce(const std::vector<int>& values) override;
void setTactilePollingRegions(const std::vector<TactileRegionKey>& regions) override;
bool acquireSensorDataStream() override;
void releaseSensorDataStream() override;
std::vector<TactileRegionData> 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<uint16_t, MOTOR_COUNT> normalizedPositions(const std::vector<int>& 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<TactileRegionKey> tactile_regions_;
static constexpr size_t INDEX_TACTILE_COUNT = 60;
std::atomic<bool> 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<TactilePoint, INDEX_TACTILE_COUNT> index_tactile_{};

View File

@ -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<uint8_t>(config.hand_id());
if (config.master_id() > 0 && config.master_id() <= 0xff) master_id_ = static_cast<uint8_t>(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<uint8_t>(hand_id);
if (master_id > 0 && master_id <= 0xff) master_id_ = static_cast<uint8_t>(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<uint16_t>(config_.command_timeout_ms() > 0 ? std::min<uint32_t>(config_.command_timeout_ms(), 65535) : 255));
HAND_SetCommandTimeOut(sdk_context_, static_cast<uint16_t>(
std::min<uint32_t>(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<int>(hand_id_) << ", protocol=" << static_cast<int>(major) << "." << static_cast<int>(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<std::mutex> subscription_lock(
tactile_subscription_mutex_);
tactile_subscriber_count_ = 0;
stopTactilePolling();
}
std::lock_guard<std::mutex> 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<int>& values) {
void OYMotionAP001::setTactilePollingRegions(
const std::vector<TactileRegionKey>& regions) {
if (!hasTactileFeedback()) return;
std::lock_guard<std::mutex> lock(io_mutex_);
tactile_regions_ = regions;
}
bool OYMotionAP001::acquireSensorDataStream() {
if (!hasTactileFeedback()) return false;
std::lock_guard<std::mutex> lock(tactile_subscription_mutex_);
++tactile_subscriber_count_;
if (tactile_subscriber_count_ == 1) {
{
std::lock_guard<std::mutex> tactile_lock(tactile_mutex_);
index_tactile_valid_ = false;
}
startTactilePolling();
}
return true;
}
void OYMotionAP001::releaseSensorDataStream() {
std::lock_guard<std::mutex> 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<AbstractDexHand::TactileRegionData> OYMotionAP001::getSensorData() {
if (!hasTactileFeedback()) return {};
auto snapshot = std::make_shared<TactileSnapshot>();
{
std::lock_guard<std::mutex> lock(tactile_mutex_);

View File

@ -26,6 +26,24 @@ using namespace cmvr::device;
#define DEXHAND_MAX_SPEED 1000
namespace {
class SensorDataStreamLease {
public:
explicit SensorDataStreamLease(
std::shared_ptr<AbstractDexHand> device)
: device_(std::move(device)),
acquired_(device_ && device_->acquireSensorDataStream()) {}
~SensorDataStreamLease() {
if (acquired_) device_->releaseSensorDataStream();
}
bool acquired() const noexcept { return acquired_; }
private:
std::shared_ptr<AbstractDexHand> 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<OYMotionAP001>(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<OYMotionAP001>(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 =

View File

@ -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;//所有传感器的数据
}
}
}

View File

@ -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;
}
}