外观
ROS 2
发行版是 Ubuntu 22.04 与 ROS 2 Humble。每个新终端先回到 W6E/,再执行:
bash
source /opt/ros/humble/setup.bash
source ros2/install/setup.bash开 ROS 前如果提示符里有 (.venv),先 deactivate。不要和 SDK 面板或网页控制同时占用 CANable。
安装依赖并编译
先按官方方式装好 ROS 2 Humble,然后:
bash
sudo apt-get install -y \
ros-humble-ros2-control \
ros-humble-ros2-controllers \
ros-humble-joint-state-broadcaster \
ros-humble-forward-command-controller \
ros-humble-controller-manager \
ros-humble-rviz2 \
ros-humble-xacro \
ros-humble-joint-state-publisher \
ros-humble-joint-state-publisher-gui \
ros-humble-robot-state-publisher \
ros-humble-moveit
deactivate 2>/dev/null || true
source /opt/ros/humble/setup.bash
cd ros2
colcon build --symlink-install
source install/setup.bash| 包 | 作用 |
|---|---|
w6e_hand_description | 当前左右手在 urdf/both/ |
w6e_hand_moveit_config | 规划组 hand。左手 demo_left,右手 demo_right |
w6e_hand_hardware | C++ ros2_control |
w6e_driver_py | Python 驱动,接口与 C++ 对齐 |
w6e_hand_bringup | hand.launch.py、python_driver.launch.py。仍是旧右手模型 |
w6e_hand_interfaces | 开合度、手势和状态的消息与服务 |
当前左右手用 demo_left / demo_right。hand.launch.py 仍加载旧右手,不要拿它当现在的左右手模型。
只看模型
先关掉正在跑的 MoveIt。窗口里拖关节只动 RViz,真机不动。
bash
ros2 launch w6e_hand_description view_model.launch.py hand:=right
ros2 launch w6e_hand_description view_model.launch.py hand:=left不写 hand 时默认右手。
MoveIt
一次只开下面一条。不写 transport 是模拟,手指不会动。带 slcan 才连接真手。
bash
ros2 launch w6e_hand_moveit_config demo_left.launch.py
ros2 launch w6e_hand_moveit_config demo_left.launch.py \
transport:=slcan serial_port:=/dev/ttyACM0
ros2 launch w6e_hand_moveit_config demo_right.launch.py
ros2 launch w6e_hand_moveit_config demo_right.launch.py \
transport:=slcan serial_port:=/dev/ttyACM0can0 已经挂好时,把传输换成 transport:=socketcan can_interface:=can0。
启动后打开 RViz。在 MotionPlanning → Joints 里拖动某一路,橙色是目标,松手停在松开的位置。Planning Group 选 hand,点 Plan,再点 Execute,真机才按编码器走到这个开合度。灰色是真机当前姿态。Goal State 里的 open、half、close 是三个现成姿势。没有逆解,不要拖手上的交互标记。
只发开合度
这个终端留着不要关。它使用旧右手模型:
bash
ros2 launch w6e_hand_bringup hand.launch.py \
transport:=slcan serial_port:=/dev/ttyACM0 use_rviz:=false另开一个终端,同样 source 两次:
bash
ros2 topic pub --once /w6e_hand/open_pct_cmd \
std_msgs/msg/Float32MultiArray "{data: [0,0,0,0,0,0]}"Python 驱动把 hand.launch.py 换成 python_driver.launch.py,并带上 sdk_path:=sdk/python。两套驱动不要一起开。
话题与服务
/w6e_hand/open_pct_cmd 的类型是 std_msgs/msg/Float32MultiArray,长度 6,顺序与 SDK 相同。0 是全合,100 是全开。负数表示该指保持。
| 名称 | 类型 | 说明 |
|---|---|---|
/w6e_hand/open_pct_cmd | Float32MultiArray | 下发开合度 |
/w6e_hand/open_pct | Float32MultiArray | 读回开合度 |
/joint_states | JointState | 模型关节角度 |
/w6e_hand/open_all、/close_all、/stop | std_srvs/Trigger | 开、合不含虎口 |
/w6e_hand/play_gesture | PlayGesture | name 或 fixed_id |
bash
ros2 service call /w6e_hand/play_gesture \
w6e_hand_interfaces/srv/PlayGesture "{name: 'ok', fixed_id: -1}"左右手角度
Joints 表显示的是角度,从 0° 起,不是开合度百分比。开合度仍是 0 全合、100 全开,由映射文件换算后发给板子。
左手虎口:0° 是合拢,约 92°(1.6 rad)是张开。右手虎口相反:0° 是张开,约 92° 是对掌。
| LQ | 手指 | 左手关节 | 右手关节 |
|---|---|---|---|
| 0 | 拇 | damu4 | damu4 |
| 1 | 虎口 | damu2 | damu2 |
| 2 | 食 | shizhi2 | shizhi2 |
| 3 | 中 | zhongzhi2 | zhongzhi2 |
| 4 | 无名 | wuming2 | wumingzhi2 |
| 5 | 小 | xiaomu2 | xiaozhi2 |
左手映射是 ros2/w6e_hand_description/config/joint_map_both_left.yaml,右手是 joint_map_both_right.yaml。
