From 5015077cb56b9ed0ecfaf4583eceaf49b9147554 Mon Sep 17 00:00:00 2001 From: xtkuang <87661715@qq.com> Date: Fri, 3 Jul 2026 08:55:30 +0800 Subject: [PATCH] fix aubo arm connection error --- cmvr-es/config/devices/arm/aubo_arm.pb.txt | 2 +- cmvr-es/config/manager/device_manager.pb.txt | 2 +- cmvr-es/devices/arm/aubo_arm/aubo_arm.cpp | 60 +++++++++++++++++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/cmvr-es/config/devices/arm/aubo_arm.pb.txt b/cmvr-es/config/devices/arm/aubo_arm.pb.txt index 0f357de6..551f31df 100644 --- a/cmvr-es/config/devices/arm/aubo_arm.pb.txt +++ b/cmvr-es/config/devices/arm/aubo_arm.pb.txt @@ -5,7 +5,7 @@ arm { vendor { brand: VENDOR_ROBOT_ARM_BRAND_AUBO_ARM ip: "192.168.192.18" - port: 30000 + port: 30004 dof: 6 joint_names: "joint_1" joint_names: "joint_2" diff --git a/cmvr-es/config/manager/device_manager.pb.txt b/cmvr-es/config/manager/device_manager.pb.txt index bcf234b8..fc3a4e1e 100644 --- a/cmvr-es/config/manager/device_manager.pb.txt +++ b/cmvr-es/config/manager/device_manager.pb.txt @@ -42,7 +42,7 @@ device_manager { id: "aubo_arm" type: DEVICE_TYPE_ROBOT_ARM config_file: "devices/arm/aubo_arm.pb.txt" - enable: false + enable: true } devices { diff --git a/cmvr-es/devices/arm/aubo_arm/aubo_arm.cpp b/cmvr-es/devices/arm/aubo_arm/aubo_arm.cpp index c0e73039..19669f23 100644 --- a/cmvr-es/devices/arm/aubo_arm/aubo_arm.cpp +++ b/cmvr-es/devices/arm/aubo_arm/aubo_arm.cpp @@ -527,13 +527,53 @@ Result AuboArm::connect(const std::string& ip, const int port) #if defined(CMVR_HAS_AUBO_SDK) try { - sdk_ = std::make_unique(); - sdk_->rpc_client = std::make_shared(); - sdk_->rpc_client->setRequestTimeout(1000); - sdk_->rpc_client->connect(ip, port > 0 ? port : 30004); - sdk_->rpc_client->login(username_, password_); + const int resolved_port = port > 0 ? port : 30004; + auto sdk_state = std::make_unique(); + sdk_state->rpc_client = std::shared_ptr( + ::createRpcClient(), + [](arcs::aubo_sdk::RpcClient* client) { + if (client) { + ::destroyRpcClient(client); + } + }); + if (!sdk_state->rpc_client) { + return Result::failure(ArmErrorCode::ConnectionFailed, + "[AuboArm] connect failed: create RPC client failed"); + } + + sdk_state->rpc_client->setRequestTimeout(1000); + int ret = sdk_state->rpc_client->connect(ip, resolved_port); + if (ret != 0) { + return Result::failure(ArmErrorCode::ConnectionFailed, + "[AuboArm] connect failed: rpc connect ret=" + + std::to_string(ret) + ", ip=" + ip + + ", port=" + std::to_string(resolved_port)); + } + + ret = sdk_state->rpc_client->login(username_, password_); + if (ret != 0) { + if (sdk_state->rpc_client->hasConnected()) { + sdk_state->rpc_client->disconnect(); + } + return Result::failure(ArmErrorCode::ConnectionFailed, + "[AuboArm] connect failed: login ret=" + std::to_string(ret)); + } + + const auto robot_names = sdk_state->rpc_client->getRobotNames(); + if (robot_names.empty()) { + if (sdk_state->rpc_client->hasLogined()) { + sdk_state->rpc_client->logout(); + } + if (sdk_state->rpc_client->hasConnected()) { + sdk_state->rpc_client->disconnect(); + } + return Result::failure(ArmErrorCode::ConnectionFailed, + "[AuboArm] connect failed: robot name list is empty"); + } + ip_ = ip; - port_ = port > 0 ? port : 30004; + port_ = resolved_port; + sdk_ = std::move(sdk_state); connected_.store(true); return Result::success(); } catch (const std::exception& e) { @@ -554,8 +594,12 @@ Result AuboArm::disconnect() #if defined(CMVR_HAS_AUBO_SDK) try { if (sdk_ && sdk_->rpc_client) { - sdk_->rpc_client->logout(); - sdk_->rpc_client->disconnect(); + if (sdk_->rpc_client->hasLogined()) { + sdk_->rpc_client->logout(); + } + if (sdk_->rpc_client->hasConnected()) { + sdk_->rpc_client->disconnect(); + } } } catch (const std::exception& e) { CMVR_LOG(ERROR) << "[AuboArm] disconnect failed: " << e.what();