fix aubo arm connection error
This commit is contained in:
parent
d04b1920d1
commit
5015077cb5
@ -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"
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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<SdkState>();
|
||||
sdk_->rpc_client = std::make_shared<arcs::aubo_sdk::RpcClient>();
|
||||
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<SdkState>();
|
||||
sdk_state->rpc_client = std::shared_ptr<arcs::aubo_sdk::RpcClient>(
|
||||
::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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user