From 1360746edb7a58336a8e27f69620170895391b94 Mon Sep 17 00:00:00 2001 From: linbo <1034003879@qq.com> Date: Mon, 12 Oct 2026 10:31:54 +0800 Subject: [PATCH] feat: report arm motor current and servo state --- cmvr-es/common/types/arm/arm_types.h | 4 +++- cmvr-es/config/manager/task_manager.pb.txt | 2 +- .../devices/arm/motor_robot_arm/include/motor_robot_arm.h | 1 + .../devices/arm/motor_robot_arm/src/motor_robot_arm.cpp | 8 ++++++-- cmvr-es/service/grpc/src/grpc_arm_service.cpp | 2 ++ protos/cmvr/api/arm_command.proto | 2 ++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmvr-es/common/types/arm/arm_types.h b/cmvr-es/common/types/arm/arm_types.h index 3b53834a..12640271 100644 --- a/cmvr-es/common/types/arm/arm_types.h +++ b/cmvr-es/common/types/arm/arm_types.h @@ -131,12 +131,14 @@ struct JointGroupState { std::vector position; std::vector velocity; std::vector effort; + std::vector current; bool validForModel(const RobotModel& model) const { return position.size() == model.dof && velocity.size() == model.dof && - (effort.empty() || effort.size() == model.dof); + (effort.empty() || effort.size() == model.dof) && + (current.empty() || current.size() == model.dof); } }; diff --git a/cmvr-es/config/manager/task_manager.pb.txt b/cmvr-es/config/manager/task_manager.pb.txt index d267306c..3d507b94 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: true + enable: false } } diff --git a/cmvr-es/devices/arm/motor_robot_arm/include/motor_robot_arm.h b/cmvr-es/devices/arm/motor_robot_arm/include/motor_robot_arm.h index bd3f5c8d..6ddb1734 100644 --- a/cmvr-es/devices/arm/motor_robot_arm/include/motor_robot_arm.h +++ b/cmvr-es/devices/arm/motor_robot_arm/include/motor_robot_arm.h @@ -144,6 +144,7 @@ private: mutable std::mutex mutex_; std::atomic busy_{false}; + std::atomic powered_on_{false}; double speed_scaling_{1.0}; std::atomic protective_stopped_{false}; std::atomic emergency_stopped_{false}; diff --git a/cmvr-es/devices/arm/motor_robot_arm/src/motor_robot_arm.cpp b/cmvr-es/devices/arm/motor_robot_arm/src/motor_robot_arm.cpp index f19328b2..7fbfb810 100644 --- a/cmvr-es/devices/arm/motor_robot_arm/src/motor_robot_arm.cpp +++ b/cmvr-es/devices/arm/motor_robot_arm/src/motor_robot_arm.cpp @@ -144,8 +144,8 @@ ArmState MotorRobotArm::getRobotState() const const bool emergency_stopped = emergency_stopped_.load(); ArmState state; state.connected = motor_manager_ != nullptr; - state.powered_on = true; - state.brake_released = !emergency_stopped; + state.powered_on = powered_on_.load(); + state.brake_released = powered_on_.load() && !emergency_stopped; state.moving = busy(); state.protective_stopped = protective_stopped; state.emergency_stopped = emergency_stopped; @@ -165,6 +165,7 @@ JointGroupState MotorRobotArm::getJointState() const state.position.reserve(joint_names_.size()); state.velocity.reserve(joint_names_.size()); state.effort.reserve(joint_names_.size()); + state.current.reserve(joint_names_.size()); for (const auto& joint_name : joint_names_) { auto motor = getMotor_(joint_name); if (!motor) { @@ -173,6 +174,7 @@ JointGroupState MotorRobotArm::getJointState() const state.position.push_back(motor->getQ()); state.velocity.push_back(motor->getQd()); state.effort.push_back(0.0); + state.current.push_back(static_cast(motor->getCurrent())); } return state; } @@ -219,6 +221,7 @@ Result MotorRobotArm::torqueOn() } } emergency_stopped_.store(false); + powered_on_.store(true); return Result::success(); } @@ -234,6 +237,7 @@ Result MotorRobotArm::torqueOff() "failed to torque off motor for joint: " + joint_name); } } + powered_on_.store(false); return Result::success(); } diff --git a/cmvr-es/service/grpc/src/grpc_arm_service.cpp b/cmvr-es/service/grpc/src/grpc_arm_service.cpp index 3dd63f1d..8ef492dc 100644 --- a/cmvr-es/service/grpc/src/grpc_arm_service.cpp +++ b/cmvr-es/service/grpc/src/grpc_arm_service.cpp @@ -102,6 +102,7 @@ void fillJointState(api::JointState* dst, for (const double value : src.position) dst->add_position(value); for (const double value : src.velocity) dst->add_velocity(value); for (const double value : src.effort) dst->add_effort(value); + for (const double value : src.current) dst->add_current(value); dst->set_timestamp(timestamp); } @@ -592,6 +593,7 @@ grpc::Status gRPCArmServiceImpl::getJointState(grpc::ServerContext*, for (double v : state.position) msg->add_position(v); for (double v : state.velocity) msg->add_velocity(v); for (double v : state.effort) msg->add_effort(v); + for (double v : state.current) msg->add_current(v); fillFeedback(response->mutable_header(), true); // CMVR_LOG(DEBUG) << "[gRPCArmServiceImpl] (getJointState): success, id=" << device_id // << ", joints=" << msg->name_size() diff --git a/protos/cmvr/api/arm_command.proto b/protos/cmvr/api/arm_command.proto index 024a0700..f91364f1 100644 --- a/protos/cmvr/api/arm_command.proto +++ b/protos/cmvr/api/arm_command.proto @@ -263,6 +263,8 @@ message JointState { repeated double effort = 4; // 状态采样的 Unix 时间戳,单位:s。 double timestamp = 5; + // 电机实际电流,单位:mA。 + repeated double current = 6; } // 查询关节状态的请求。