Skip to content

Commit 5d3d8c5

Browse files
committed
1 parent 47c115e commit 5d3d8c5

18 files changed

Lines changed: 3759 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
install
3+
log

README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# LinkerHand-CPP-ROS2
2+
3+
## 概述
4+
LinkerHand-CPP-ROS2 是灵心巧手科技有限公司开发,基于 LinkerHand-CPP-SDK 的ROS2封装版本。
5+
6+
#### 环境安装
7+
[LinkerHand-CPP-SDK](../README.md)
8+
9+
#### 工程编译
10+
cd linker_hand_cpp_sdk/ros2/
11+
colcon build
12+
13+
#### 配置XML文件
14+
15+
```bash
16+
<?xml version="1.0" encoding="utf-8"?>
17+
<launch>
18+
<!-- 参数声明 -->
19+
<arg name="VERSION" default="1.1.6" description="版本号"/>
20+
21+
<!-- 左手配置 -->
22+
<arg name="LEFT_HAND_EXISTS" default="true" description="是否存在左手"/>
23+
<arg name="LEFT_TOUCH" default="true" description="是否有压力传感器"/>
24+
<arg name="LEFT_JOINTS" default="L10" description="左手型号 L7 \ L10 \ L20 \ L21 \ L25"/>
25+
<arg name="LEFT_CANBUS" default="can0" description="can0 \ can1"/>
26+
27+
<!-- 右手配置 -->
28+
<arg name="RIGHT_HAND_EXISTS" default="false" description="是否存在右手"/>
29+
<arg name="RIGHT_TOUCH" default="false" description="是否有压力传感器"/>
30+
<arg name="RIGHT_JOINTS" default="L10" description="右手型号 L7 \ L10 \ L20 \ L21 \ L25"/>
31+
<arg name="RIGHT_CANBUS" default="can0" description="can0 \ can1"/>
32+
33+
<!-- 通用配置 -->
34+
<arg name="HAND_SPEED" default="100" description="关节速度 0 ~ 255"/>
35+
<arg name="HAND_EFFORT" default="200" description="关节扭矩 0 ~ 255"/>
36+
37+
......
38+
39+
</launch>
40+
```
41+
42+
#### 运行
43+
source install/setup.bash
44+
ros2 launch linker_hand_cpp_ros2 run.xml
45+
46+
47+
#### 话题
48+
49+
| 话题名称 | I/O | 消息类型 | 描述 |
50+
| :--- | :--- | :--- | :--- |
51+
| /left_hand_control | Input | sensor_msgs/msg/JointState | 左手控制指令 |
52+
| /left_hand_settings | Input | sensor_msgs/msg/String | 左手设置指令 |
53+
| /left_hand_touch | Output | std_msgs/msg/Float32MultiArray | 左手触觉传感器数据 |
54+
| /left_hand_state | Output | sensor_msgs/msg/JointState | 左手关节状态 |
55+
| /left_hand_info | Output | std_msgs/msg/String | 左手基本信息 |
56+
| /right_hand_control | Input | sensor_msgs/msg/JointState | 左手控制指令 |
57+
| /right_hand_settings | Input | sensor_msgs/msg/String | 右手设置指令 |
58+
| /right_hand_touch | Output | std_msgs/msg/Float32MultiArray | 左手触觉传感器数据 |
59+
| /right_hand_state | Output | sensor_msgs/msg/JointState | 左手关节状态 |
60+
| /right_hand_info | Output | std_msgs/msg/String | 左手基本信息 |
61+
62+
63+
针对以上话题的具体字段及其详细描述如下表所示:
64+
65+
66+
- 控制关节话题 /left_hand_control
67+
68+
```bash
69+
$ ros2 topic echo /left_hand_control
70+
71+
header:
72+
seq: 256
73+
stamp:
74+
secs: 1744343699
75+
nsecs: 232647418
76+
frame_id: ''
77+
name: []
78+
position: [155.0, 162.0, 176.0, 125.0, 255.0, 255.0, 180.0, 179.0, 181.0, 68.0]
79+
velocity: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
80+
effort: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
81+
```
82+
- position与手指关节对照表
83+
84+
```bash
85+
L7: ["大拇指弯曲", "大拇指横摆","食指弯曲", "中指弯曲", "无名指弯曲","小拇指弯曲","拇指旋转"]
86+
87+
L10: ["拇指根部", "拇指侧摆","食指根部", "中指根部", "无名指根部","小指根部","食指侧摆","无名指侧摆","小指侧摆","拇指旋转"]
88+
89+
L20: ["拇指根部", "食指根部", "中指根部", "无名指根部","小指根部","拇指侧摆","食指侧摆","中指侧摆","无名指侧摆","小指侧摆","拇指横摆","预留","预留","预留","预留","拇指尖部","食指末端","中指末端","无名指末端","小指末端"]
90+
91+
L21: ["大拇指根部", "食指根部", "中指根部","无名指根部","小拇指根部","大拇指侧摆","食指侧摆","中指侧摆","无名指侧摆","小拇指侧摆","大拇指横滚","预留","预留","预留","预留","大拇指中部","预留","预留","预留","预留","大拇指指尖","食指指尖","中指指尖","无名指指尖","小拇指指尖"]
92+
93+
L25: ["大拇指根部", "食指根部", "中指根部","无名指根部","小拇指根部","大拇指侧摆","食指侧摆","中指侧摆","无名指侧摆","小拇指侧摆","大拇指横滚","预留","预留","预留","预留","大拇指中部","食指中部","中指中部","无名指中部","小拇指中部","大拇指指尖","食指指尖","中指指尖","无名指指尖","小拇指指尖"]
94+
```
95+
96+
97+
---
98+
99+
100+
- 设置指令话题 /left_hand_settings
101+
102+
```bash
103+
# 清除故障码
104+
$ ros2 topic pub /left_hand_setting std_msgs/msg/String "data: '{\"setting_cmd\": \"clear_faults\"}'"
105+
106+
# 设置电流
107+
$ ros2 topic pub /left_hand_setting std_msgs/msg/String "data: '{\"setting_cmd\": \"set_electric_current\", \"params\": {\"electric_current\": 50}}'"
108+
109+
# 使能
110+
$ ros2 topic pub /left_hand_setting std_msgs/msg/String "data: '{\"setting_cmd\": \"enable\"}'"
111+
112+
# 失能
113+
$ ros2 topic pub /left_hand_setting std_msgs/msg/String "data: '{\"setting_cmd\": \"disable\"}'"
114+
115+
```
116+
117+
118+
---
119+
- 关节反馈话题 /left_hand_state
120+
121+
```bash
122+
$ ros2 topic echo /left_hand_state
123+
124+
header:
125+
seq: 256
126+
stamp:
127+
secs: 1744343699
128+
nsecs: 232647418
129+
frame_id: ''
130+
name: []
131+
position: [155.0, 162.0, 176.0, 125.0, 255.0, 255.0, 180.0, 179.0, 181.0, 68.0]
132+
velocity: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
133+
effort: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
134+
```
135+
136+
---
137+
138+
- 左手基本信息 /left_hand_info
139+
140+
```bash
141+
$ ros2 topic echo /left_hand_info
142+
143+
data: 'Hand direction: Left hand
144+
145+
Software Version: 7.0.0.0
146+
147+
Hardware Version: 2.0.19.0
148+
149+
Temperature: 47 49 40 41 0 39 0 46 42 0 0 39 0 49...'
150+
```
151+
- 压感数据 /left_hand_touch
152+
153+
注意:反馈数据为一个一维数组,长度为360,由每个手指的压感数据组成。单个指头压感数据长度是72(6*12矩阵),每个手指压感数据需要单独拆分。(仅适用点阵式传感器)
154+
155+
```bash
156+
$ ros2 topic echo /left_hand_touch
157+
layout:
158+
dim: []
159+
data_offset: 0
160+
data:
161+
- 0.0
162+
- 0.0
163+
- 0.0
164+
- 0.0
165+
- 0.0
166+
- '...'
167+
```
168+
169+
## 示例
170+
171+
| 序号 | 文件名称 | 描述 |
172+
| :--- | :-------- | :--------------------------------------------- |
173+
| 1 | examples/src/action_group_show_l7 | L7型号手指舞示例 |
174+
| 2 | examples/src/action_group_show_l10 | L10型号手指舞示例 |
175+
| 3 | examples/src/action_group_show_l20 | L20型号手指舞示例 |
176+
| 4 | examples/src/loop_l20 | L20型号手势张开握拳示例 |
177+
| 5 | examples/src/show_ok_l20 | L20型号手势ok示例 |
178+
| 6 | examples/src/show_surround_index_finger_l20 | L20型号单指手势示例 |
179+
| 7 | examples/src/show_wave_l20 | L20型号wave手势示例 |
180+
| 8 | examples/src/action_group_show_l25 | L25型号手指舞示例 |
181+
| 9 | examples/src/loop_l25 | L25型号手势张开握拳示例 |

