feat:add arm motion config
This commit is contained in:
parent
8656f3fae8
commit
b93e482b6a
29
cmvr-es/config/devices/arm/tchl_arm.pb.txt
Normal file
29
cmvr-es/config/devices/arm/tchl_arm.pb.txt
Normal file
@ -0,0 +1,29 @@
|
||||
# 七轴纯关节运动配置;MoveJ 目标向量按 joint_names 的顺序填写。
|
||||
arm {
|
||||
robot_arms {
|
||||
id: "tchl_arm"
|
||||
|
||||
motor {
|
||||
motor_system_id: "tchl_joint_motors"
|
||||
motor_group_ids: "tchl_joint_motors"
|
||||
dof: 6
|
||||
joint_names: "TCHL_AXIS_1"
|
||||
joint_names: "TCHL_AXIS_2"
|
||||
joint_names: "TCHL_AXIS_3"
|
||||
joint_names: "TCHL_AXIS_4"
|
||||
joint_names: "TCHL_AXIS_5"
|
||||
joint_names: "TCHL_AXIS_6"
|
||||
upd_freq: 1000
|
||||
}
|
||||
|
||||
motion {
|
||||
# 未指定平滑器时,使用五次 B 样条,采样周期 1 ms。
|
||||
move_j {
|
||||
settle_timeout_s: 2.0
|
||||
settle_position_tolerance_rad: 0.002
|
||||
settle_velocity_tolerance_rad_s: 0.02
|
||||
settle_stable_sample_count: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
cmvr-es/config/devices/motor/tchl_multi_motors.pb.txt
Normal file
61
cmvr-es/config/devices/motor/tchl_multi_motors.pb.txt
Normal file
@ -0,0 +1,61 @@
|
||||
# 同川 TC600E TR 七轴模板;设备管理器默认不启用。
|
||||
# 各轴按实机确认 PrD.00、电子齿轮、编码器分辨率和减速比。
|
||||
# 以下 131072 / 101 仅为 PrD.00=0、电子齿轮 1:1 的配置示例。
|
||||
motor {
|
||||
id: "tchl_motors"
|
||||
|
||||
motor_groups {
|
||||
id: "tchl_joint_motors"
|
||||
bus_type: MOTOR_BUS_ETHERCAT
|
||||
vendor: MOTOR_VENDOR_TCHL
|
||||
protocol: MOTOR_PROTOCOL_ETHERCAT_CIA402
|
||||
|
||||
ethercat {
|
||||
master_index: 0
|
||||
cycle_us: 1000
|
||||
slave_op_timeout_ms: 12000
|
||||
slave_state_poll_period_ms: 10
|
||||
|
||||
cia402 {
|
||||
state_transition_timeout_ms: 1200
|
||||
velocity_stop_timeout_ms: 2000
|
||||
status_poll_period_ms: 10
|
||||
stopped_velocity_tolerance_rad_s: 0.001
|
||||
}
|
||||
|
||||
dc { enable: false }
|
||||
|
||||
slaves { motor_id: 1 alias: 0 position: 0 }
|
||||
slaves { motor_id: 2 alias: 0 position: 1 }
|
||||
slaves { motor_id: 3 alias: 0 position: 2 }
|
||||
slaves { motor_id: 4 alias: 0 position: 3 }
|
||||
slaves { motor_id: 5 alias: 0 position: 4 }
|
||||
slaves { motor_id: 6 alias: 0 position: 5 }
|
||||
|
||||
}
|
||||
|
||||
# 示例限位;启用设备前按各轴实际行程和允许速度、加速度填写。
|
||||
# q: rad,qd: rad/s,qdd: rad/s^2。
|
||||
joint_limits {
|
||||
enable: true
|
||||
source: JOINT_LIMIT_SOURCE_CUSTOM
|
||||
joints { joint_name: "TCHL_AXIS_1" q_lb: -1.0 q_ub: 1.0 qd: 0.5 qdd: 1.0 }
|
||||
joints { joint_name: "TCHL_AXIS_2" q_lb: -1.0 q_ub: 1.0 qd: 0.5 qdd: 1.0 }
|
||||
joints { joint_name: "TCHL_AXIS_3" q_lb: -1.0 q_ub: 1.0 qd: 0.5 qdd: 1.0 }
|
||||
joints { joint_name: "TCHL_AXIS_4" q_lb: -1.0 q_ub: 1.0 qd: 0.5 qdd: 1.0 }
|
||||
joints { joint_name: "TCHL_AXIS_5" q_lb: -1.0 q_ub: 1.0 qd: 0.5 qdd: 1.0 }
|
||||
joints { joint_name: "TCHL_AXIS_6" q_lb: -1.0 q_ub: 1.0 qd: 0.5 qdd: 1.0 }
|
||||
|
||||
}
|
||||
|
||||
motors {
|
||||
motors { id: 1 joint_name: "TCHL_AXIS_1" encoder_counts_per_rev: 131072 gear_ratio: 101 }
|
||||
motors { id: 2 joint_name: "TCHL_AXIS_2" encoder_counts_per_rev: 131072 gear_ratio: 101 }
|
||||
motors { id: 3 joint_name: "TCHL_AXIS_3" encoder_counts_per_rev: 131072 gear_ratio: 101 }
|
||||
motors { id: 4 joint_name: "TCHL_AXIS_4" encoder_counts_per_rev: 131072 gear_ratio: 101 }
|
||||
motors { id: 5 joint_name: "TCHL_AXIS_5" encoder_counts_per_rev: 131072 gear_ratio: 101 }
|
||||
motors { id: 6 joint_name: "TCHL_AXIS_6" encoder_counts_per_rev: 131072 gear_ratio: 101 }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,42 +6,42 @@ device_manager {
|
||||
id: "mujoco_world"
|
||||
type: DEVICE_TYPE_MUJOCO_WORLD
|
||||
config_file: "devices/mujoco/right_arm_eye_to_hand_world.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "right_arm_mujoco_motors"
|
||||
type: DEVICE_TYPE_MOTOR_SYSTEM
|
||||
config_file: "devices/motor/mujoco_motors.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "mujoco_right_arm"
|
||||
type: DEVICE_TYPE_ROBOT_ARM
|
||||
config_file: "devices/arm/arm_mujoco_qp.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "mujoco_viewer"
|
||||
type: DEVICE_TYPE_MUJOCO_VIEWER
|
||||
config_file: "devices/mujoco/mujoco_viewer.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "mujoco_hand_cam"
|
||||
type: DEVICE_TYPE_CAMERA
|
||||
config_file: "devices/camera/camera.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "mujoco_external_touch_cam"
|
||||
type: DEVICE_TYPE_CAMERA
|
||||
config_file: "devices/camera/camera.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
@ -77,7 +77,7 @@ device_manager {
|
||||
id: "mujoco_zero_touch_dexhand"
|
||||
type: DEVICE_TYPE_DEXHAND
|
||||
config_file: "devices/dexhand/dexhand.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
@ -213,4 +213,18 @@ device_manager {
|
||||
enable: false
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "tchl_joint_motors"
|
||||
type: DEVICE_TYPE_MOTOR_SYSTEM
|
||||
config_file: "devices/motor/tchl_multi_motors.pb.txt"
|
||||
enable: true
|
||||
}
|
||||
|
||||
devices {
|
||||
id: "tchl_arm"
|
||||
type: DEVICE_TYPE_ROBOT_ARM
|
||||
config_file: "devices/arm/tchl_arm.pb.txt"
|
||||
enable: true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ task_manager {
|
||||
run_mode: TASK_RUN_MODE_PERIODIC_STEP
|
||||
control_period_s: 0.001
|
||||
config_file: "tasks/touch_screen_task/touch_screen_task_mujoco.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
tasks {
|
||||
id: "grpc_server"
|
||||
|
||||
@ -173,15 +173,23 @@ ArmState MotorRobotArm::getRobotState() const
|
||||
state.safety_mode = getSafetyMode();
|
||||
state.control_mode = ControlMode::Position;
|
||||
state.actual_joint_state = getJointState();
|
||||
auto solver = std::dynamic_pointer_cast<cmvr::PinocchioIKBase>(ik_solver_);
|
||||
const auto& q = state.actual_joint_state.position;
|
||||
const auto& qd = state.actual_joint_state.velocity;
|
||||
if (q.size() != getDof() || qd.size() != getDof() ||
|
||||
!std::all_of(q.begin(), q.end(), [](double v) { return std::isfinite(v); }) ||
|
||||
!std::all_of(qd.begin(), qd.end(), [](double v) { return std::isfinite(v); })) {
|
||||
state.fault = true;
|
||||
state.robot_mode = RobotMode::Fault;
|
||||
return state;
|
||||
}
|
||||
if (!ik_solver_) {
|
||||
return state;
|
||||
}
|
||||
auto solver = std::dynamic_pointer_cast<cmvr::PinocchioIKBase>(ik_solver_);
|
||||
Eigen::Matrix4d pose;
|
||||
Eigen::MatrixXd jacobian;
|
||||
Eigen::Matrix3d rotation;
|
||||
if (solver && q.size() == getDof() && qd.size() == getDof() &&
|
||||
std::all_of(qd.begin(), qd.end(), [](double v) { return std::isfinite(v); }) &&
|
||||
solver->computePoseAndJacobianBaseAtQ(q, true, pose, jacobian, rotation)) {
|
||||
if (solver && solver->computePoseAndJacobianBaseAtQ(q, true, pose, jacobian, rotation)) {
|
||||
state.actual_tcp_pose = common::math::matrixToPose(pose);
|
||||
const Eigen::Matrix<double, 6, 1> twist = jacobian *
|
||||
Eigen::Map<const Eigen::VectorXd>(qd.data(), static_cast<Eigen::Index>(qd.size()));
|
||||
@ -721,9 +729,22 @@ Result MotorRobotArm::moveJ(const JointPositionCommand& target, const MotionOpti
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
Eigen::VectorXd lower, upper, joint_velocity;
|
||||
if (!ik_solver_ || !ik_solver_->getJointPositionLimits(lower, upper) ||
|
||||
!ik_solver_->getJointVelocityLimits(joint_velocity) ||
|
||||
lower.size() != dof_ || upper.size() != dof_ || joint_velocity.size() != dof_) {
|
||||
if (ik_solver_) {
|
||||
if (!ik_solver_->getJointPositionLimits(lower, upper) ||
|
||||
!ik_solver_->getJointVelocityLimits(joint_velocity) ||
|
||||
lower.size() != dof_ || upper.size() != dof_ || joint_velocity.size() != dof_) {
|
||||
return Result::failure(ArmErrorCode::RobotNotReady, "moveJ cannot read joint limits");
|
||||
}
|
||||
} else if (model_.joint_limits.size() == getDof()) {
|
||||
lower.resize(dof_);
|
||||
upper.resize(dof_);
|
||||
joint_velocity.resize(dof_);
|
||||
for (std::size_t j = 0; j < getDof(); ++j) {
|
||||
lower[j] = model_.joint_limits[j].lower;
|
||||
upper[j] = model_.joint_limits[j].upper;
|
||||
joint_velocity[j] = model_.joint_limits[j].max_velocity;
|
||||
}
|
||||
} else {
|
||||
return Result::failure(ArmErrorCode::RobotNotReady, "moveJ cannot read joint limits");
|
||||
}
|
||||
MotionOptions limits = options;
|
||||
@ -744,6 +765,10 @@ Result MotorRobotArm::moveJ(const JointPositionCommand& target, const MotionOpti
|
||||
velocity = std::min(velocity, requested);
|
||||
}
|
||||
limits.joint_velocity_limits[j] = std::min(options.velocity, velocity);
|
||||
if (!ik_solver_ && model_.joint_limits[j].max_acceleration > 0.0) {
|
||||
limits.acceleration = std::min(limits.acceleration,
|
||||
model_.joint_limits[j].max_acceleration);
|
||||
}
|
||||
}
|
||||
const double scaling = speed_scaling_.load();
|
||||
if (!std::isfinite(scaling) || scaling <= 0.0 || scaling > 1.0) {
|
||||
@ -1858,7 +1883,10 @@ bool MotorRobotArm::configureAlgorithms_()
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& smoother_config = cfg_.motion().joint_trajectory_smoother();
|
||||
auto smoother_config = cfg_.motion().joint_trajectory_smoother();
|
||||
if (!cfg_.motion().has_joint_trajectory_smoother()) {
|
||||
smoother_config.mutable_quintic_bspline();
|
||||
}
|
||||
joint_trajectory_sample_period_s_ = smoother_config.has_sample_period_s()
|
||||
? smoother_config.sample_period_s() : 0.001;
|
||||
if (!std::isfinite(joint_trajectory_sample_period_s_) || joint_trajectory_sample_period_s_ <= 0.0) {
|
||||
@ -1870,37 +1898,63 @@ bool MotorRobotArm::configureAlgorithms_()
|
||||
return false;
|
||||
}
|
||||
|
||||
ik_solver_ = cmvr::IKSolverFactory::create(cfg_.kinematics());
|
||||
if (!ik_solver_ || !ik_solver_->init()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
model_ = ik_solver_->getRobotModel();
|
||||
model_.name = id_;
|
||||
model_.manufacturer = "cmvr";
|
||||
if (!model_.valid() || !model_.hasKinematics() || model_.joint_names != joint_names_) {
|
||||
CMVR_LOG(ERROR) << "[MotorRobotArm] robot model does not match configured joints: " << id_;
|
||||
return false;
|
||||
if (cfg_.has_kinematics()) {
|
||||
ik_solver_ = cmvr::IKSolverFactory::create(cfg_.kinematics());
|
||||
if (!ik_solver_ || !ik_solver_->init()) {
|
||||
return false;
|
||||
}
|
||||
model_ = ik_solver_->getRobotModel();
|
||||
model_.name = id_;
|
||||
model_.manufacturer = "cmvr";
|
||||
if (!model_.valid() || !model_.hasKinematics() || model_.joint_names != joint_names_) {
|
||||
CMVR_LOG(ERROR) << "[MotorRobotArm] robot model does not match configured joints: " << id_;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (cfg_.motion().has_move_l() || cfg_.motion().has_speed_l() ||
|
||||
cfg_.motion().has_joint_path()) {
|
||||
CMVR_LOG(ERROR) << "[MotorRobotArm] move_l, speed_l and joint_path require "
|
||||
"kinematics configuration: " << id_;
|
||||
return false;
|
||||
}
|
||||
model_.joint_limits.clear();
|
||||
for (const auto& joint_name : joint_names_) {
|
||||
const auto motor = getMotor_(joint_name);
|
||||
if (!motor) return false;
|
||||
const auto info = motor->motorInfo();
|
||||
if (!std::isfinite(info.limit_q_lb) || !std::isfinite(info.limit_q_ub) ||
|
||||
info.limit_q_lb >= info.limit_q_ub || !std::isfinite(info.limit_qd) ||
|
||||
info.limit_qd <= 0.0 || !std::isfinite(info.limit_qdd) || info.limit_qdd < 0.0) {
|
||||
CMVR_LOG(ERROR) << "[MotorRobotArm] invalid configured motor limits: " << joint_name;
|
||||
return false;
|
||||
}
|
||||
model_.joint_limits.push_back(JointLimit{
|
||||
info.limit_q_lb, info.limit_q_ub, info.limit_qd, info.limit_qdd});
|
||||
}
|
||||
}
|
||||
|
||||
if (!configureJointPathPlanner_()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cfg_.motion().has_move_l() && !cfg_.motion().has_speed_l()) {
|
||||
return true;
|
||||
}
|
||||
auto pinocchio_solver = std::dynamic_pointer_cast<cmvr::PinocchioIKBase>(ik_solver_);
|
||||
if (!pinocchio_solver) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& move_l = cfg_.motion().move_l();
|
||||
const auto& speed_l = cfg_.motion().speed_l();
|
||||
auto cartesian_motion = CartesianMotionPlannerFactory::createMoveL(move_l, pinocchio_solver);
|
||||
auto cartesian_velocity = CartesianMotionPlannerFactory::createSpeedL(speed_l, pinocchio_solver, getDof());
|
||||
if (!cartesian_motion || !cartesian_velocity) {
|
||||
return false;
|
||||
if (cfg_.motion().has_move_l()) {
|
||||
cartesian_planner_ = CartesianMotionPlannerFactory::createMoveL(
|
||||
cfg_.motion().move_l(), pinocchio_solver);
|
||||
if (!cartesian_planner_) return false;
|
||||
}
|
||||
|
||||
cartesian_planner_ = cartesian_motion;
|
||||
if (!cfg_.motion().has_speed_l()) return true;
|
||||
const auto& speed_l = cfg_.motion().speed_l();
|
||||
auto cartesian_velocity = CartesianMotionPlannerFactory::createSpeedL(
|
||||
speed_l, pinocchio_solver, getDof());
|
||||
if (!cartesian_velocity) return false;
|
||||
SpeedLExecutor::BeginCycleCallback begin_cycle;
|
||||
SpeedLExecutor::EndCycleCallback end_cycle;
|
||||
if (auto world = MotorManager::mujocoWorldFor(motor_system_id_)) {
|
||||
|
||||
@ -269,6 +269,40 @@ TEST_P(MotorRobotArmMujocoTest, MoveJ)
|
||||
EXPECT_LT(outcome.move_j_initial_error, 0.10);
|
||||
}
|
||||
|
||||
TEST_P(MotorRobotArmMujocoTest, MoveJWithoutKinematics)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
arm_.reset();
|
||||
arm_config_.clear_kinematics();
|
||||
arm_config_.clear_motion();
|
||||
arm_config_.mutable_motion()->mutable_move_j()->set_settle_timeout_s(2.0);
|
||||
arm_ = std::make_unique<MotorRobotArm>(arm_config_);
|
||||
if (!arm_->init() || arm_->kinematicsSolver() ||
|
||||
arm_->getRobotState().fault) {
|
||||
throw std::runtime_error("Joint-only arm initialization failed");
|
||||
}
|
||||
|
||||
auto target = arm_->getJointState().position;
|
||||
for (auto& q : target) q += 0.02;
|
||||
MotionOptions options;
|
||||
options.velocity = 0.2;
|
||||
options.acceleration = 0.5;
|
||||
options.jerk = 5.0;
|
||||
const auto result = arm_->moveJ(JointPositionCommand{target}, options);
|
||||
if (!result.ok()) throw std::runtime_error(result.message);
|
||||
std::cout << "Joint-only MoveJ max position error: "
|
||||
<< maxPositionError(arm_->getJointState().position, target) << std::endl;
|
||||
|
||||
target[0] = arm_->getRobotModel().joint_limits[0].upper + 0.1;
|
||||
if (arm_->moveJ(JointPositionCommand{target}, options).ok()) {
|
||||
throw std::runtime_error("MoveJ accepted a target outside the motor limits");
|
||||
}
|
||||
if (arm_->moveL(CartesianPose{}, options).ok() ||
|
||||
arm_->speedL(CartesianVelocity{}, 0.5, 0.1).ok()) {
|
||||
throw std::runtime_error("Unconfigured Cartesian motion was accepted");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(MotorRobotArmMujocoTest, MoveL)
|
||||
{
|
||||
MotorRobotArm& arm = *arm_;
|
||||
|
||||
@ -21,6 +21,7 @@ namespace cmvr::device{
|
||||
|
||||
} MotorProfile;
|
||||
|
||||
public:
|
||||
struct MotorInfo {
|
||||
int id;
|
||||
std::string joint_name;
|
||||
@ -30,6 +31,7 @@ namespace cmvr::device{
|
||||
double limit_qdd;
|
||||
};
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
double position;
|
||||
double velocity;
|
||||
@ -98,13 +100,14 @@ namespace cmvr::device{
|
||||
// virtual void setLimitCurrent(double tau) = 0;
|
||||
virtual bool brakeRelease() = 0;
|
||||
|
||||
virtual bool quickStop() {
|
||||
// deceleration: positive output-axis rad/s^2.
|
||||
virtual bool quickStop(double deceleration = 5.0) {
|
||||
std::scoped_lock lock(mtx_);
|
||||
if (!protocol_) {
|
||||
CMVR_LOG(ERROR) << "Protocol not set for motor";
|
||||
return false;
|
||||
}
|
||||
return protocol_->quickStop(node_id_);
|
||||
return protocol_->quickStop(node_id_, deceleration);
|
||||
}
|
||||
virtual bool commandProfilePosition(double target_q,
|
||||
double max_qd = 0.0,
|
||||
@ -223,6 +226,11 @@ namespace cmvr::device{
|
||||
std::string jointName() const {
|
||||
return info_.joint_name;
|
||||
}
|
||||
// Cached metadata and configured limits; does not read the drive.
|
||||
MotorInfo motorInfo() const {
|
||||
std::scoped_lock lock(mtx_);
|
||||
return info_;
|
||||
}
|
||||
protected:
|
||||
mutable std::mutex mtx_;
|
||||
MotorInfo info_{};
|
||||
|
||||
@ -24,6 +24,8 @@ namespace cmvr::device {
|
||||
|
||||
class EthercatMotorBusRuntime final : public AbstractMotorBusRuntime {
|
||||
public:
|
||||
~EthercatMotorBusRuntime() override;
|
||||
|
||||
struct PdoWrite {
|
||||
int motor_id{0};
|
||||
std::uint16_t index{0};
|
||||
|
||||
@ -15,6 +15,11 @@
|
||||
|
||||
namespace cmvr::device {
|
||||
|
||||
EthercatMotorBusRuntime::~EthercatMotorBusRuntime()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
bool EthercatMotorBusRuntime::init(const config::MotorGroupConfig& group_cfg)
|
||||
{
|
||||
id_ = group_cfg.id();
|
||||
|
||||
@ -59,7 +59,6 @@ add_executable(tchl_motor_real_test
|
||||
target_link_libraries(tchl_motor_real_test
|
||||
PRIVATE
|
||||
cmvr_es::device::motor_manager
|
||||
absl::cleanup
|
||||
gtest
|
||||
gtest_main
|
||||
pthread
|
||||
|
||||
@ -53,6 +53,7 @@ public:
|
||||
msgs::RunMode getMode(std::uint8_t node_id) override;
|
||||
void setLimitQdd(std::uint8_t node_id, double u_qdd, double l_qdd) override;
|
||||
bool reachedTargetQ(std::uint8_t node_id) override;
|
||||
// Uses abs(max_qd) in rad/s; zero or non-finite speeds send no command.
|
||||
bool commandProfilePosition(std::uint8_t node_id,
|
||||
double target_q,
|
||||
double max_qd,
|
||||
@ -79,7 +80,8 @@ public:
|
||||
double gear_ratio) override;
|
||||
bool torqueOn(std::uint8_t node_id) override;
|
||||
bool torqueOff(std::uint8_t node_id) override;
|
||||
bool quickStop(std::uint8_t node_id) override;
|
||||
// Position/velocity modes use 6085, then disable the drive (605A = 2).
|
||||
bool quickStop(std::uint8_t node_id, double deceleration = 5.0) override;
|
||||
|
||||
double getQ(std::uint8_t node_id) override;
|
||||
double getQd(std::uint8_t node_id) override;
|
||||
|
||||
@ -54,6 +54,11 @@ bool Cia402Protocol::commandProfilePosition(const std::uint8_t node_id,
|
||||
const double max_qd,
|
||||
const double max_qdd)
|
||||
{
|
||||
if (!std::isfinite(max_qd) || max_qd == 0.0) {
|
||||
CMVR_LOG(ERROR) << "[Cia402Protocol] profile velocity must be finite and nonzero, node="
|
||||
<< static_cast<int>(node_id) << ", max_qd=" << max_qd;
|
||||
return false;
|
||||
}
|
||||
auto& state = nodeState_(node_id);
|
||||
if (!hasValidConversion_(node_id, state) ||
|
||||
!status_monitor_->isNodeOperational(node_id, 1)) {
|
||||
@ -61,18 +66,7 @@ bool Cia402Protocol::commandProfilePosition(const std::uint8_t node_id,
|
||||
}
|
||||
state.mode = msgs::RUN_MODE_PROFILE_POSITION;
|
||||
state.target_position = radToCounts_(target_q, state);
|
||||
if (max_qd > 0.0) {
|
||||
state.profile_velocity = std::abs(radPerSecToCounts_(max_qd, state));
|
||||
} else {
|
||||
std::uint32_t profile_velocity = 0;
|
||||
if (!bus_runtime_->readSdo<std::uint32_t>(
|
||||
node_id, msgs::CIA402_PROFILE_VELOCITY_6081, 0x00, profile_velocity) ||
|
||||
profile_velocity > static_cast<std::uint32_t>(
|
||||
std::numeric_limits<std::int32_t>::max())) {
|
||||
return false;
|
||||
}
|
||||
state.profile_velocity = static_cast<std::int32_t>(profile_velocity);
|
||||
}
|
||||
state.profile_velocity = radPerSecToCounts_(std::abs(max_qd), state);
|
||||
if (max_qdd > 0.0) {
|
||||
const auto profile_acceleration = std::abs(radPerSec2ToCounts_(max_qdd, state));
|
||||
state.profile_acceleration = profile_acceleration;
|
||||
@ -510,27 +504,41 @@ bool Cia402Protocol::torqueOff(const std::uint8_t node_id)
|
||||
"Switch On Disabled");
|
||||
}
|
||||
|
||||
bool Cia402Protocol::quickStop(const std::uint8_t node_id)
|
||||
bool Cia402Protocol::quickStop(const std::uint8_t node_id, const double deceleration)
|
||||
{
|
||||
if (!bus_runtime_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& state = nodeState_(node_id);
|
||||
if (!refreshMode_(node_id, state)) {
|
||||
if (!std::isfinite(deceleration) || deceleration <= 0.0 ||
|
||||
!hasValidConversion_(node_id, state)) {
|
||||
return false;
|
||||
}
|
||||
state.target_velocity = 0;
|
||||
state.target_torque = 0;
|
||||
if (!writeTargetsForMode_(node_id, state.mode, state)) {
|
||||
const double deceleration_counts = std::round(
|
||||
deceleration / (2.0 * M_PI) * state.gear_ratio * state.encoder_counts_per_rev);
|
||||
if (!std::isfinite(deceleration_counts) || deceleration_counts < 1.0 ||
|
||||
deceleration_counts > std::numeric_limits<std::uint32_t>::max()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool parameters_written =
|
||||
bus_runtime_->writeSdo<std::uint32_t>(
|
||||
node_id, msgs::CIA402_QUICK_STOP_DECELERATION_6085, 0x00,
|
||||
static_cast<std::uint32_t>(deceleration_counts)) &&
|
||||
bus_runtime_->writeSdo<std::int16_t>(
|
||||
node_id, msgs::CIA402_QUICK_STOP_OPTION_605A, 0x00, 2);
|
||||
if (!parameters_written) {
|
||||
CMVR_LOG(ERROR) << "[Cia402Protocol] failed to configure quick stop, node="
|
||||
<< static_cast<int>(node_id);
|
||||
}
|
||||
// Let the drive apply its configured stop ramp; do not step cyclic targets to zero.
|
||||
// Still request a stop if SDO configuration failed, and report the failure.
|
||||
state.controlword = cia402::quickStopControlword();
|
||||
if (!writeControlword_(node_id, state.controlword)) {
|
||||
return false;
|
||||
}
|
||||
return waitVelocityNearZero_(node_id, "quickStop");
|
||||
const bool stopped = waitVelocityNearZero_(node_id, "quickStop");
|
||||
return parameters_written && stopped;
|
||||
}
|
||||
|
||||
double Cia402Protocol::getQ(const std::uint8_t node_id)
|
||||
|
||||
@ -343,7 +343,23 @@ bool TchlMotorAdapter::torqueOff(
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(disable_delay_);
|
||||
return targets_written && stopped && disabled;
|
||||
// A forced release without an intervening enable remains latched after disabling.
|
||||
std::uint16_t brake_command = 0;
|
||||
const bool brake_reset = disabled &&
|
||||
bus_runtime_->readSdo<std::uint16_t>(
|
||||
node_id, kForceBrakeRelease, 0x00, brake_command) &&
|
||||
(brake_command == 0 ||
|
||||
(bus_runtime_->writeSdo<std::uint16_t>(
|
||||
node_id, kForceBrakeRelease, 0x00, 0) &&
|
||||
bus_runtime_->readSdo<std::uint16_t>(
|
||||
node_id, kForceBrakeRelease, 0x00, brake_command) &&
|
||||
brake_command == 0));
|
||||
if (disabled && !brake_reset) {
|
||||
CMVR_LOG(ERROR) << "[TchlMotorAdapter] failed to clear forced brake release, node="
|
||||
<< static_cast<int>(node_id)
|
||||
<< ", command_readback=" << brake_command;
|
||||
}
|
||||
return targets_written && stopped && disabled && brake_reset;
|
||||
}
|
||||
|
||||
bool TchlMotorAdapter::calibrateZero(
|
||||
@ -475,9 +491,9 @@ bool TchlMotorAdapter::brakeRelease(const std::uint8_t node_id)
|
||||
std::uint16_t statusword = 0;
|
||||
if (!bus_runtime_->readSdo<std::uint16_t>(
|
||||
node_id, msgs::CIA402_STATUS_WORD_6041, 0x00, statusword) ||
|
||||
cia402::isOperationEnabled(cia402::statusword(statusword))) {
|
||||
cia402::statusword(statusword).operation_enabled != 0) {
|
||||
CMVR_LOG(ERROR) << "[TchlMotorAdapter] brake release requires a readable "
|
||||
<< "statusword and a drive that is not operation enabled, node="
|
||||
<< "statusword with operation-enabled bit cleared, node="
|
||||
<< static_cast<int>(node_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include <absl/cleanup/cleanup.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "common/config/config_files.h"
|
||||
@ -17,353 +15,202 @@
|
||||
namespace cmvr::device {
|
||||
namespace {
|
||||
|
||||
constexpr double kTargetPositionRad = 1.57; // Absolute output-axis position.
|
||||
constexpr double kTargetPositionRad = 1.57;
|
||||
constexpr double kVelocityRadS = 0.5;
|
||||
constexpr double kAccelerationRadS2 = 5.0;
|
||||
constexpr double kCspExcursionRad = 1.57; // Motion range: q0 to q0 + excursion.
|
||||
constexpr double kCspExcursionRad = 3.0;
|
||||
constexpr double kCspPeriodS = 6.0;
|
||||
constexpr int kCspCycles = 2;
|
||||
constexpr double kPvVelocityRadS = -0.3;
|
||||
constexpr double kPvAccelerationRadS2 = 1.0;
|
||||
constexpr std::chrono::seconds kPvDuration{2};
|
||||
constexpr double kCsvVelocityAmplitudeRadS = 0.8;
|
||||
constexpr double kCsvPeriodS = 6.0;
|
||||
constexpr double kCsvVelocityAmplitudeRadS = 1.3;
|
||||
constexpr double kCsvPeriodS = 12.0;
|
||||
constexpr int kCsvCycles = 2;
|
||||
constexpr double kQuickStopVelocityRadS = 0.3;
|
||||
constexpr double kQuickStopAccelerationRadS2 = 1.0;
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
volatile std::sig_atomic_t stop_requested = 0;
|
||||
constexpr std::chrono::milliseconds kCommandPeriod{1};
|
||||
constexpr std::chrono::milliseconds kPrintPeriod{100};
|
||||
|
||||
void requestStop(int)
|
||||
{
|
||||
stop_requested = 1;
|
||||
}
|
||||
|
||||
// Running this test enables and moves the real motor.
|
||||
TEST(TchlMotorRealTest, ProfilePosition)
|
||||
std::shared_ptr<AbstractMotor> initMotor(std::shared_ptr<MotorManager>& manager)
|
||||
{
|
||||
const char* config_path = std::getenv("TCHL_MOTOR_CONFIG");
|
||||
config::MotorRootConfig root;
|
||||
ASSERT_TRUE(ConfigHelper::loadConfigFile(
|
||||
config_path ? config_path : "cmvr-es/config/devices/motor/tchl_motors.pb.txt", root));
|
||||
ASSERT_EQ(root.motor().motor_groups_size(), 1);
|
||||
if (!ConfigHelper::loadConfigFile(
|
||||
config_path ? config_path : "cmvr-es/config/devices/motor/tchl_motors.pb.txt", root) ||
|
||||
root.motor().motor_groups_size() != 1 ||
|
||||
root.motor().motor_groups(0).motors().motors_size() != 1) {
|
||||
throw std::runtime_error("Cannot load the single-axis motor configuration");
|
||||
}
|
||||
const auto& group = root.motor().motor_groups(0);
|
||||
ASSERT_EQ(group.motors().motors_size(), 1);
|
||||
auto manager = std::make_shared<MotorManager>(root.motor().id(), root.motor(), group.id());
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
bool enable_attempted = false;
|
||||
manager = std::make_shared<MotorManager>(root.motor().id(), root.motor(), group.id());
|
||||
if (!manager->init()) {
|
||||
throw std::runtime_error("Motor initialization failed");
|
||||
}
|
||||
auto motor = manager->getMotor(group.motors().motors(0).joint_name());
|
||||
if (!motor) {
|
||||
throw std::runtime_error("Configured motor was not found");
|
||||
}
|
||||
return motor;
|
||||
}
|
||||
|
||||
stop_requested = 0;
|
||||
const auto previous_sigint = std::signal(SIGINT, requestStop);
|
||||
const auto previous_sigterm = std::signal(SIGTERM, requestStop);
|
||||
// Also runs when an ASSERT returns early.
|
||||
absl::Cleanup cleanup = [&] {
|
||||
if (enable_attempted) {
|
||||
EXPECT_TRUE(motor->quickStop());
|
||||
EXPECT_TRUE(motor->torqueOff());
|
||||
}
|
||||
manager->stop();
|
||||
std::signal(SIGINT, previous_sigint);
|
||||
std::signal(SIGTERM, previous_sigterm);
|
||||
};
|
||||
void printFeedback(const std::shared_ptr<AbstractMotor>& motor)
|
||||
{
|
||||
std::cout << "q=" << motor->getQ() << " rad"
|
||||
<< ", qd=" << motor->getQd() << " rad/s"
|
||||
<< ", torque=" << motor->getTau() << " per mille" << std::endl;
|
||||
}
|
||||
|
||||
ASSERT_TRUE(manager->init());
|
||||
motor = manager->getMotor(group.motors().motors(0).joint_name());
|
||||
ASSERT_NE(motor, nullptr);
|
||||
ASSERT_FALSE(stop_requested);
|
||||
enable_attempted = true;
|
||||
ASSERT_TRUE(motor->setMode(msgs::RUN_MODE_PROFILE_POSITION));
|
||||
ASSERT_TRUE(motor->torqueOn());
|
||||
ASSERT_FALSE(stop_requested);
|
||||
ASSERT_TRUE(motor->commandProfilePosition(
|
||||
kTargetPositionRad, kVelocityRadS, kAccelerationRadS2));
|
||||
|
||||
const std::vector<std::shared_ptr<AbstractMotor>> motors{motor};
|
||||
std::vector<double> positions, velocities, torques;
|
||||
const auto end = std::chrono::steady_clock::now() + std::chrono::seconds{10};
|
||||
while (!stop_requested && std::chrono::steady_clock::now() < end) {
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
std::cout << "target=" << kTargetPositionRad
|
||||
<< ", q=" << positions[0] << " rad"
|
||||
<< ", qd=" << velocities[0] << " rad/s"
|
||||
<< ", torque=" << torques[0] << " per mille" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
||||
void printFeedbackFor(const std::shared_ptr<AbstractMotor>& motor,
|
||||
std::chrono::seconds duration)
|
||||
{
|
||||
const auto end = std::chrono::steady_clock::now() + duration;
|
||||
while (std::chrono::steady_clock::now() < end) {
|
||||
printFeedback(motor);
|
||||
std::this_thread::sleep_for(kPrintPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
// Running this test enables and moves the real motor.
|
||||
TEST(TchlMotorRealTest, ProfilePosition)
|
||||
{
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
motor->calibrateZeroQ();
|
||||
if (!motor->setMode(msgs::RUN_MODE_PROFILE_POSITION) || !motor->torqueOn() ||
|
||||
!motor->commandProfilePosition(-6, -1, kAccelerationRadS2)) {
|
||||
throw std::runtime_error("Profile position command failed");
|
||||
}
|
||||
std::cout << "target=" << kTargetPositionRad << " rad" << std::endl;
|
||||
printFeedbackFor(motor, std::chrono::seconds{4});
|
||||
// motor->quickStop();
|
||||
printFeedbackFor(motor, std::chrono::seconds{1000});
|
||||
}
|
||||
|
||||
TEST(TchlMotorRealTest, CyclicPositionSin)
|
||||
{
|
||||
const char* config_path = std::getenv("TCHL_MOTOR_CONFIG");
|
||||
config::MotorRootConfig root;
|
||||
ASSERT_TRUE(ConfigHelper::loadConfigFile(
|
||||
config_path ? config_path : "cmvr-es/config/devices/motor/tchl_motors.pb.txt", root));
|
||||
ASSERT_EQ(root.motor().motor_groups_size(), 1);
|
||||
const auto& group = root.motor().motor_groups(0);
|
||||
ASSERT_EQ(group.motors().motors_size(), 1);
|
||||
ASSERT_TRUE(group.joint_limits().enable());
|
||||
ASSERT_EQ(group.joint_limits().joints_size(), 1);
|
||||
const auto command_period = std::chrono::microseconds{group.ethercat().cycle_us()};
|
||||
ASSERT_GT(command_period.count(), 0);
|
||||
auto manager = std::make_shared<MotorManager>(root.motor().id(), root.motor(), group.id());
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
bool enable_attempted = false;
|
||||
|
||||
stop_requested = 0;
|
||||
const auto previous_sigint = std::signal(SIGINT, requestStop);
|
||||
const auto previous_sigterm = std::signal(SIGTERM, requestStop);
|
||||
absl::Cleanup cleanup = [&] {
|
||||
if (enable_attempted) {
|
||||
EXPECT_TRUE(motor->quickStop());
|
||||
EXPECT_TRUE(motor->torqueOff());
|
||||
}
|
||||
manager->stop();
|
||||
std::signal(SIGINT, previous_sigint);
|
||||
std::signal(SIGTERM, previous_sigterm);
|
||||
};
|
||||
|
||||
ASSERT_TRUE(manager->init());
|
||||
motor = manager->getMotor(group.motors().motors(0).joint_name());
|
||||
ASSERT_NE(motor, nullptr);
|
||||
ASSERT_FALSE(stop_requested);
|
||||
enable_attempted = true;
|
||||
ASSERT_TRUE(motor->setMode(msgs::RUN_MODE_CYCLIC_SYNC_POSITION));
|
||||
ASSERT_TRUE(motor->torqueOn());
|
||||
|
||||
const std::vector<std::shared_ptr<AbstractMotor>> motors{motor};
|
||||
std::vector<double> positions, velocities, torques;
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
const double start_q = positions[0];
|
||||
const auto& limit = group.joint_limits().joints(0);
|
||||
ASSERT_GE(std::min(start_q, start_q + kCspExcursionRad), limit.q_lb());
|
||||
ASSERT_LE(std::max(start_q, start_q + kCspExcursionRad), limit.q_ub());
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
motor->calibrateZeroQ();
|
||||
if (!motor->setMode(msgs::RUN_MODE_CYCLIC_SYNC_POSITION) || !motor->torqueOn()) {
|
||||
throw std::runtime_error("CSP enable failed");
|
||||
}
|
||||
const double start_q = motor->getQ();
|
||||
const double omega = 2.0 * kPi / kCspPeriodS;
|
||||
const double duration_s = kCspPeriodS * kCspCycles;
|
||||
|
||||
const auto start_time = std::chrono::steady_clock::now();
|
||||
auto next_print = start_time;
|
||||
while (!stop_requested) {
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
auto next_print = start;
|
||||
while (true) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const double t = std::min(duration_s,
|
||||
std::chrono::duration<double>(now - start_time).count());
|
||||
const double t = std::min(duration_s, std::chrono::duration<double>(now - start).count());
|
||||
const bool finished = t >= duration_s;
|
||||
// Same raised-cosine position and sine velocity as the Eyou CSP test.
|
||||
const double target_q = finished ? start_q :
|
||||
start_q + 0.5 * kCspExcursionRad * (1.0 - std::cos(omega * t));
|
||||
const double target_qd = finished ? 0.0 :
|
||||
0.5 * kCspExcursionRad * omega * std::sin(omega * t);
|
||||
ASSERT_TRUE(motor->commandCyclicPosition(target_q, target_qd));
|
||||
|
||||
if (!motor->commandCyclicPosition(target_q, target_qd)) {
|
||||
throw std::runtime_error("Cyclic position command failed");
|
||||
}
|
||||
if (now >= next_print || finished) {
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
std::cout << "t=" << t << " s, target_q=" << target_q << " rad"
|
||||
<< ", target_qd=" << target_qd << " rad/s"
|
||||
<< ", q=" << positions[0] << " rad"
|
||||
<< ", qd=" << velocities[0] << " rad/s"
|
||||
<< ", torque=" << torques[0] << " per mille" << std::endl;
|
||||
next_print = now + std::chrono::milliseconds{100};
|
||||
std::cout << "t=" << t << " s, target_q=" << target_q
|
||||
<< " rad, target_qd=" << target_qd << " rad/s, ";
|
||||
printFeedback(motor);
|
||||
next_print = now + kPrintPeriod;
|
||||
}
|
||||
if (finished) {
|
||||
break;
|
||||
}
|
||||
// Skip elapsed ticks instead of sending a burst after a delayed wakeup.
|
||||
const auto next_tick =
|
||||
(std::chrono::steady_clock::now() - start_time) / command_period + 1;
|
||||
std::this_thread::sleep_until(start_time + next_tick * command_period);
|
||||
const auto next_tick = (std::chrono::steady_clock::now() - start) / kCommandPeriod + 1;
|
||||
std::this_thread::sleep_until(start + next_tick * kCommandPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
// Running this test enables and moves the real motor.
|
||||
TEST(TchlMotorRealTest, ProfileVelocity)
|
||||
{
|
||||
const char* config_path = std::getenv("TCHL_MOTOR_CONFIG");
|
||||
config::MotorRootConfig root;
|
||||
ASSERT_TRUE(ConfigHelper::loadConfigFile(
|
||||
config_path ? config_path : "cmvr-es/config/devices/motor/tchl_motors.pb.txt", root));
|
||||
ASSERT_EQ(root.motor().motor_groups_size(), 1);
|
||||
const auto& group = root.motor().motor_groups(0);
|
||||
ASSERT_EQ(group.motors().motors_size(), 1);
|
||||
ASSERT_TRUE(group.joint_limits().enable());
|
||||
ASSERT_EQ(group.joint_limits().joints_size(), 1);
|
||||
auto manager = std::make_shared<MotorManager>(root.motor().id(), root.motor(), group.id());
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
bool enable_attempted = false;
|
||||
|
||||
stop_requested = 0;
|
||||
const auto previous_sigint = std::signal(SIGINT, requestStop);
|
||||
const auto previous_sigterm = std::signal(SIGTERM, requestStop);
|
||||
absl::Cleanup cleanup = [&] {
|
||||
if (enable_attempted) {
|
||||
EXPECT_TRUE(motor->quickStop());
|
||||
EXPECT_TRUE(motor->torqueOff());
|
||||
}
|
||||
manager->stop();
|
||||
std::signal(SIGINT, previous_sigint);
|
||||
std::signal(SIGTERM, previous_sigterm);
|
||||
};
|
||||
|
||||
ASSERT_TRUE(manager->init());
|
||||
motor = manager->getMotor(group.motors().motors(0).joint_name());
|
||||
ASSERT_NE(motor, nullptr);
|
||||
ASSERT_FALSE(stop_requested);
|
||||
enable_attempted = true;
|
||||
ASSERT_TRUE(motor->setMode(msgs::RUN_MODE_PROFILE_VELOCITY));
|
||||
ASSERT_TRUE(motor->torqueOn());
|
||||
|
||||
const std::vector<std::shared_ptr<AbstractMotor>> motors{motor};
|
||||
std::vector<double> positions, velocities, torques;
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
const auto& limit = group.joint_limits().joints(0);
|
||||
ASSERT_LE(std::abs(kPvVelocityRadS), limit.qd());
|
||||
// Allow travel at target speed for the whole run plus the stopping distance.
|
||||
const double stop_distance = kPvVelocityRadS * kPvVelocityRadS / (2.0 * kPvAccelerationRadS2);
|
||||
const double end_q = positions[0] + kPvVelocityRadS * kPvDuration.count() +
|
||||
std::copysign(stop_distance, kPvVelocityRadS);
|
||||
ASSERT_GE(std::min(positions[0], end_q), limit.q_lb());
|
||||
ASSERT_LE(std::max(positions[0], end_q), limit.q_ub());
|
||||
|
||||
for (const double target_qd : {kPvVelocityRadS, 0.0}) {
|
||||
if (stop_requested) {
|
||||
break;
|
||||
}
|
||||
ASSERT_TRUE(motor->commandProfileVelocity(target_qd, kPvAccelerationRadS2));
|
||||
const auto duration = target_qd == 0.0 ? std::chrono::seconds{1} : kPvDuration;
|
||||
const auto end = std::chrono::steady_clock::now() + duration;
|
||||
while (!stop_requested && std::chrono::steady_clock::now() < end) {
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
ASSERT_GE(positions[0], limit.q_lb());
|
||||
ASSERT_LE(positions[0], limit.q_ub());
|
||||
std::cout << "target_qd=" << target_qd << " rad/s"
|
||||
<< ", q=" << positions[0] << " rad"
|
||||
<< ", qd=" << velocities[0] << " rad/s"
|
||||
<< ", torque=" << torques[0] << " per mille" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
||||
}
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
motor->calibrateZeroQ();
|
||||
if (!motor->setMode(msgs::RUN_MODE_PROFILE_VELOCITY) || !motor->torqueOn()) {
|
||||
throw std::runtime_error("PV enable failed");
|
||||
}
|
||||
if (!motor->commandProfileVelocity(-1.0, kPvAccelerationRadS2)) {
|
||||
throw std::runtime_error("Profile velocity command failed");
|
||||
}
|
||||
std::cout << "target_qd=" << kPvVelocityRadS << " rad/s" << std::endl;
|
||||
while (true) {
|
||||
printFeedback(motor);
|
||||
std::this_thread::sleep_for(kPrintPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
// Running this test enables and moves the real motor.
|
||||
TEST(TchlMotorRealTest, CyclicVelocitySin)
|
||||
{
|
||||
const char* config_path = std::getenv("TCHL_MOTOR_CONFIG");
|
||||
config::MotorRootConfig root;
|
||||
ASSERT_TRUE(ConfigHelper::loadConfigFile(
|
||||
config_path ? config_path : "cmvr-es/config/devices/motor/tchl_motors.pb.txt", root));
|
||||
ASSERT_EQ(root.motor().motor_groups_size(), 1);
|
||||
const auto& group = root.motor().motor_groups(0);
|
||||
ASSERT_EQ(group.motors().motors_size(), 1);
|
||||
ASSERT_TRUE(group.joint_limits().enable());
|
||||
ASSERT_EQ(group.joint_limits().joints_size(), 1);
|
||||
const auto command_period = std::chrono::microseconds{group.ethercat().cycle_us()};
|
||||
ASSERT_GT(command_period.count(), 0);
|
||||
auto manager = std::make_shared<MotorManager>(root.motor().id(), root.motor(), group.id());
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
bool enable_attempted = false;
|
||||
|
||||
stop_requested = 0;
|
||||
const auto previous_sigint = std::signal(SIGINT, requestStop);
|
||||
const auto previous_sigterm = std::signal(SIGTERM, requestStop);
|
||||
absl::Cleanup cleanup = [&] {
|
||||
if (enable_attempted) {
|
||||
EXPECT_TRUE(motor->quickStop());
|
||||
EXPECT_TRUE(motor->torqueOff());
|
||||
}
|
||||
manager->stop();
|
||||
std::signal(SIGINT, previous_sigint);
|
||||
std::signal(SIGTERM, previous_sigterm);
|
||||
};
|
||||
|
||||
ASSERT_TRUE(manager->init());
|
||||
motor = manager->getMotor(group.motors().motors(0).joint_name());
|
||||
ASSERT_NE(motor, nullptr);
|
||||
ASSERT_FALSE(stop_requested);
|
||||
enable_attempted = true;
|
||||
ASSERT_TRUE(motor->setMode(msgs::RUN_MODE_CYCLIC_SYNC_VELOCITY));
|
||||
ASSERT_TRUE(motor->torqueOn());
|
||||
|
||||
const std::vector<std::shared_ptr<AbstractMotor>> motors{motor};
|
||||
std::vector<double> positions, velocities, torques;
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
const auto& limit = group.joint_limits().joints(0);
|
||||
ASSERT_LE(std::abs(kCsvVelocityAmplitudeRadS), limit.qd());
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
if (!motor->setMode(msgs::RUN_MODE_CYCLIC_SYNC_VELOCITY) || !motor->torqueOn()) {
|
||||
throw std::runtime_error("CSV enable failed");
|
||||
}
|
||||
const double omega = 2.0 * kPi / kCsvPeriodS;
|
||||
const double end_q = positions[0] + 2.0 * kCsvVelocityAmplitudeRadS / omega;
|
||||
ASSERT_GE(std::min(positions[0], end_q), limit.q_lb());
|
||||
ASSERT_LE(std::max(positions[0], end_q), limit.q_ub());
|
||||
const double duration_s = kCsvPeriodS * kCsvCycles;
|
||||
|
||||
const auto start_time = std::chrono::steady_clock::now();
|
||||
auto next_print = start_time;
|
||||
while (!stop_requested) {
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
auto next_print = start;
|
||||
while (true) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const double t = std::min(duration_s,
|
||||
std::chrono::duration<double>(now - start_time).count());
|
||||
const double t = std::min(duration_s, std::chrono::duration<double>(now - start).count());
|
||||
const bool finished = t >= duration_s;
|
||||
const double target_qd = finished ? 0.0 :
|
||||
kCsvVelocityAmplitudeRadS * std::sin(omega * t);
|
||||
ASSERT_TRUE(motor->commandCyclicVelocity(target_qd));
|
||||
|
||||
const double target_qd = finished ? 0.0 : kCsvVelocityAmplitudeRadS * std::sin(omega * t);
|
||||
if (!motor->commandCyclicVelocity(target_qd)) {
|
||||
throw std::runtime_error("Cyclic velocity command failed");
|
||||
}
|
||||
if (now >= next_print || finished) {
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
ASSERT_GE(positions[0], limit.q_lb());
|
||||
ASSERT_LE(positions[0], limit.q_ub());
|
||||
std::cout << "t=" << t << " s, target_qd=" << target_qd << " rad/s"
|
||||
<< ", q=" << positions[0] << " rad"
|
||||
<< ", qd=" << velocities[0] << " rad/s"
|
||||
<< ", torque=" << torques[0] << " per mille" << std::endl;
|
||||
next_print = now + std::chrono::milliseconds{100};
|
||||
std::cout << "t=" << t << " s, target_qd=" << target_qd << " rad/s, ";
|
||||
printFeedback(motor);
|
||||
next_print = now + kPrintPeriod;
|
||||
}
|
||||
if (finished) {
|
||||
break;
|
||||
}
|
||||
const auto next_tick =
|
||||
(std::chrono::steady_clock::now() - start_time) / command_period + 1;
|
||||
std::this_thread::sleep_until(start_time + next_tick * command_period);
|
||||
const auto next_tick = (std::chrono::steady_clock::now() - start) / kCommandPeriod + 1;
|
||||
std::this_thread::sleep_until(start + next_tick * kCommandPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
// Changes the current zero point; calibration temporarily enables then disables the motor.
|
||||
TEST(TchlMotorRealTest, QuickStopInProfileVelocity)
|
||||
{
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
const double target_qd = motor->getQ() > 0.0 ? -kQuickStopVelocityRadS : kQuickStopVelocityRadS;
|
||||
if (!motor->setMode(msgs::RUN_MODE_PROFILE_VELOCITY) || !motor->torqueOn() ||
|
||||
!motor->commandProfileVelocity(target_qd, kQuickStopAccelerationRadS2)) {
|
||||
throw std::runtime_error("Profile velocity command failed");
|
||||
}
|
||||
printFeedbackFor(motor, std::chrono::seconds{2});
|
||||
if (!motor->quickStop()) { // Default deceleration: 5.0 rad/s^2.
|
||||
throw std::runtime_error("Quick stop failed");
|
||||
}
|
||||
printFeedbackFor(motor, std::chrono::seconds{1});
|
||||
}
|
||||
|
||||
TEST(TchlMotorRealTest, BrakeRelease)
|
||||
{
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
if (!motor->torqueOff() || !motor->brakeRelease()) {
|
||||
throw std::runtime_error("Brake release failed");
|
||||
}
|
||||
printFeedbackFor(motor, std::chrono::seconds{10});
|
||||
}
|
||||
|
||||
TEST(TchlMotorRealTest, CalibrateZeroQ)
|
||||
{
|
||||
const char* config_path = std::getenv("TCHL_MOTOR_CONFIG");
|
||||
config::MotorRootConfig root;
|
||||
ASSERT_TRUE(ConfigHelper::loadConfigFile(
|
||||
config_path ? config_path : "cmvr-es/config/devices/motor/tchl_motors.pb.txt", root));
|
||||
ASSERT_EQ(root.motor().motor_groups_size(), 1);
|
||||
const auto& group = root.motor().motor_groups(0);
|
||||
ASSERT_EQ(group.motors().motors_size(), 1);
|
||||
auto manager = std::make_shared<MotorManager>(root.motor().id(), root.motor(), group.id());
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
|
||||
stop_requested = 0;
|
||||
const auto previous_sigint = std::signal(SIGINT, requestStop);
|
||||
const auto previous_sigterm = std::signal(SIGTERM, requestStop);
|
||||
absl::Cleanup cleanup = [&] {
|
||||
if (motor) {
|
||||
EXPECT_TRUE(motor->torqueOff());
|
||||
}
|
||||
manager->stop();
|
||||
std::signal(SIGINT, previous_sigint);
|
||||
std::signal(SIGTERM, previous_sigterm);
|
||||
};
|
||||
|
||||
ASSERT_TRUE(manager->init());
|
||||
motor = manager->getMotor(group.motors().motors(0).joint_name());
|
||||
ASSERT_NE(motor, nullptr);
|
||||
const std::vector<std::shared_ptr<AbstractMotor>> motors{motor};
|
||||
std::vector<double> positions, velocities, torques;
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
std::cout << "before calibration: q=" << positions[0] << " rad"
|
||||
<< ", qd=" << velocities[0] << " rad/s"
|
||||
<< ", torque=" << torques[0] << " per mille"
|
||||
<< ", mode=" << msgs::RunMode_Name(motor->getMode()) << std::endl;
|
||||
|
||||
ASSERT_FALSE(stop_requested);
|
||||
ASSERT_TRUE(motor->calibrateZeroQ());
|
||||
|
||||
ASSERT_TRUE(manager->readFeedbacksAtomic(motors, positions, velocities, torques));
|
||||
std::cout << "after calibration: q=" << positions[0] << " rad"
|
||||
<< ", qd=" << velocities[0] << " rad/s"
|
||||
<< ", torque=" << torques[0] << " per mille"
|
||||
<< ", mode=" << msgs::RunMode_Name(motor->getMode()) << std::endl;
|
||||
std::shared_ptr<MotorManager> manager;
|
||||
auto motor = initMotor(manager);
|
||||
std::cout << "before calibration: ";
|
||||
printFeedback(motor);
|
||||
if (!motor->calibrateZeroQ()) {
|
||||
throw std::runtime_error("Zero calibration failed");
|
||||
}
|
||||
std::cout << "after calibration: ";
|
||||
printFeedback(motor);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -26,7 +26,8 @@ public:
|
||||
bool torqueOn() override;
|
||||
bool torqueOff() override;
|
||||
bool brakeRelease() override;
|
||||
bool quickStop() override;
|
||||
// Holds the current position; this backend does not simulate a deceleration ramp.
|
||||
bool quickStop(double deceleration = 5.0) override;
|
||||
|
||||
bool setLimitQ(double ub, double lb) override;
|
||||
bool setLimitQd(double qd) override;
|
||||
|
||||
@ -74,8 +74,11 @@ bool MujocoMotor::brakeRelease()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MujocoMotor::quickStop()
|
||||
bool MujocoMotor::quickStop(const double deceleration)
|
||||
{
|
||||
if (!std::isfinite(deceleration) || deceleration <= 0.0) {
|
||||
return false;
|
||||
}
|
||||
return holdPosition_();
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ namespace cmvr {
|
||||
bool torqueOn(uint8_t node_id) override;
|
||||
bool torqueOff(uint8_t node_id) override;
|
||||
bool brakeRelease(uint8_t node_id);
|
||||
bool quickStop(uint8_t node_id) override;
|
||||
bool quickStop(uint8_t node_id, double deceleration = 5.0) override;
|
||||
bool reachedTargetQ(uint8_t node_id) override;
|
||||
|
||||
double getQ(uint8_t node_id) override;
|
||||
|
||||
@ -669,11 +669,22 @@ bool Ti5MotorCanopenProtocol::brakeRelease(uint8_t node_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ti5MotorCanopenProtocol::quickStop(uint8_t node_id) {
|
||||
bool Ti5MotorCanopenProtocol::quickStop(uint8_t node_id, const double deceleration) {
|
||||
const auto* conversion = conversionForNode(node_id);
|
||||
if (!conversion || !std::isfinite(deceleration) || deceleration <= 0.0) {
|
||||
return false;
|
||||
}
|
||||
const double raw = radPerSecToVelocityRaw(deceleration, *conversion) /
|
||||
Ti5AccelerationTimeScale;
|
||||
if (!std::isfinite(raw) || raw < 1.0 ||
|
||||
raw > std::numeric_limits<uint32_t>::max()) {
|
||||
return false;
|
||||
}
|
||||
const auto deceleration_raw = radPerSec2ToAccelerationRaw(deceleration, *conversion);
|
||||
// // 开机未使能电机时调用
|
||||
// seedSdoRequest(node_id, CS_WRITE_TWO_BYTES, CIA402_CONTROL_WORD_6040, SUB_INDEX_0, 0x0F);
|
||||
// 6 抱闸 0 : 立即停机 自由
|
||||
seedSdoRequest(node_id, CS_WRITE_FOUR_BYTES, CIA402_QUICK_STOP_DECELERATION_6085, SUB_INDEX_0, 0XFFFFFFF0);
|
||||
seedSdoRequest(node_id, CS_WRITE_FOUR_BYTES, CIA402_QUICK_STOP_DECELERATION_6085, SUB_INDEX_0, deceleration_raw);
|
||||
seedSdoRequest(node_id, CS_WRITE_TWO_BYTES, CIA402_QUICK_STOP_OPTION_605A, SUB_INDEX_0, 6);
|
||||
seedSdoRequest(node_id, CS_WRITE_TWO_BYTES, CIA402_CONTROL_WORD_6040, SUB_INDEX_0, 0x02, 100);
|
||||
|
||||
|
||||
@ -69,7 +69,8 @@ namespace cmvr {
|
||||
double gear_ratio) = 0;
|
||||
virtual bool torqueOn(uint8_t node_id) = 0;
|
||||
virtual bool torqueOff(uint8_t node_id) = 0;
|
||||
virtual bool quickStop(uint8_t node_id) = 0;
|
||||
// deceleration: positive output-axis rad/s^2.
|
||||
virtual bool quickStop(uint8_t node_id, double deceleration = 5.0) = 0;
|
||||
|
||||
virtual double getQ(uint8_t node_id) = 0;
|
||||
virtual double getQd(uint8_t node_id) = 0;
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
MASTER0_DEVICE=""
|
||||
MASTER0_DEVICE="a0:ad:9f:c4:c2:2c"
|
||||
DEVICE_MODULES="generic"
|
||||
UPDOWN_INTERFACES=""
|
||||
UPDOWN_INTERFACES="eno1"
|
||||
|
||||
@ -173,6 +173,39 @@ motor {
|
||||
}
|
||||
```
|
||||
|
||||
### 七轴同川纯 MoveJ
|
||||
|
||||
使用以下配套配置:
|
||||
|
||||
- 电机:`cmvr-es/config/devices/motor/tchl_multi_motors.pb.txt`。
|
||||
- 机械臂:`cmvr-es/config/devices/arm/tchl_arm.pb.txt`。
|
||||
|
||||
七个关节按 `TCHL_AXIS_1` 至 `TCHL_AXIS_7` 排列,对应从站 `position: 0` 至 `6`。
|
||||
电机组及 MotorManager 的 ID 为 `tchl_joint_motors`,Arm 的 ID 为 `tchl_arm`。
|
||||
DeviceManager 已登记这两个设备,默认 `enable: false`;启用前填写各轴实际换算参数及限位。
|
||||
|
||||
纯 MoveJ 配置可以省略 `kinematics`、`joint_path`、`move_l`、`speed_l`,无需加载 URDF。
|
||||
省略整个 `joint_trajectory_smoother` 时,默认使用五次 B 样条,采样周期为 `0.001 s`,控制点间距为 `0.05 rad`。
|
||||
没有运动学配置时,Arm 初始化会读取电机缓存的配置限位;MoveJ 使用其中的位置、速度上限,
|
||||
并将请求加速度收紧至各轴已配置的正加速度上限中的最小值。限位不是从驱动器读回的值。
|
||||
已有运动学配置继续使用原来的 IK 位置、速度限位。显式配置 `move_l`、`speed_l` 或 `joint_path` 时仍需提供运动学配置。
|
||||
|
||||
先初始化 MotorManager,再初始化 MotorRobotArm 并调用 `torqueOn()`。随后可调用:
|
||||
|
||||
```cpp
|
||||
MotionOptions options;
|
||||
options.velocity = 0.2; // rad/s
|
||||
options.acceleration = 0.5; // rad/s^2
|
||||
options.jerk = 5.0; // rad/s^3
|
||||
auto result = arm.moveJ(
|
||||
JointPositionCommand{{0.1, -0.1, 0.1, -0.1, 0.1, -0.1, 0.1}}, options);
|
||||
if (!result.ok()) {
|
||||
std::cerr << result.message << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
目标为输出轴绝对角度,顺序与 Arm 的 `joint_names` 一致。MoveJ 通过批量 CSP 下发,调用会等待轨迹完成及反馈稳定。
|
||||
|
||||
## 5. 代码结构
|
||||
|
||||
EtherCAT 总线运行时:
|
||||
@ -258,17 +291,21 @@ CSP 写目标位置 `607A` 和速度前馈 `60B1`;CSV 的目标速度写 `60FF
|
||||
|
||||
- 位置限位完整流程在 Adapter 中:写入 `607D:01/:02`,再设置 `3809:00 UINT16=1` 开启软限位,并读回验证。速度限位也由 Adapter 写入、读回 `607F` 和 `6081`;意优另外处理厂家限速对象 `2024`。
|
||||
- 初始化读取 `3136:00`(Pr1.54)和 `3137:00`(Pr1.55),均为 UINT16 毫秒值,范围 0–500。同川 Adapter 完整执行使能/失能:使能后等待固定 PrF.44 的 200 ms 加 Pr1.54;失能后等待 Pr1.55,再允许后续使能。
|
||||
- 强制释放抱闸先确认 `6041` 不是 Operation Enabled,再写 `381E:00 UINT16=128` 并读回。该读回只确认命令值,不能作为物理抱闸状态反馈。
|
||||
- 强制释放抱闸调用 `motor->brakeRelease()`:Adapter 先确认 `6041` 的使能位 bit2 为 `0`,再写 `381E:00 UINT16=128` 并读回;Quick Stop Active 的 bit2 仍为 `1`,不能直接松闸。`torqueOff()` 确认失能后检查该对象;若仍为非零,写 `0` 取消强制松闸并读回验证。读回只确认命令值,不能作为物理抱闸状态反馈。
|
||||
- 零位校准沿用 `motor->calibrateZeroQ()`,具体流程在 `TchlMotorAdapter::calibrateZero()` 中实现:停止并失能后,将 `6098:00 INT8` 设为 35、`607C:00 INT32` 设为 0,切换 `6060=6`,按 `0006→0007→000F→001F` 将当前位置定义为零。Adapter 内部处理使能/失能延迟、完成检查、最终失能、目标 PDO 同步和软限位恢复;`TchlMotor` 只调用 Adapter。意优仍由自己的 Adapter 实现完整校准,`Cia402Protocol` 不提供厂家校准流程。
|
||||
- 同川手册还给出了写 `3801:00 UINT16=5` 后断电重启的置零方式;上述接口使用方法 35,其掉电保持尚未实机验证。
|
||||
|
||||
单轴用例保留 `TEST` 名称以便选择运行,公共 `initMotor()` 通过 `MotorManager` 初始化并取得电机,后续直接调用 Motor 接口。初始化或命令失败时抛出 `std::runtime_error`,不使用 `ASSERT/EXPECT`。反馈每 100 ms 分别调用 `getQ()`、`getQd()`、`getTau()`,不是同一个原子采样快照。
|
||||
|
||||
用例没有退出停车、失能或信号处理逻辑,也不调用 `manager->stop()`。正常返回或异常展开时,`EthercatMotorBusRuntime` 析构仅结束通信线程并释放 master,不下发电机停车或失能命令。
|
||||
|
||||
### 单轴 PP 实机测试
|
||||
|
||||
`commandProfilePosition(target_q, max_qd, max_qdd)` 使用 `abs(max_qd)` 作为速度幅值,方向由目标位置决定,传入 `-1` 和 `1` 均按 `1 rad/s` 执行。`Cia402Protocol` 对 `0` 和非有限速度直接返回 `false`,不读取原有 `6081`,也不下发新目标;这不表示停止已在执行的运动。
|
||||
|
||||
测试入口为 `tchl_motor_real_test` 的 `TchlMotorRealTest.ProfilePosition`。默认读取同川单轴模板,可用环境变量 `TCHL_MOTOR_CONFIG` 指定配置文件。
|
||||
|
||||
测试使用 `MotorManager` 完成总线、电机及限位初始化,随后设置 PP 模式、使能、下发一次目标、打印反馈。目标是绝对输出轴位置 `1.57 rad`,速度 `0.5 rad/s`,加减速度 `5.0 rad/s²`;修改测试文件顶部三个常量即可。每 100 ms 打印目标、实际位置、速度和额定力矩千分比,共打印 10 秒,不自动返回起点,也不进行到位或轮廓参数读回校验。
|
||||
|
||||
正常结束、接口失败或收到 Ctrl+C 后,依次尝试 `quickStop`、`torqueOff`,最后停止总线。Ctrl+C 在当前阻塞接口返回后处理。
|
||||
测试设置 PP 模式、使能、下发一次目标、打印反馈。目标是绝对输出轴位置 `1.57 rad`,速度 `0.5 rad/s`,加减速度 `5.0 rad/s²`;修改测试文件顶部三个常量即可。目标打印一次,随后打印实际位置、速度和额定力矩千分比,共打印 10 秒。
|
||||
|
||||
构建和列举用例:
|
||||
|
||||
@ -296,9 +333,9 @@ qd_target = Δq / 2 × ω × sin(ωt)
|
||||
ω = 2π / T
|
||||
```
|
||||
|
||||
`q0` 取设置 CSP 并使能后的实际位置。当前 `Δq = 1.57 rad`、`T = 6 s`、运行两周期(12 秒),范围为 `q0` 到 `q0 + 1.57 rad`;可修改测试顶部的 `kCspExcursionRad`、`kCspPeriodS`、`kCspCycles`。开始下发前检查整个轨迹在配置的位置限位内。
|
||||
`q0` 取设置 CSP 并使能后的实际位置。当前 `Δq = 1.57 rad`、`T = 6 s`、运行两周期(12 秒),范围为 `q0` 到 `q0 + 1.57 rad`;可修改测试顶部的 `kCspExcursionRad`、`kCspPeriodS`、`kCspCycles`。
|
||||
|
||||
下发间隔使用 `ethercat.cycle_us`(当前为 1 ms),位置经 PDO 写入 `607A`,速度前馈写入同川的 `60B1`。轨迹按实际经过时间计算,延迟后跳过错过的时刻;每 100 ms 打印目标位置、目标速度及实际位置、速度、力矩。正常结束下发起点位置和零前馈,再停止、失能;中途 Ctrl+C 直接停止、失能。
|
||||
下发间隔使用测试常量 `kCommandPeriod = 1 ms`,独立于总线配置。`commandCyclicPosition()` 将目标位置写入 PDO `607A`,速度前馈写入同川的 `60B1`。轨迹按实际经过时间计算,延迟后跳过错过的时刻;每 100 ms 打印目标位置、目标速度及反馈,最后下发起点位置和零前馈。
|
||||
|
||||
以下命令会使能并移动电机:
|
||||
|
||||
@ -314,14 +351,12 @@ LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
||||
|
||||
| 用例 | 目标及持续时间 | 下发方式 |
|
||||
| --- | --- | --- |
|
||||
| `TchlMotorRealTest.ProfileVelocity` | `0.3 rad/s`,加减速度 `1 rad/s²`,运行 2 秒;随后下发零速度并打印 1 秒 | 每个阶段调用一次 `commandProfileVelocity`;`6083/6084` 通过 SDO 配置,`60FF` 通过 PDO 下发 |
|
||||
| `TchlMotorRealTest.CyclicVelocitySin` | `qd = 0.2 × sin(2πt/6) rad/s`,运行两周期(12 秒),最后下发零速度 | 按 `ethercat.cycle_us`(当前 1 ms)调用 `commandCyclicVelocity`,写入 PDO `60FF` |
|
||||
| `TchlMotorRealTest.ProfileVelocity` | 设置 PV 模式并使能,目标速度 `-0.3 rad/s`,加减速度 `1.0 rad/s²`,持续打印反馈,直到进程结束 | 调用一次 `commandProfileVelocity` 下发目标 |
|
||||
| `TchlMotorRealTest.CyclicVelocitySin` | `qd = 0.8 × sin(2πt/6) rad/s`,运行两周期(12 秒),最后下发零速度 | 按测试常量 `kCommandPeriod = 1 ms` 调用 `commandCyclicVelocity`,写入 PDO `60FF` |
|
||||
|
||||
可修改测试顶部的 `kPvVelocityRadS`、`kPvAccelerationRadS2`、`kPvDuration` 和 `kCsvVelocityAmplitudeRadS`、`kCsvPeriodS`、`kCsvCycles`。两个用例每 100 ms 打印目标速度、实际位置、实际速度和力矩;开始前检查预计行程及速度限位,打印反馈时检查实际位置是否越界。正常结束、接口失败或 Ctrl+C 都会执行停止和失能。
|
||||
PV 可修改测试顶部的 `kPvVelocityRadS`、`kPvAccelerationRadS2`;CSV 可修改 `kCsvVelocityAmplitudeRadS`、`kCsvPeriodS`、`kCsvCycles`。两个用例每 100 ms 打印实际位置、速度和力矩;PV 在下发时打印目标速度,CSV 随周期打印目标速度。
|
||||
|
||||
默认 PV 预计前进约 `0.6 rad`,开始前按 `0.645 rad` 预留运行及减速空间;CSV 的理想最大位移约为 `0.382 rad`,整周期积分回到起点,实际位置以反馈为准。
|
||||
|
||||
分别运行以下用例会使能并移动电机:
|
||||
分别运行以下用例:
|
||||
|
||||
```bash
|
||||
LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
||||
@ -333,9 +368,39 @@ LD_LIBRARY_PATH="$PWD/dependency/x86/third_party/grpc/v1.76.0/lib" \
|
||||
--gtest_filter=TchlMotorRealTest.CyclicVelocitySin
|
||||
```
|
||||
|
||||
### 单轴运动中减速停车测试
|
||||
|
||||
`quickStop(double deceleration = 5.0)` 的减速度单位为输出轴 `rad/s²`,必须是有限正数。省略参数时使用 `5.0`,例如 `motor->quickStop()`;需要其他减速度时传入 `motor->quickStop(1.0)`。
|
||||
|
||||
`Cia402Protocol` 将减速度按编码器分辨率、减速比换算后,通过 SDO 写入 `6085:00 UINT32`,并设置 `605A:00 INT16=2`,然后通过 PDO 写 `6040=0x000B`,等待实际速度接近零。意优和同川的 PP/PV/CSP/CSV 模式都按快停减速度停车,停车后失能;力矩模式的停车斜坡另由驱动器定义,意优使用 `6087`。参数仅写入运行字典,不执行保存;参数下发失败仍尝试发送快停控制字,但接口返回 `false`。
|
||||
|
||||
入口为 `TchlMotorRealTest.QuickStopInProfileVelocity`。测试设置 PV 模式并使能,以 `±0.3 rad/s`、加减速度 `1 rad/s²` 运行 2 秒;当前位置大于零时取负速度,否则取正速度。随后调用 `motor->quickStop()`,使用默认快停减速度 `5.0 rad/s²`,再打印反馈 1 秒。测试只调用 Motor 接口,不直接读写 SDO 或断言预计行程。
|
||||
|
||||
`quickStop()` 阻塞到停车完成或配置的 `velocity_stop_timeout_ms` 超时,调用期间不打印反馈;100 ms 的打印间隔不能还原完整减速曲线。较小减速度需要相应增大等待超时。
|
||||
|
||||
下方命令优先加载 `output/lib`,接口修改后需先重新构建并 install,确保测试程序和运行库版本一致。
|
||||
|
||||
```bash
|
||||
LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
||||
./cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
||||
--gtest_filter=TchlMotorRealTest.QuickStopInProfileVelocity
|
||||
```
|
||||
|
||||
### 单轴释放刹车测试
|
||||
|
||||
入口为 `TchlMotorRealTest.BrakeRelease`。先调用 `torqueOff()` 确认失能,再调用一次 `brakeRelease()`,保持总线运行 10 秒,每 100 ms 打印实际位置、速度和力矩。测试不发送使能或运动指令;松闸后轴可能因重力或外力运动,运行前需支撑好机械轴和负载。
|
||||
|
||||
退出时不调用 `torqueOff()`,也不主动清除强制松闸命令。
|
||||
|
||||
```bash
|
||||
LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
||||
./cmake-build-debug/cmvr-es/devices/motor/drivers/ethercat_motor/tchl_motor_real_test \
|
||||
--gtest_filter=TchlMotorRealTest.BrakeRelease
|
||||
```
|
||||
|
||||
### 单轴当前位置置零测试
|
||||
|
||||
入口为 `TchlMotorRealTest.CalibrateZeroQ`。将机械轴放在希望定义为零点的位置后单独运行。测试调用一次 `motor->calibrateZeroQ()`,打印校准前后的实际位置、速度、力矩和模式。方法 35 内部会暂时使能,成功后保持失能、模式为 Homing;后续运动需先设置所需模式,再重新使能。
|
||||
入口为 `TchlMotorRealTest.CalibrateZeroQ`。将机械轴放在希望定义为零点的位置后单独运行。测试调用一次 `motor->calibrateZeroQ()`,打印校准前后的实际位置、速度和力矩。方法 35 内部会暂时使能,成功后保持失能、模式为 Homing;后续运动需先设置所需模式,再重新使能。
|
||||
|
||||
Adapter 检查启动命令已经到达驱动、状态字 bit12/bit10 已置位、bit13 无错误且实际位置接近 0。等待默认超时 2000 ms、轮询 10 ms、位置容差 100 个计数,可通过已有 `ethercat.zero_calibration` 配置覆盖。配置中的软限位会按新零点重新应用。
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user