feat(touch): initialize xiaozhao head and update simulation setup

Register the neck as a three-DOF MotorRobotArm and add optional head
initialization to the touch task. Run a synchronous MoveJ before entering
IDLE, validate the complete joint set, and fail initialization when the
head is unavailable or motion fails. Preserve existing configurations.

Set the head startup target to [0.15, -0.1, 0.1] rad. Include the updated
S05-reference screen layout, matching right-arm preset and documentation.

Validation: Release build and 29 related tests passed. An isolated MuJoCo
probe verified task initialization moving the head from a nonzero pose to
its configured zero target before the final target-value update. The final
configuration parsed successfully. Full visual-servo motion was not tested.
This commit is contained in:
lgv 2026-11-18 10:06:43 +08:00
parent 90bae95654
commit 2c4dff5d7f
11 changed files with 526 additions and 64 deletions

View File

@ -0,0 +1,35 @@
# xiaozhao 三轴颈部按 RobotArm 注册,仅使用关节空间控制。
# MoveJ 目标顺序为 neck-joint1、neck-joint2、neck-joint3,单位为弧度。
arm {
robot_arms {
id: "xiaozhao_head"
motor {
motor_system_id: "xiaozhao_head_motors"
motor_group_ids: "xiaozhao_head_motors"
dof: 3
joint_names: "neck-joint1"
joint_names: "neck-joint2"
joint_names: "neck-joint3"
upd_freq: 1000
buffer_size: 50
default_vel: 0.25
default_acc: 0.5
}
motion {
joint_trajectory_smoother {
sample_period_s: 0.001
quintic_bspline {
control_point_spacing_rad: 0.05
}
}
move_j {
settle_timeout_s: 3.0
settle_position_tolerance_rad: 0.002
settle_velocity_tolerance_rad_s: 0.02
settle_stable_sample_count: 3
}
}
}
}

View File

@ -62,4 +62,26 @@ motor {
motors { id: 7 joint_name: "joint7-right" }
}
}
motor_groups {
id: "xiaozhao_head_motors"
bus_type: MOTOR_BUS_MUJOCO
vendor: MOTOR_VENDOR_MUJOCO
protocol: MOTOR_PROTOCOL_MUJOCO
mujoco {
world_id: "mujoco_world"
}
joint_limits {
enable: true
source: JOINT_LIMIT_SOURCE_CUSTOM
joints { joint_name: "neck-joint1" q_lb: -1.57 q_ub: 1.57 qd: 0.5 qdd: 2.0 }
joints { joint_name: "neck-joint2" q_lb: -1.57 q_ub: 0.44 qd: 0.5 qdd: 2.0 }
joints { joint_name: "neck-joint3" q_lb: -0.44 q_ub: 0.44 qd: 0.5 qdd: 2.0 }
}
motors {
motors { id: 1 joint_name: "neck-joint1" }
motors { id: 2 joint_name: "neck-joint2" }
motors { id: 3 joint_name: "neck-joint3" }
}
}
}

View File