src/examples/CMakeLists.txt

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(examples)
3+
4+
# Default to C99
5+
if(NOT CMAKE_C_STANDARD)
6+
set(CMAKE_C_STANDARD 99)
7+
endif()
8+
9+
# Default to C++14
10+
if(NOT CMAKE_CXX_STANDARD)
11+
set(CMAKE_CXX_STANDARD 14)
12+
endif()
13+
14+
# Enable additional compiler warnings
15+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
16+
add_compile_options(-Wall -Wextra -Wpedantic)
17+
endif()
18+
19+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
20+
set(LIB_SUBDIR "x86_64")
21+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
22+
set(LIB_SUBDIR "aarch64")
23+
else()
24+
message(WARNING "Unknown architecture, defaulting to x86_64")
25+
set(LIB_SUBDIR "x86_64")
26+
endif()
27+
28+
# Find dependencies
29+
find_package(ament_cmake REQUIRED)
30+
find_package(rclcpp REQUIRED)
31+
find_package(std_msgs REQUIRED)
32+
find_package(sensor_msgs REQUIRED)
33+
34+
# Define common include directories
35+
set(COMMON_INCLUDE_DIRS
36+
/usr/local/linker_hand_cpp_sdk/include
37+
/usr/local/linker_hand_cpp_sdk/third_party/Robotic_Arm/include
38+
include
39+
)
40+
41+
#-----------------------------------------------------------------------------
42+
# LINKER_HAND_CPP_SDK
43+
#-----------------------------------------------------------------------------
44+
find_library(LINKER_HAND_LIB
45+
NAMES linkerhand_cpp_sdk linkerhand_cpp
46+
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/${LIB_SUBDIR}
47+
/usr/local/lib/linkerhand-cpp-sdk/${LIB_SUBDIR}
48+
/usr/lib/linkerhand-cpp-sdk/${LIB_SUBDIR}
49+
${CMAKE_INSTALL_PREFIX}/lib/linkerhand-cpp-sdk/${LIB_SUBDIR}
50+
NO_DEFAULT_PATH
51+
)
52+
53+
set(LINKER_HAND_INCLUDE_DIR
54+
${CMAKE_CURRENT_SOURCE_DIR}/include
55+
/usr/local/include/linkerhand-cpp-sdk
56+
/usr/include/linkerhand-cpp-sdk
57+
${CMAKE_INSTALL_PREFIX}/include/linkerhand-cpp-sdk
58+
)
59+
60+
if(NOT LINKER_HAND_LIB)
61+
message(FATAL_ERROR "linkerhand_cpp_sdk library not found!")
62+
endif()
63+
64+
if(NOT LINKER_HAND_INCLUDE_DIR)
65+
message(FATAL_ERROR "LinkerHand headers not found!")
66+
endif()
67+
68+
message(STATUS "Found linkerhand_cpp_sdk library: ${LINKER_HAND_LIB}")
69+
message(STATUS "Found LinkerHand headers: ${LINKER_HAND_INCLUDE_DIR}")
70+
71+
#-----------------------------------------------------------------------------
72+
# INCLUDE_DIRECTORIES
73+
#-----------------------------------------------------------------------------
74+
include_directories(
75+
${CMAKE_CURRENT_SOURCE_DIR}/include
76+
${LINKER_HAND_INCLUDE_DIR}
77+
)
78+
79+
# ----------------------------------------------------------------------
80+
81+
# Define common link libraries
82+
set(COMMON_LIBS ${LINKER_HAND_LIB} pthread)
83+
84+
# Define source files
85+
set(SOURCE_FILES
86+
action_group_show_l7
87+
action_group_show_l10
88+
action_group_show_l20
89+
action_group_show_l25
90+
loop_l20
91+
loop_l25
92+
show_surround_index_finger_l20
93+
show_ok_l20
94+
show_wave_l20
95+
)
96+
97+
# Create and name a shared library
98+
foreach(SOURCE_FILE ${SOURCE_FILES})
99+
add_executable(${SOURCE_FILE} src/${SOURCE_FILE}.cpp)
100+
target_include_directories(${SOURCE_FILE} PUBLIC
101+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
102+
$<INSTALL_INTERFACE:include>
103+
)
104+
ament_target_dependencies(${SOURCE_FILE}
105+
rclcpp
106+
std_msgs
107+
sensor_msgs
108+
)
109+
target_link_libraries(${SOURCE_FILE} ${COMMON_LIBS})
110+
install(TARGETS ${SOURCE_FILE}
111+
DESTINATION lib/${PROJECT_NAME}
112+
)
113+
endforeach()
114+
115+
# Install launch files
116+
# install(DIRECTORY launch
117+
# DESTINATION share/${PROJECT_NAME}/
118+
# )
119+
120+
# Install configuration files
121+
# install(DIRECTORY config
122+
# DESTINATION share/${PROJECT_NAME}/
123+
# )
124+
125+
# Install settings file
126+
# install(FILES config/setting.yaml
127+
# DESTINATION config
128+
# )
129+
130+
# If BUILD_TESTING is enabled, include test-related dependencies
131+
if(BUILD_TESTING)
132+
find_package(ament_lint_auto REQUIRED)
133+
ament_lint_auto_find_test_dependencies()
134+
endif()
135+
136+
# Package information
137+
ament_package()

src/examples/package.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>examples</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="liangshaoteng2012@163.com">lst</maintainer>
8+
<license>Apache2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<test_depend>ament_lint_auto</test_depend>
13+
<test_depend>ament_lint_common</test_depend>
14+
15+
<export>
16+
<build_type>ament_cmake</build_type>
17+
<depend>rclcpp</depend>
18+
<depend>std_msgs</depend>
19+
<depend>sensor_msgs</depend>
20+
</export>
21+
</package>

0 commit comments

Comments
 (0)