末端执行器(夹爪)
fd_api 末端执行器(手部)说明
天链机器人外设 · 夹爪 / 灵巧手控制与状态接口(C++)
RoHand + Inspire 双后端 · 2 控制接口 + 2 状态接口一、概述
末端执行器(End Effector)在手册中对应「手部」(hand)模块,即安装在机械臂末端、用于执行实际操作的夹爪或灵巧手。它是机器人与外界交互的最后执行环节,接口简洁:2 个控制接口 + 2 个状态接口。
与机械臂(多关节、双运动空间)不同,手部只需表达「开度或关节角度」这一个核心概念。真正需要理解的是它支持两种硬件后端——傲意 RoHand(灵巧手)与因时 Inspire(夹爪),二者的入参语义完全不同(详见第六章)。
上层应用
#include "fd_api/control.h" / "fd_api/state.h"
▼
#include "fd_api/control.h" / "fd_api/state.h"
fd_robot::Control / fd_robot::State
hand_move(移动) · hand_stop(停止) · 位置读/订阅
▼
hand_move(移动) · hand_stop(停止) · 位置读/订阅
ROS 2 通信层
发布手部关节/开度命令 · 订阅手部状态
▼
发布手部关节/开度命令 · 订阅手部状态
末端执行器硬件
傲意 RoHand(6 路关节) · 因时 Inspire(夹爪开度)
傲意 RoHand(6 路关节) · 因时 Inspire(夹爪开度)
核心特性
双后端兼容
RoHand + Inspire 一套接口
RoHand + Inspire 一套接口
左右手区分
HandType 三值枚举
HandType 三值枚举
重载设计
带/不带 type 两种调用
带/不带 type 两种调用
同步 + 订阅
读开度与实时回调
读开度与实时回调
二、类型与标识
2.1 枚举类型
| 类型 | 枚举 | 值 | 说明 |
|---|---|---|---|
| HandType | kLeft | 0 | 左手 |
| kRight | 1 | 右手 | |
| kBoth | 2 | 双手 | |
| HandBackend | kRohand | 0 | 傲意 RoHand,6 路关节值 |
| kInspire | 1 | 因时 Inspire,取首个整型开度值 | |
| kBoth | 2 | 同时驱动 RoHand 与 Inspire |
2.2 相关外设标识(PeripheralId)
| 枚举 | 值 | 说明 |
|---|---|---|
| kCameraLeftHand | 14 | 左手相机 |
| kCameraRightHand | 15 | 右手相机 |
| kForceSensorLeftHand | 19 | 左手力传感器 |
| kForceSensorRightHand | 20 | 右手力传感器 |
2.3 关键配置项(Control::Options)
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
| hand_backend | HandBackend | kInspire | 手部驱动后端 |
| hand_type | HandType | kBoth | 默认控制哪只手 |
| inspire_gripper_id | int32 | 1 | 因时夹爪 ID |
默认值要点:后端默认
kInspire(因时夹爪),手型默认 kBoth(双手)。因此「无参 / 无 type 重载」的调用,实际上落在 Inspire 后端 + 双手语义上。三、接口总览
| 分类 | 接口 | C++ 签名 | 返回值 |
|---|---|---|---|
| 控制 | hand_move | bool hand_move(const std::vector<float>& value) bool hand_move(HandType type, const std::vector<float>& value) |
命令已下发 |
| 控制 | hand_stop | bool hand_stop() bool hand_stop(HandType type) |
命令已下发 |
| 状态 | hand_get_current_pos | bool hand_get_current_pos(HandType type, std::vector<float>& value) const | 是否有有效数据 |
| 状态 | hand_sub_current_pos | SubscriptionId hand_sub_current_pos(HandType type, HandPosCallback cb) | 订阅 ID;0 失败 |
四、控制接口
命名空间 fd_robot::Control。两个控制接口均提供带 type 与不带 type 两种重载:不带 type 的重载使用 Init() 时配置的默认 HandType 与 HandBackend。
4.1 hand_move — 手部移动
bool hand_move(const std::vector<float>& value);bool hand_move(HandType type, const std::vector<float>& value);控制夹爪 / 灵巧手的开度或关节。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| type | HandType | Options.hand_type | kLeft / kRight / kBoth |
| value | float[] | - | RoHand:6 个 float 关节值;Inspire:取首个整型开度 |
value 语义随后端而变:
HandBackend::kRohand 下 value 是 6 个 float 关节值;kInspire 下只取首个整型开度值。传错长度或语义会导致动作异常。4.2 hand_stop — 手部停止
bool hand_stop();bool hand_stop(HandType type);停止手部运动。无参重载使用默认手型。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| type | HandType | Options.hand_type | 指定停止哪只手 |
五、状态接口
命名空间 fd_robot::State。同步读返回 bool 表示「是否有有效数据」,订阅返回 SubscriptionId(uint64_t),0 表示失败,用 unsubscribe(id) 取消。
5.1 hand_get_current_pos — 获取手部位置/开度
bool hand_get_current_pos(HandType type, std::vector<float>& value) const;同步读取关节或开度数组。
| 参数 | 类型 | 说明 |
|---|---|---|
| type | HandType | kLeft / kRight(一般不用 kBoth) |
| value | float[]& | 关节或开度(C++ 出参) |
一般不用 kBoth:同步读时
type 通常指定 kLeft 或 kRight,避免双手语义歧义。5.2 hand_sub_current_pos — 订阅手部位置
SubscriptionId hand_sub_current_pos(HandType type, HandPosCallback cb);
// cb: void(HandType, const std::vector<float>&)
| 参数 | 类型 | 说明 |
|---|---|---|
| type | HandType | 订阅哪只手 |
| cb | HandPosCallback | 手部位置回调 |
回调带手型标识:回调签名为
void(HandType, const std::vector<float>&),第一个参数即触发该回调的手,便于在同一个回调中区分左右手。六、两种后端对比
| 维度 | 傲意 RoHand(kRohand) | 因时 Inspire(kInspire) |
|---|---|---|
| 设备形态 | 灵巧手(多自由度) | 夹爪(单开度) |
| hand_move 入参 | 6 个 float 关节值 | 取首个整型开度值 |
| 值含义 | 各关节角度 | 开度大小 |
| 相关配置 | — | inspire_gripper_id(默认 1) |
| 适用场景 | 精细抓取、多指操作 | 简单夹持、开合动作 |
此外 HandBackend::kBoth 表示同时驱动 RoHand 与 Inspire 两种设备。
七、使用示例
完整 C++ 示例:初始化(指定 Inspire 后端 + 双手)→ 移动 → 同步读 → 订阅 → 停止。
#include "fd_api/control.h"
#include "fd_api/state.h"
#include <iostream>
#include <vector>
int main() {
// 1. 初始化:指定后端与默认手型
fd_robot::Control ctrl;
if (!ctrl.Init()) {
std::cerr << "Control Init failed" << std::endl;
return 1;
}
fd_robot::State state;
if (!state.Init()) {
std::cerr << "State Init failed" << std::endl;
return 1;
}
// 2. Inspire 夹爪:取首个整型开度值(单元素即可)
std::vector<float> open = {100.0f}; // 开
ctrl.hand_move(fd_robot::HandType::kRight, open);
// 3. RoHand 灵巧手:需 6 个关节值(此时需后端为 kRohand)
std::vector<float> joints = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
// ctrl.hand_move(fd_robot::HandType::kLeft, joints);
// 4. 同步读取右手开度
std::vector<float> val;
if (state.hand_get_current_pos(fd_robot::HandType::kRight, val)) {
std::cout << "opening = " << val[0] << std::endl;
}
// 5. 订阅左手位置(回调带 HandType 标识)
auto sid = state.hand_sub_current_pos(
fd_robot::HandType::kLeft,
[](fd_robot::HandType t, const std::vector<float>& v) {
// 处理手部位置/开度
});
// 6. 停止 + 取消订阅
ctrl.hand_stop(fd_robot::HandType::kRight);
state.unsubscribe(sid);
return 0;
}
八、注意事项
入参语义必须匹配后端:
hand_move 的 value 在 kRohand 下是 6 个关节值,在 kInspire 下取首个整型开度值。后端配置与实际设备不符会导致动作错误。默认后端为 Inspire:
Options::hand_backend 默认 kInspire,若使用 RoHand 灵巧手需显式改配置。无 type 重载用默认手型:
hand_move(value) / hand_stop() 使用 Options::hand_type(默认 kBoth)与 hand_backend 配置。同步读一般不用 kBoth:
hand_get_current_pos 的 type 通常用 kLeft / kRight,避免双手语义歧义。回调带手型标识:订阅回调
void(HandType, const std::vector<float>&),可在同一回调内区分左右手。末端执行器 vs 机械臂:本模块只管「手部开度/关节」,不涉及机械臂本体的关节运动、笛卡尔运动或位姿——那些属于机械臂(arm)接口。