@ -2,7 +2,7 @@ device_manager {
name: "cmvr_es"
version: "0.1"
description: "cmvr edge system version 0.1"
# xiaozhao 双臂与右臂触屏仿真:先创建 world,再创建电机、机械臂、viewer 和传感器。
# xiaozhao 双臂、颈部与右臂触屏仿真:先创建 world,再创建电机、机械臂、viewer 和传感器。
devices {
id: "mujoco_world"
type: DEVICE_TYPE_MUJOCO_WORLD
@ -24,6 +24,13 @@ device_manager {
enable: true
}
devices {
id: "xiaozhao_head_motors"
type: DEVICE_TYPE_MOTOR_SYSTEM
config_file: "devices/motor/xiaozhao_motors.pb.txt"
enable: true
}
devices {
id: "xiaozhao_left_arm"
type: DEVICE_TYPE_ROBOT_ARM
@ -38,6 +45,13 @@ device_manager {
enable: true
}
devices {
id: "xiaozhao_head"
type: DEVICE_TYPE_ROBOT_ARM
config_file: "devices/arm/xiaozhao_head.pb.txt"
enable: true
}
devices {
id: "right_arm_mujoco_motors"
type: DEVICE_TYPE_MOTOR_SYSTEM

View File

@ -1,5 +1,5 @@
task_manager {
# xiaozhao 右臂触屏流程仿真;任务启动后等待 gRPC touch 请求,不自动运动。
# xiaozhao 触屏仿真:初始化时头部 MoveJ 到预设位,随后等待 gRPC touch 请求。
tasks {
id: "touch_screen"
type: TASK_TYPE_TOUCH_SCREEN

View File

@ -8,6 +8,7 @@ touch_screen_task {
devices {
arm_id: "xiaozhao_right_arm"
head_id: "xiaozhao_head"
# ZeroSimTouch 始终返回零力,用于测试无接触时的前进限距和回撤流程。
touch_id: "mujoco_zero_touch"
# 手部相机和外部相机的 DeviceManager ID。
@ -15,6 +16,17 @@ touch_screen_task {
external_camera_id: "mujoco_external_touch_cam"
}
# 任务 init() 时同步执行一次头部 MoveJ,到位后任务才进入 IDLE。
# 后续每次 touch 请求不重复移动头部。角度单位 rad,顺序通过关节名匹配。
head_initialization {
enable: true
joint_positions { joint_name: "neck-joint1" rad: 0.15 }
joint_positions { joint_name: "neck-joint2" rad: -0.1 }
joint_positions { joint_name: "neck-joint3" rad: 0.1 }
velocity: 0.25
acceleration: 0.5
}
initialization {
# 开始前使用 MoveJ 回到初始关节位置。
before_start: true
@ -22,15 +34,16 @@ touch_screen_task {
# 每次测试前仍通过上面的 MoveJ 回到初始位。
after_finish: false
after_failure: false
# 正前方屏幕起姿:TCP 约 (0.50738, -0.12160, 0.43024) m,头部三关节保持零位。
# 此姿态下手相机识别屏幕 Tag,头部相机同时识别屏幕/手部 Tag。
joint_positions { joint_name: "joint1-right" rad: 1.8647731978 }
joint_positions { joint_name: "joint2-right" rad: 0.9322349780 }
joint_positions { joint_name: "joint3-right" rad: -0.3888895185 }
joint_positions { joint_name: "joint4-right" rad: 1.7262026729 }
joint_positions { joint_name: "joint5-right" rad: -1.3492569035 }
joint_positions { joint_name: "joint6-right" rad: -0.2361915889 }
joint_positions { joint_name: "joint7-right" rad: -0.9300000000 }
# S05 参考布局(左右偏转0°、后仰15°)起姿:TCP约(0.52237,-0.23207,0.42622)m。
# 原识别验证在颈部零位完成;当前头部角度由 head_initialization 指定。
# 手相机 1280x720 原图中 (953, 592) 附近为可见屏幕区域;点击运动尚未动态验证。
joint_positions { joint_name: "joint1-right" rad: 1.8648861126 }
joint_positions { joint_name: "joint2-right" rad: 0.8084619160 }
joint_positions { joint_name: "joint3-right" rad: -0.4141750858 }
joint_positions { joint_name: "joint4-right" rad: 1.6622227972 }
joint_positions { joint_name: "joint5-right" rad: -1.3312572926 }
joint_positions { joint_name: "joint6-right" rad: -0.2423592867 }
joint_positions { joint_name: "joint7-right" rad: -1.0088169947 }
velocity: 0.5
acceleration: 1.0
# 当前关节位置误差小于该值时跳过初始位置回位,单位为弧度。
@ -97,7 +110,7 @@ touch_screen_task {
rx: 0.0
ry: 0.0
# 使用检测得到的 G:屏幕纹理使 G 相对 MJCF body 绕 Z 旋转 pi,H 与 body 同向。
# 因此这里的 pi 对应物理手部正立、TCP +Z 向上;设为 0 反而会翻转手腕。
# 因此这里的 pi 对应物理手部正立、TCP +Z 沿屏幕向上;设为 0 反而会翻转手腕。
rz: 3.141592653589793
}
# 点击目标点到 TCP 预对齐位置的偏移,表达在 G 坐标系,单位为米。

View File

@ -81,6 +81,11 @@ public:
const std::shared_ptr<device::AbstractTouch>& touch_sensor,
const std::shared_ptr<device::AbstractCamera>& camera,
const std::shared_ptr<device::AbstractCamera>& external_camera);
bool init(const std::shared_ptr<device::RobotArm>& arm,
const std::shared_ptr<device::AbstractTouch>& touch_sensor,
const std::shared_ptr<device::AbstractCamera>& camera,
const std::shared_ptr<device::AbstractCamera>& external_camera,
const std::shared_ptr<device::RobotArm>& head);
const std::string& id() const override { return id_; }
@ -148,6 +153,7 @@ private:
bool buildInitJointPositions(std::vector<double>& positions_out) const;
bool isAtInitPosition(const std::vector<double>& positions) const;
bool moveToInitPositionIfEnabled(bool enabled, bool use_move_j = false);
bool initializeHead(const std::shared_ptr<device::RobotArm>& head);
bool readCurrentTouchPointPositionBase(Eigen::Vector3d& p_out) const;
void logTouchingSpeedLState() const;

View File

@ -213,6 +213,8 @@ bool TouchScreenTask::init() {
auto camera = dm.getDevice<device::AbstractCamera>(devices.camera_id());
auto external_camera =
dm.getDevice<device::AbstractCamera>(devices.external_camera_id());
auto head = config_.head_initialization().enable()
? dm.getDevice<device::RobotArm>(devices.head_id()) : nullptr;
if (!camera || !camera->start()) {
CMVR_LOG(ERROR) << "[TouchScreenTask] Failed to start camera: " << devices.camera_id();
return false;
@ -222,7 +224,7 @@ bool TouchScreenTask::init() {
<< devices.external_camera_id();
return false;
}
return init(arm, touch_sensor, camera, external_camera);
return init(arm, touch_sensor, camera, external_camera, head);
}
bool TouchScreenTask::init(const std::shared_ptr<device::RobotArm>& arm,
@ -233,13 +235,24 @@ bool TouchScreenTask::init(const std::shared_ptr<device::RobotArm>& arm,
external_camera = device::DeviceManager::getInstance().getDevice<device::AbstractCamera>(
config_.devices().external_camera_id());
}
return init(arm, touch_sensor, camera, external_camera);
auto head = config_.head_initialization().enable()
? device::DeviceManager::getInstance().getDevice<device::RobotArm>(
config_.devices().head_id()) : nullptr;
return init(arm, touch_sensor, camera, external_camera, head);
}
bool TouchScreenTask::init(const std::shared_ptr<device::RobotArm>& arm,
const std::shared_ptr<device::AbstractTouch>& touch_sensor,
const std::shared_ptr<device::AbstractCamera>& camera,
const std::shared_ptr<device::AbstractCamera>& external_camera) {
return init(arm, touch_sensor, camera, external_camera, nullptr);
}
bool TouchScreenTask::init(const std::shared_ptr<device::RobotArm>& arm,
const std::shared_ptr<device::AbstractTouch>& touch_sensor,
const std::shared_ptr<device::AbstractCamera>& camera,
const std::shared_ptr<device::AbstractCamera>& external_camera,
const std::shared_ptr<device::RobotArm>& head) {
std::lock_guard<std::mutex> lock(mutex_);
stopUnlocked();
initialized_ = false;
@ -266,21 +279,25 @@ bool TouchScreenTask::init(const std::shared_ptr<device::RobotArm>& arm,
std::make_shared<perception::AprilTagPerception>(external_camera_);
tracker_.setPerception(perception_);
initialized_ = applyConfig();
if (initialized_) {
tracker_.clear();
tracker_.resetActiveTagTracking();
tcp_pose_tracker_.clear();
pbvs_.reset();
phase_ = Phase::IDLE;
resetRunState();
last_status_ = Status::IDLE;
// Make presentation settings available before the first task tick.
publishCoordinateOverlay();
startCoordinateOverlayWorker();
} else {
if (!applyConfig()) {
last_status_ = Status::INVALID_CONFIG;
return false;
}
if (!initializeHead(head)) {
phase_ = Phase::FAILED;
return false;
}
initialized_ = true;
tracker_.clear();
tracker_.resetActiveTagTracking();
tcp_pose_tracker_.clear();
pbvs_.reset();
phase_ = Phase::IDLE;
resetRunState();
last_status_ = Status::IDLE;
// Make presentation settings available before the first task tick.
publishCoordinateOverlay();
startCoordinateOverlayWorker();
return initialized_;
}
@ -786,6 +803,27 @@ bool TouchScreenTask::validateConfig(const cmvr::config::TouchScreenTaskConfig&
return false;
}
const auto& head_init = config.head_initialization();
if (head_init.enable()) {
if (config.devices().head_id().empty() ||
config.devices().head_id() == config.devices().arm_id() ||
head_init.joint_positions().empty() ||
!head_init.has_velocity() || !std::isfinite(head_init.velocity()) ||
head_init.velocity() <= 0.0 ||
!head_init.has_acceleration() || !std::isfinite(head_init.acceleration()) ||
head_init.acceleration() <= 0.0) {
return false;
}
std::unordered_set<std::string> head_joints;
for (const auto& joint : head_init.joint_positions()) {
if (joint.joint_name().empty() || !joint.has_rad() ||
!std::isfinite(joint.rad()) ||
!head_joints.insert(joint.joint_name()).second) {
return false;
}
}
}
const auto& perception = config.perception();
const auto& tags = perception.tags();
const auto& hand_tag = tags.hand();
@ -1861,6 +1899,62 @@ void TouchScreenTask::logTouchingSpeedLState() const {
CMVR_LOG(DEBUG) << state_log.str();
}
bool TouchScreenTask::initializeHead(const std::shared_ptr<device::RobotArm>& head) {
const auto& head_init = config_.head_initialization();
if (!head_init.enable()) return true;
const auto fail = [&](const Status status, const std::string& message) {
CMVR_LOG(ERROR) << "[TouchScreenTask][HEAD_INIT] head=" << config_.devices().head_id()
<< ", " << message;
last_status_ = status;
return false;
};
if (!head || head == arm_) {
return fail(Status::INVALID_CONFIG, "head must be a separate RobotArm device");
}
try {
// Match the complete joint set, then reorder by the device's joint order.
const auto names = head->getRobotModel().joint_names;
if (names.size() != head->getDof() ||
names.size() != static_cast<std::size_t>(head_init.joint_positions_size())) {
return fail(Status::INVALID_CONFIG, "head joint count does not match configuration");
}
std::unordered_map<std::string, double> targets;
for (const auto& joint : head_init.joint_positions()) {
targets.emplace(joint.joint_name(), joint.rad());
}
device::JointPositionCommand command;
for (const auto& name : names) {
const auto it = targets.find(name);
if (it == targets.end()) {
return fail(Status::INVALID_CONFIG, "unknown or duplicate head joint: " + name);
}
command.position.push_back(it->second);
targets.erase(it);
}
if (!head->isConnected() || head->isEmergencyStopped() ||
head->isProtectiveStopped() || head->isFault() || head->busy()) {
return fail(Status::ROBOT_COMMAND_FAILED, "head is disconnected, stopped, faulted or busy");
}
device::MotionOptions options;
options.velocity = head_init.velocity();
options.acceleration = head_init.acceleration();
CMVR_LOG(INFO) << "[TouchScreenTask][HEAD_INIT] moveJ start, head="
<< config_.devices().head_id();
const auto result = head->moveJ(command, options);
if (!result.ok()) return fail(Status::ROBOT_COMMAND_FAILED, "moveJ failed: " + result.message);
CMVR_LOG(INFO) << "[TouchScreenTask][HEAD_INIT] moveJ complete, head="
<< config_.devices().head_id();
return true;
} catch (const std::exception& error) {
return fail(Status::ROBOT_COMMAND_FAILED, error.what());
} catch (...) {
return fail(Status::ROBOT_COMMAND_FAILED, "unknown moveJ initialization error");
}
}
bool TouchScreenTask::buildInitJointPositions(std::vector<double>& positions_out) const {
if (!arm_) {
return false;

View File

@ -13,6 +13,7 @@
#include <limits>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>
#include <thread>
#include <unordered_set>
@ -213,10 +214,13 @@ public:
bool isEmergencyStopped() const override { return emergency; }
bool isFault() const override { return planning_fault; }
bool isConnected() const override { return connected; }
bool busy() const override { return false; }
bool busy() const override { return motion_busy; }
double getSpeedScaling() const override { return 1.0; }
Result stopL(std::optional<double>) override { return Result::success(); }
Result stopL(std::optional<double>) override {
++stop_l_calls;
return Result::success();
}
Result stopMotion() override {
calls.push_back("stopMotion");
return stop_result;
@ -238,6 +242,7 @@ public:
calls.push_back("moveJ");
startup_target = target.position;
startup_options = options;
if (move_j_throws) throw std::runtime_error("injected moveJ exception");
return move_result;
}
@ -291,6 +296,9 @@ public:
bool connected{true};
bool emergency{false};
bool protective{false};
bool motion_busy{false};
bool move_j_throws{false};
int stop_l_calls{0};
std::vector<std::string> calls;
std::vector<double> return_target;
cmvr::device::MotionOptions return_options;
@ -336,6 +344,44 @@ protected:
std::shared_ptr<FailureReturnArm> arm;
};
class TouchScreenHeadInitializationTest : public ::testing::Test {
protected:
void SetUp() override {
config = loadMujocoTouchConfig(findProjectRoot());
config.set_debug_draw_coordinate_frames(false);
config.mutable_approach()->set_enable(false);
config.mutable_initialization()->set_before_start(false);
config.mutable_initialization()->set_after_finish(false);
config.mutable_initialization()->set_after_failure(false);
config.mutable_devices()->set_head_id("test_head");
auto* initialization = config.mutable_head_initialization();
initialization->set_enable(true);
initialization->set_velocity(0.25);
initialization->set_acceleration(0.5);
// Deliberately reverse the configuration order: commands must follow
// the head model's joint order, not protobuf insertion order.
auto* joint = initialization->add_joint_positions();
joint->set_joint_name("neck-joint2");
joint->set_rad(0.15);
joint = initialization->add_joint_positions();
joint->set_joint_name("neck-joint1");
joint->set_rad(-0.2);
arm = std::make_shared<FailureReturnArm>(config);
head = std::make_shared<FailureReturnArm>(config);
head->model.joint_names = {"neck-joint1", "neck-joint2"};
head->model.dof = 2;
head->state.position = {0.0, 0.0};
head->state.velocity = {0.0, 0.0};
camera = std::make_shared<FailureReturnCamera>();
}
cmvr::config::TouchScreenTaskConfig config;
std::shared_ptr<FailureReturnArm> arm;
std::shared_ptr<FailureReturnArm> head;
std::shared_ptr<FailureReturnCamera> camera;
};
cmvr::device::DeviceManager& getTestDeviceManager() {
static bool initialized = [] {
cmvr::ConfigHelper::setConfigRootFromFile("cmvr-es/config/cmvr_es.pb.txt");
@ -686,6 +732,196 @@ TEST_F(TouchScreenFailureReturnTest, FailedReturnPreservesOriginalFailure) {
EXPECT_EQ(arm->calls, (std::vector<std::string>{"stopMotion", "moveP"}));
}
TEST_F(TouchScreenHeadInitializationTest, AbsentOrDisabledConfigurationDoesNotCommandEitherDevice) {
for (const auto* mode : {"absent", "disabled", "enable_unset"}) {
SCOPED_TRACE(mode);
auto cfg = config;
if (std::string(mode) == "absent") {
cfg.clear_head_initialization();
cfg.mutable_devices()->clear_head_id();
} else {
auto* initialization = cfg.mutable_head_initialization();
initialization->set_enable(false);
if (std::string(mode) == "enable_unset") initialization->clear_enable();
// Disabled settings must not constrain existing configurations.
cfg.mutable_devices()->set_head_id(cfg.devices().arm_id());
initialization->clear_velocity();
initialization->set_acceleration(-1.0);
initialization->mutable_joint_positions(0)->set_rad(
std::numeric_limits<double>::quiet_NaN());
}
cmvr::task::TouchScreenTask task(cfg);
ASSERT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::NOT_INITIALIZED);
if (std::string(mode) == "absent") {
ASSERT_TRUE(task.init(arm, nullptr, camera, camera));
} else {
ASSERT_TRUE(task.init(arm, nullptr, camera, camera, head));
}
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::IDLE);
EXPECT_TRUE(arm->calls.empty());
EXPECT_TRUE(head->calls.empty());
EXPECT_EQ(arm->stop_l_calls, 0);
EXPECT_EQ(head->stop_l_calls, 0);
}
}
TEST_F(TouchScreenHeadInitializationTest, MovesOnlyHeadOnceInModelJointOrderWithConfiguredLimits) {
cmvr::task::TouchScreenTask task(config);
ASSERT_TRUE(task.init(arm, nullptr, camera, camera, head));
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::IDLE);
EXPECT_EQ(task.phase(), cmvr::task::TouchScreenTask::Phase::IDLE);
EXPECT_EQ(head->calls, std::vector<std::string>{"moveJ"});
EXPECT_EQ(head->startup_target, (std::vector<double>{-0.2, 0.15}));
EXPECT_DOUBLE_EQ(head->startup_options.velocity, 0.25);
EXPECT_DOUBLE_EQ(head->startup_options.acceleration, 0.5);
EXPECT_EQ(head->stop_l_calls, 0);
EXPECT_TRUE(arm->calls.empty());
EXPECT_EQ(arm->stop_l_calls, 0);
}
TEST_F(TouchScreenHeadInitializationTest, RepeatedTouchRequestsDoNotRepeatHeadInitialization) {
cmvr::task::TouchScreenTask task(config);
ASSERT_TRUE(task.init(arm, nullptr, camera, camera, head));
ASSERT_TRUE(task.touch(320, 240));
task.stop();
ASSERT_TRUE(task.touch(350, 260));
EXPECT_EQ(head->calls, std::vector<std::string>{"moveJ"});
EXPECT_EQ(head->stop_l_calls, 0);
EXPECT_EQ(arm->calls, (std::vector<std::string>{
"stopMotion", "recoverSpeedLPlanningFault",
"stopMotion", "recoverSpeedLPlanningFault"}));
}
TEST_F(TouchScreenHeadInitializationTest, EnabledConfigurationRequiresHeadIdAndCompleteFiniteParameters) {
for (const auto* invalid_case : {
"missing_id", "empty_id", "touch_arm_id", "empty_joints", "missing_name",
"empty_name", "missing_position", "duplicate", "nan_position", "infinite_position",
"missing_velocity", "zero_velocity", "negative_velocity", "nan_velocity",
"infinite_velocity", "missing_acceleration", "zero_acceleration",
"negative_acceleration", "nan_acceleration", "infinite_acceleration"}) {
SCOPED_TRACE(invalid_case);
auto cfg = config;
auto* initialization = cfg.mutable_head_initialization();
const std::string name(invalid_case);
if (name == "missing_id") cfg.mutable_devices()->clear_head_id();
if (name == "empty_id") cfg.mutable_devices()->set_head_id("");
if (name == "touch_arm_id") cfg.mutable_devices()->set_head_id(cfg.devices().arm_id());
if (name == "empty_joints") initialization->clear_joint_positions();
if (name == "duplicate") {
const auto joint = initialization->joint_positions(0);
*initialization->add_joint_positions() = joint;
}
if (name == "missing_name") initialization->mutable_joint_positions(0)->clear_joint_name();
if (name == "empty_name") initialization->mutable_joint_positions(0)->set_joint_name("");
if (name == "missing_position") initialization->mutable_joint_positions(0)->clear_rad();
if (name == "nan_position") initialization->mutable_joint_positions(0)->set_rad(
std::numeric_limits<double>::quiet_NaN());
if (name == "infinite_position") initialization->mutable_joint_positions(0)->set_rad(
std::numeric_limits<double>::infinity());
if (name == "missing_velocity") initialization->clear_velocity();
if (name == "zero_velocity") initialization->set_velocity(0.0);
if (name == "negative_velocity") initialization->set_velocity(-0.1);
if (name == "nan_velocity") initialization->set_velocity(std::numeric_limits<double>::quiet_NaN());
if (name == "infinite_velocity") initialization->set_velocity(std::numeric_limits<double>::infinity());
if (name == "missing_acceleration") initialization->clear_acceleration();
if (name == "zero_acceleration") initialization->set_acceleration(0.0);
if (name == "negative_acceleration") initialization->set_acceleration(-0.1);
if (name == "nan_acceleration") initialization->set_acceleration(std::numeric_limits<double>::quiet_NaN());
if (name == "infinite_acceleration") initialization->set_acceleration(std::numeric_limits<double>::infinity());
cmvr::task::TouchScreenTask task(cfg);
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::INVALID_CONFIG);
}
}
TEST_F(TouchScreenHeadInitializationTest, MissingHeadOrTouchArmAliasFailsWithoutCommands) {
for (const bool use_touch_arm : {false, true}) {
SCOPED_TRACE(use_touch_arm);
cmvr::task::TouchScreenTask task(config);
if (use_touch_arm) {
EXPECT_FALSE(task.init(arm, nullptr, camera, camera, arm));
} else {
// Existing four-argument callers remain source-compatible, but
// cannot silently skip explicitly enabled head initialization.
EXPECT_FALSE(task.init(arm, nullptr, camera, camera));
}
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::INVALID_CONFIG);
EXPECT_TRUE(arm->calls.empty());
EXPECT_TRUE(head->calls.empty());
EXPECT_EQ(arm->stop_l_calls, 0);
EXPECT_EQ(head->stop_l_calls, 0);
EXPECT_FALSE(task.touch(320, 240));
EXPECT_TRUE(arm->calls.empty());
}
}
TEST_F(TouchScreenHeadInitializationTest, HeadJointNamesMustExactlyMatchModel) {
for (const auto* mismatch : {"wrong_name", "missing_joint", "extra_joint"}) {
SCOPED_TRACE(mismatch);
auto cfg = config;
auto* initialization = cfg.mutable_head_initialization();
const std::string name(mismatch);
if (name == "wrong_name") {
initialization->mutable_joint_positions(0)->set_joint_name("not_a_head_joint");
} else if (name == "missing_joint") {
initialization->mutable_joint_positions()->RemoveLast();
} else {
auto* joint = initialization->add_joint_positions();
joint->set_joint_name("not_a_head_joint");
joint->set_rad(0.0);
}
cmvr::task::TouchScreenTask task(cfg);
ASSERT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::NOT_INITIALIZED);
EXPECT_FALSE(task.init(arm, nullptr, camera, camera, head));
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::INVALID_CONFIG);
EXPECT_TRUE(head->calls.empty());
EXPECT_TRUE(arm->calls.empty());
EXPECT_EQ(head->stop_l_calls, 0);
EXPECT_FALSE(task.touch(320, 240));
EXPECT_TRUE(arm->calls.empty());
}
}
TEST_F(TouchScreenHeadInitializationTest, UnavailableHeadFailsWithoutRecoveryOrMotion) {
for (const auto* condition : {"emergency", "protective", "disconnected", "fault", "busy"}) {
SCOPED_TRACE(condition);
const std::string name(condition);
head->emergency = name == "emergency";
head->protective = name == "protective";
head->connected = name != "disconnected";
head->planning_fault = name == "fault";
head->motion_busy = name == "busy";
cmvr::task::TouchScreenTask task(config);
EXPECT_FALSE(task.init(arm, nullptr, camera, camera, head));
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::ROBOT_COMMAND_FAILED);
EXPECT_TRUE(head->calls.empty());
EXPECT_EQ(head->stop_l_calls, 0);
EXPECT_TRUE(arm->calls.empty());
EXPECT_FALSE(task.touch(320, 240));
EXPECT_TRUE(arm->calls.empty());
}
}
TEST_F(TouchScreenHeadInitializationTest, FailedOrThrowingHeadMovePreventsTaskInitialization) {
for (const bool throws : {false, true}) {
SCOPED_TRACE(throws);
head->calls.clear();
head->move_j_throws = throws;
head->move_result = cmvr::device::Result::failure(
cmvr::device::ArmErrorCode::CommandFailed, "injected head move failure");
cmvr::task::TouchScreenTask task(config);
EXPECT_FALSE(task.init(arm, nullptr, camera, camera, head));
EXPECT_EQ(task.lastStatus(), cmvr::task::TouchScreenTask::Status::ROBOT_COMMAND_FAILED);
EXPECT_EQ(task.phase(), cmvr::task::TouchScreenTask::Phase::FAILED);
EXPECT_EQ(head->calls, std::vector<std::string>{"moveJ"});
EXPECT_EQ(head->stop_l_calls, 0);
EXPECT_TRUE(arm->calls.empty());
EXPECT_EQ(arm->stop_l_calls, 0);
EXPECT_FALSE(task.touch(320, 240));
EXPECT_EQ(head->calls, std::vector<std::string>{"moveJ"});
EXPECT_TRUE(arm->calls.empty());
}
}
TEST(TouchScreenTaskTest, FailureReturnRequiresValidInitialJointPositions) {
auto config = loadMujocoTouchConfig(findProjectRoot());
config.mutable_initialization()->set_before_start(false);

View File

@ -5,7 +5,7 @@
默认设备配置 `cmvr-es/config/manager/device_manager.pb.txt` 已选择
`devices/mujoco/xiaozhao_world.pb.txt`,加载 `model/xiaozhao/xml/scene.xml`。
场景包含机器人、地面、灯光、触控测试屏幕、手部/外部相机和共 17 个位置执行器(双臂 14 个、颈部 3 个),仿真步长为 1 ms。
已启用 MuJoCo world、viewer、xiaozhao 两组电机、左右臂、两路仿真相机、
已启用 MuJoCo world、viewer、xiaozhao 双臂与颈部电机、左右臂、头部、两路仿真相机、
零力触觉设备、右臂触屏任务和 gRPC 控制服务。原 xiaoyan 的电机、机械臂及真实硬件保持关闭。
xiaozhao 的双臂关节名为 `joint1-left`…`joint7-left` 和
`joint1-right`…`joint7-right`,不能直接复用原模型的机械臂配置。
@ -23,7 +23,9 @@ J2 `[-1.57, 0.44]`、J3 `[-0.44, 0.44]` rad;首关节已补偿现有基座绕
模型现有 17 个活动关节及对应的位置执行器,限位 CSV 包含双臂和颈部。
`actuators.xml` 中的 `neck-joint1_pos`~`neck-joint3_pos` 追加在双臂执行器之后,
保持双臂索引不变;颈部初始 `kp=80`、`dampratio=1`,控制量为弧度,范围与 URDF 限位一致。
可通过 MuJoCo 的 Control 面板调整三个颈部目标角;颈部尚未接入 CMVR 电机设备配置。
颈部已通过 `xiaozhao_head_motors` 接入 CMVR,并注册为 3DOF 机械臂 `xiaozhao_head`,
使用 `devices/arm/xiaozhao_head.pb.txt`,复用 MoveJ 关节控制,无需配置运动学求解器。
头部接管控制后,通过 ArmService 的 `xiaozhao_head` 控制三轴目标角。
颈部真正的零位(`qpos=0`)是直立的;Control 面板中的数值是执行器目标角度。
头部与下段颈部的凸包在内部机构处重叠,曾把零目标下的 J3 推到约 19.62°。
颈部仅排除 `neck_Link1`/`neck_Link3` 这一对内部碰撞,保留其他碰撞、关节原点、轴向及限位。
@ -50,11 +52,21 @@ MuJoCo 外观共 538,499 面。手部全部顶点和面中心的双向检查最
触控场景拆分为 `model/xiaozhao/xml/` 下的三个模块:`touch_scene.xml`、
`hand_camera.xml` 和 `head_camera.xml`。
`touch_scene.xml` 定义 50 × 30 cm 屏幕和屏幕 AprilTag ID 1;
Tag 位于机器人正面看向屏幕时的右上角,含白边距上边、右边各 18.75 mm,
中心为屏幕局部坐标 `(-0.22125, 0.0151, 0.12125) m`。
机器人正前方为 Base 的 `+X`。屏幕中心为世界坐标 `(0.60, 0, 0.38) m`,
屏幕正面朝 `−X`(朝向机器人),可直接在该文件调整位置。
`touch_scene.xml` 参考深蓝 S05 的 **15.4 英寸向日葵屏版本**设置中控屏及 AprilTag ID 1。
[官方车型页](https://www.changaneurope.com/uk/models/changan-deepal-s05-bev)确认屏幕为 15.4 英寸、
2.5K,可向驾驶员或乘客偏转 15°;此 15° 指左右转向,不是后仰角。
当前使用中国左舵布局,以 Base/世界原点作为主驾 H 点参考:`+X` 向前、`+Y` 向左、`+Z` 向上。
玻璃正面中心 `screen_center` 为 `(0.60, -0.25, 0.38) m`,即 H 点前方 600 mm、
右侧 250 mm、上方 380 mm;屏幕左右偏转设为 0°、后仰 15°。
位置、后仰角及 16:10 长宽比均为仿真估算,并非 S05 实测尺寸;按该长宽比和对角线,
玻璃显示区为约 331.703 × 207.314 mm,边框外沿另加每边 8 mm。
屏幕局部 `+Y` 为正面法向、`+Z` 向上、`−X` 为正面观看时的右侧;
旋转为 `Ry(15°) * Rz(90°)`,世界正面法向约 `(-0.965926, 0, 0.258819)`。
`touch_screen` body 的位置补偿了玻璃局部 `Y=0.015 m` 的偏移,不能直接当作玻璃中心。
Tag 保持右上角位置,含白边距上边、右边各 18.75 mm,局部中心为
`(-0.137101508297, 0.0151, 0.074907192686) m`;四角 site 也按正面观看方向命名。
原落地支架已换成简化背部固定支撑,不代表完整仪表台或真实座舱碰撞几何。
可直接在该文件调整屏幕位姿,无需重新生成机器人 XML。
`hand_camera.xml` 定义右手相机 `hand_cam` 和手部 AprilTag ID 0,
由生成脚本挂到 `link7-right`,随右手运动;
触控末端 TCP 仍使用已有的直径 5 mm 红球。
@ -70,9 +82,14 @@ Tag 位于机器人正面看向屏幕时的右上角,含白边距上边、右
小赵使用独立配置 `cmvr-es/config/tasks/touch_screen_task/touch_screen_task_xiaozhao_mujoco.pb.txt`,
绑定 `xiaozhao_right_arm`、`mujoco_hand_cam`、`mujoco_external_touch_cam` 和 `mujoco_zero_touch`。
两路相机使用 `devices/camera/xiaozhao_camera.pb.txt`,手相机原图为 1280 × 720,
头部相机为 2560 × 1440;16 mm 屏幕 Tag 在头部相机的 720p 图中存在明显姿态误估,
该初姿的 1440p 图经项目实际检测器验证,屏幕 Tag 姿态误差约 0.26°,G/H 相对位置误差约 1.3 mm。
任务启动后等待 gRPC `HlcService.touch(u, v)` 请求,不会自动运动。
头部相机为 2560 × 1440;旧居中屏幕布局下,16 mm 屏幕 Tag 在头部相机的 720p 图中
存在明显姿态误估,因此保留 1440p。旧布局测得的屏幕 Tag 姿态误差约 0.26°、
G/H 相对位置误差约 1.3 mm,不作为当前 S05 参考布局的精度结论。
触控配置中的 `devices.head_id` 指向 `xiaozhao_head`;`head_initialization.enable: true`
使任务在初始化期间执行一次头部 MoveJ,三轴 `neck-joint1/2/3` 的初始角设为 `[0.15, -0.1, 0.1]` rad,
速度 `0.25 rad/s`、加速度 `0.5 rad/s²`。可直接修改 `head_initialization.joint_positions`。
头部到位后任务才进入 IDLE,随后等待 gRPC `HlcService.touch(u, v)`;每次 touch 不重复移动头部。
头部缺失、关节配置不匹配或 MoveJ 失败会导致任务初始化失败。未配置或关闭此选项的旧配置保持原行为。
手部 Tag 位于相机背板左端(右 J7 的 `+X` 一侧),中心为 `(0.0345, -0.0946, 0.036) m`,
正面朝右 J7 的 `+Y`,背面距背板 0.1 mm,并向外侧避开中央支架。
屏幕和手部 Tag 的黑框外缘边长均为 16 mm,整张含白边为 20 mm;
@ -81,19 +98,25 @@ Tag 位于机器人正面看向屏幕时的右上角,含白边距上边、右
旋转 `Rx(pi/2)`,与当前模型一致。
`hand_orientation_G` 使用实际检测到的 Tag 坐标系:屏幕纹理使检测 G 相对其 MJCF body
绕 Z 旋转 180°,而检测 H 与手部 Tag body 同向。因此目标 `(rx, ry, rz)=(0, 0, pi)`
对应物理手部正立、TCP +Z 向上;不能仅按 body 坐标将 rz 改成 0。
对应物理手部正立、TCP +Z 沿屏幕向上;不能仅按 body 坐标将 rz 改成 0。
触屏测试前,先将右臂 MoveJ 到新配置 `initialization.joint_positions` 给出的初始位,再获取
`mujoco_hand_cam` 的 RGB 图像并点击屏幕上的目标。`u/v` 使用原始图像的 1280 × 720 像素坐标;
上位机 RGB Image 页面会按原图尺寸换算点击坐标。不要使用外部相机或编码视频的像素直接调用 touch。
每次 touch 请求还会用 MoveJ 确认初始位,点击后不要手动改变机械臂姿态。
右臂初始角按 J1~J7 顺序为 `[1.8647731978, 0.9322349780, -0.3888895185, 1.7262026729,
-1.3492569035, -0.2361915889, -0.93]` rad;MoveJ 使用速度 `0.5 rad/s`、加速度 `1.0 rad/s²`。
头部三关节保持零位。该姿态下可先选手相机原始图约 `(u=750, v=635)` 的屏幕区域做小范围测试,
不要直接把右上角 Tag 中心作为第一个触碰目标。初姿、这个点击点对应的 5 cm 预对齐目标及
再前进 2 cm 的位置已做离线运动学检查;这不等同于完成整条视觉伺服流程的动态验证。
零位到初姿的 21 个关节插值样本未出现新增接触对,但当前模型仍有肩、颈及腕部内部接触,
初姿右腕碰撞几何穿透约 18.9 mm,因此该初姿不作为无碰撞路径验证结果。
右臂初始角按 J1~J7 顺序为 `[1.8648861126, 0.8084619160, -0.4141750858, 1.6622227972,
-1.3312572926, -0.2423592867, -1.0088169947]` rad;MoveJ 使用速度 `0.5 rad/s`、加速度 `1.0 rad/s²`。
TCP 约 `(0.52237, -0.23207, 0.42622) m`,距屏幕正面约 86.95 mm。
以下头相机静态识别及像素数据在颈部零位时测得;当前头部采用上述非零初始角,以实际画面为准。
新起姿经项目实际 AprilTag 检测器确认:手相机识别 ID 1,头相机同时识别 ID 0 和 ID 1。
手相机中屏幕 Tag 中心约 `(1076, 488)`,头相机中屏幕/手部 Tag 中心分别约
`(2277, 576)` / `(2058, 735)`。这是静态渲染检查,不保证整个运动过程始终可见。
手相机原始图约 `(u=953, v=592)` 的位置为可见屏幕区域,对应屏幕局部
`(x=-0.08, y=0.015, z=0.045) m`;不要直接把右上角 Tag 中心作为第一个触碰目标。
此参考点仅做静态投影检查;左右偏转改为 0° 后,点击运动的 IK、整条路径避碰及
完整视觉伺服流程尚未重新验证。
当前模型仍有肩、颈及腕部内部接触,新初姿右腕碰撞几何穿透约 20.3 mm,
因此该初姿不作为无碰撞路径验证结果。
小赵尚未配置 MoveP 避障规划,因此此配置关闭 MoveP 预接近及完成/失败后的自动回初始位,
直接从初始位进行 PBVS 视觉对齐。更换测试点前需手动回初始位并重新取图。
@ -118,6 +141,7 @@ cp cmvr-es/config/manager/task_manager.pb.txt output/bin/config/manager/
cp cmvr-es/config/devices/mujoco/xiaozhao_world.pb.txt output/bin/config/devices/mujoco/
cp cmvr-es/config/devices/motor/xiaozhao_motors.pb.txt output/bin/config/devices/motor/
cp cmvr-es/config/devices/arm/xiaozhao_arm.pb.txt output/bin/config/devices/arm/
cp cmvr-es/config/devices/arm/xiaozhao_head.pb.txt output/bin/config/devices/arm/
cp cmvr-es/config/devices/camera/xiaozhao_camera.pb.txt output/bin/config/devices/camera/
cp cmvr-es/config/tasks/touch_screen_task/touch_screen_task_xiaozhao_mujoco.pb.txt output/bin/config/tasks/touch_screen_task/
cp -a model/xiaozhao output/bin/model/

View File

@ -1,9 +1,16 @@
<mujoco model="xiaozhao_touch_scene">
<!-- Fixed touch-test equipment, adapted from right_arm_eye_to_hand.xml.
Units: metres/radians; base_link = world. Robot front is world +X.
Screen: 500 x 300 mm, front normal -X, glass front at x = +0.585 m.
Move touch_screen here; the external camera is attached to the head
through head_camera.xml and generate_mujoco_xml.py. -->
<!-- Fixed cockpit screen, referencing the DEEPAL S05 15.4-inch Sunflower version.
Units: metres/radians; base_link = world = driver H-point reference.
+X forward, +Y left, +Z up; left-hand-drive layout.
Official reference: 15.4-inch diagonal, up to 15 deg driver/passenger swivel.
https://www.changaneurope.com/uk/models/changan-deepal-s05-bev
Simulation estimates (not measured S05 dimensions): 16:10 glass aspect,
glass center (0.60, -0.25, 0.38) m, 15 deg rearward recline.
Glass size: 331.703 x 207.314 mm; left/right swivel set to 0 deg.
Local +Y is the front normal, +Z is up, -X is the viewer's right.
Rotation: Ry(15 deg) * Rz(90 deg).
Body position compensates the local glass front offset (0, 0.015, 0).
The head camera remains attached through head_camera.xml. -->
<asset>
<texture name="screen_apriltag_tex" type="2d"
file="../../april_tag/tag36_11_00001.png"/>
@ -16,29 +23,28 @@
specular="0.2" shininess="0.3"/>
</asset>
<worldbody>
<body name="touch_screen" pos="0.60 0 0.38" quat="0.7071067811865476 0 0 0.7071067811865476">
<geom name="screen_frame" type="box" size="0.265 0.012 0.165"
<body name="touch_screen" pos="0.614488887394 -0.25 0.376117714323"
quat="0.701057384650 0.092295955641 0.092295955641 0.701057384650">
<geom name="screen_frame" type="box" size="0.173851508297 0.012 0.111657192686"
material="screen_frame_material" contype="1" conaffinity="1"/>
<geom name="screen_surface" type="box" pos="0 0.013 0"
size="0.25 0.002 0.15" material="screen_material"
size="0.165851508297 0.002 0.103657192686" material="screen_material"
contype="1" conaffinity="1" friction="0.5 0.005 0.0001"/>
<site name="screen_center" pos="0 0.015 0" size="0.0025" rgba="1 0 0 1"/>
<site name="screen_top_left" pos="-0.25 0.015 0.15" size="0.002" rgba="1 1 0 1"/>
<site name="screen_top_right" pos="0.25 0.015 0.15" size="0.002" rgba="1 1 0 1"/>
<site name="screen_bottom_left" pos="-0.25 0.015 -0.15" size="0.002" rgba="1 1 0 1"/>
<site name="screen_bottom_right" pos="0.25 0.015 -0.15" size="0.002" rgba="1 1 0 1"/>
<site name="screen_top_left" pos="0.165851508297 0.015 0.103657192686" size="0.002" rgba="1 1 0 1"/>
<site name="screen_top_right" pos="-0.165851508297 0.015 0.103657192686" size="0.002" rgba="1 1 0 1"/>
<site name="screen_bottom_left" pos="0.165851508297 0.015 -0.103657192686" size="0.002" rgba="1 1 0 1"/>
<site name="screen_bottom_right" pos="-0.165851508297 0.015 -0.103657192686" size="0.002" rgba="1 1 0 1"/>
<!-- ID 1: 20 mm texture including quiet zone, 16 mm black tag region.
Top-right as viewed by the robot: local -X, +Z; 18.75 mm edge margins.
Entire tag stays inside the glass, offset 0.2 mm from its face. -->
<body name="SCREEN_APRILTAG" pos="-0.22125 0.0151 0.12125" quat="0.7071067811865476 -0.7071067811865476 0 0">
<body name="SCREEN_APRILTAG" pos="-0.137101508297 0.0151 0.074907192686" quat="0.7071067811865476 -0.7071067811865476 0 0">
<geom name="SCREEN_APRILTAG_GEOM" type="box" size="0.01 0.01 0.0001"
material="screen_apriltag_mat" contype="0" conaffinity="0" mass="0" group="2"/>
<site name="SCREEN_APRILTAG_SITE" size="0.002" rgba="0 1 0 0"/>
</body>
<!-- A fixed visual stand reaches the floor at z = -0.183 m. -->
<geom name="screen_stand" type="box" pos="0 -0.02 -0.36" size="0.025 0.025 0.19"
material="screen_frame_material" contype="0" conaffinity="0"/>
<geom name="screen_stand_foot" type="box" pos="0 -0.02 -0.553" size="0.18 0.12 0.01"
<!-- Simplified fixed rear mount; not a measured dashboard or collision model. -->
<geom name="screen_mount" type="box" pos="0 -0.05 -0.07" size="0.03 0.038 0.025"
material="screen_frame_material" contype="0" conaffinity="0"/>
</body>
</worldbody>

View File

@ -19,6 +19,17 @@ message TouchScreenTaskDevicesConfig {
optional string arm_id = 4;
optional string external_camera_id = 5;
optional string touch_id = 6;
// Joint-controlled head/neck, exposed through the RobotArm interface.
optional string head_id = 7;
}
message TouchScreenTaskHeadInitializationConfig {
// Move the head once during task init(), before the task becomes ready.
// Unset/false preserves startup behavior for configurations without a head.
optional bool enable = 1;
repeated TouchScreenInitJointPoint joint_positions = 2;
optional double velocity = 3; // rad/s
optional double acceleration = 4; // rad/s^2
}
message TouchScreenTaskInitializationConfig {
@ -172,6 +183,7 @@ message TouchScreenTaskConfig {
// G/H 坐标轴长度,单位为米。
optional double debug_coordinate_axis_length_m = 9;
TouchScreenTaskApproachConfig approach = 10;
TouchScreenTaskHeadInitializationConfig head_initialization = 11;
}
message TouchScreenTaskRootConfig {