Skip to content

Commit 2212e24

Browse files
committed
更新L20示例,修改L20读取YAML动作文件错误
1 parent c97ee89 commit 2212e24

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#!/usr/bin/env python3
2+
import sys, os, time
3+
current_dir = os.path.dirname(os.path.abspath(__file__))
4+
target_dir = os.path.abspath(os.path.join(current_dir, "../../.."))
5+
sys.path.append(target_dir)
6+
from LinkerHand.linker_hand_api import LinkerHandApi
7+
8+
'''
9+
循环执行7个新的预设手部动作
10+
'''
11+
def main():
12+
hand = LinkerHandApi(hand_joint="L20", hand_type="left")
13+
#hand_r = LinkerHandApi(hand_joint="L10", hand_type="right")
14+
# 设置使能状态
15+
hand.set_enable()
16+
#hand_r.set_enable()
17+
time.sleep(0.1)
18+
# 设置速度
19+
hand.set_speed(speed=[240]*5)
20+
#hand_r.set_speed(speed=[240]*5)
21+
22+
# 定义7个新的预设动作
23+
24+
25+
26+
pose = [255, 128, 255, 255, 255, 255, 128, 128, 128, 128]
27+
#open_hand
28+
action1=[250, 250, 250, 250, 250, 250, 128, 128, 128, 128, 250, 0, 0, 0, 0, 250, 250, 250, 250, 250]
29+
#ring_little_shrink
30+
action2=[250,250,250, 0, 0, 250,128,128,128,128,250, 0, 0, 0, 0,250,250,250, 0, 0]#shrink stretch
31+
#show_yeah
32+
action3=[100,250,250, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
33+
action4=[100,250,250, 0, 0, 180,200,200,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
34+
action5=[100,250,250, 0, 0, 180, 50, 50,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
35+
action6=[100,250,250, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
36+
action7=[100,250,250, 0, 0, 180, 58,200,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
37+
action8=[100,250,250, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
38+
#action9=[190, 20, 0, 25, 40, 255, 255, 150, 150, 150, 100, 255, 255, 255, 255, 150, 255, 255, 255, 255, 255, 255, 255, 255, 255]
39+
poses = []
40+
41+
action9=[100,250,250, 0, 0, 180, 58,200,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
42+
#9): #// 收Y
43+
action10=[100,250,250, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
44+
#10): #// 中指和食指弯曲伸直交替两遍
45+
action11=[100,100,100, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,100,100, 0, 0]
46+
#11): #// 中指和食指弯曲伸直交替两遍
47+
action12=[100,250,250, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
48+
#12): #// 中指和食指弯曲伸直交替两遍
49+
action13=[100,100,100, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,100,100, 0, 0]
50+
#13): #// 中指和食指弯曲伸直交替两遍
51+
action14=[100,250,250, 0, 0, 180,128,128,128,128,200, 0, 0, 0, 0, 0,250,250, 0, 0]
52+
#14): #// 蜷曲拇指
53+
action15=[250,250,250, 0, 0, 150,128,128,128,128,250, 0, 0, 0, 0, 0,250,250, 0, 0]
54+
#15): #// 拇指收于掌内
55+
action16=[250,250,250, 0, 0, 5 ,128,128,128,128,250, 0, 0, 0, 0, 0,250,250, 0, 0]
56+
#16): #// 收4指
57+
action17=[250,100,100,100,100, 5 ,128,128,128,128,250, 0, 0, 0, 0, 0,10, 10, 10, 10]
58+
#17): #// 依次放开4指和拇指
59+
action18=[250,100,100,100,250, 5 ,128,128,128,128,250, 0, 0, 0, 0, 0,10, 10, 10, 250]
60+
#18): #// 1
61+
action19=[250,100,100,250,250, 5 ,128,128,128,128,250, 0, 0, 0, 0, 0,10, 10, 250, 250]
62+
#19): #// 2
63+
action20=[250,100,250,250,250, 5 ,128,128,128,128,250, 0, 0, 0, 0, 0,10, 250, 250, 250]
64+
#20): #// 3
65+
action21=[250,250,250,250,250, 5 ,128,128,128,128,250, 0, 0, 0, 0, 0,250, 250, 250, 250]
66+
#21): #// 4
67+
action22=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250,250, 250, 250, 250]
68+
#22): #// 并拢拇指
69+
action23=[250,250,250,250,250,250,128,128,128,128, 10, 0, 0, 0, 0, 250,250, 250, 250, 250]
70+
#23): #// 反转拇指指掌心
71+
action24=[ 0,250,250,250,250,250,128,128,128,128, 10, 0, 0, 0, 0, 250,250, 250, 250, 250]
72+
#24): #// 分两步回到初始位置
73+
action25=[ 0,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250,250, 250, 250, 250]
74+
#25): #// 1
75+
action26=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250,250, 250, 250, 250]
76+
#26): #// 2
77+
action27=[250,250,250,250,250,250,200,200,200,200,250, 0, 0, 0, 0, 250,250, 250, 250, 250]
78+
#27): #// 3
79+
action28=[250,250,250,250,250,250, 80, 80, 80, 80,250, 0, 0, 0, 0, 250,250, 250, 250, 250]
80+
#28): #// 4
81+
action29=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250,250, 250, 250, 250]
82+
#29): #// 依次蜷曲4小指
83+
action30=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 250, 250, 250]
84+
#30): #// 蜷曲4指
85+
action31=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 250, 250]
86+
#31): #// 4
87+
action32=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 250]
88+
#32): #// 4
89+
action33=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 0]
90+
#33): #// 依次蜷曲4小指
91+
action34=[250, 0,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 0]
92+
#34): #// 依次蜷曲4小指
93+
action35=[250, 0, 0,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 0]
94+
#35): #// 依次蜷曲4小指
95+
action36=[250, 0, 0, 0,250,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 0]
96+
#36): #// 依次蜷曲4小指
97+
action37=[250, 0, 0, 0, 0,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 0]
98+
#37): #// 蜷曲拇指
99+
action38=[ 0, 0, 0, 0, 0,250,128,128,128,128,250, 0, 0, 0, 0, 200, 0, 0, 0, 0]
100+
#38): #// 打开食指和小指
101+
action39=[250, 0, 0, 0, 0,250,128,128,128,128,250, 0, 0, 0, 0, 250, 0, 0, 0, 0]
102+
#39): #// 打开食指和小指
103+
action40=[250,250, 0, 0,250,250,128,128,128,128,250, 0, 0, 0, 0, 250,250, 0, 0,250]
104+
#40): #// 将拇指搭上666
105+
action41=[100,250, 0, 0,250,200,128,128,128,128,100, 0, 0, 0, 0,100,250, 0, 0,250]
106+
#41): #// 左右动手指
107+
action42=[100,250, 0, 0,250,200, 80,128,128,200,100, 0, 0, 0, 0,100,250, 0, 0,250]
108+
#42): #// 左右动手指
109+
action43=[100,250, 0, 0,250,200,200,128,128, 80,100, 0, 0, 0, 0,100,250, 0, 0,250]
110+
#43): #// 左右动手指
111+
action44=[100,250, 0, 0,250,200, 80,128,128,200,100, 0, 0, 0, 0,100,250, 0, 0,250]
112+
#44): #// 左右动手指
113+
action45=[100,250, 0, 0,250,200,200,128,128, 80,100, 0, 0, 0, 0,100,250, 0, 0,250]
114+
#45): #// 左右动手指
115+
action46=[100,250, 0, 0,250,200,128,128,128,128,100, 0, 0, 0, 0,100,250, 0, 0,250]
116+
#46): #// 展开
117+
action47=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0,250,250,250, 250,250]
118+
#47): #// 拇指和食指捏
119+
action48=[ 55, 0,250,250,250,170,128,128,128,128,70, 0, 0, 0, 0,250,250,250, 250,250]
120+
#48): #// 1
121+
action49=[250,250, 20,250,250,220,128,128,128,128,100, 0, 0, 0, 0,250,250,250, 250,250]
122+
#49): #// 拇指和中指捏
123+
action50=[ 55,250, 0,250,250,140,128,128,128,128,60, 0, 0, 0, 0,250,250,250, 250,250]
124+
#50): #// 1
125+
action51=[250,250,250, 20,250,170,128,128,128,128,100, 0, 0, 0, 0,250,250,250, 250,250]
126+
#51): #// 拇指和无名指捏
127+
action52=[ 55,250,250, 0 ,250,110,128,128,128,128,50, 0, 0, 0, 0,250,250,250, 250,250]
128+
#52): #// 1
129+
action53=[250,250,250,250, 20,130,128,128,128,128,100, 0, 0, 0, 0,250,250,250, 250,250]
130+
#53): #// 拇指和小指捏
131+
action54=[ 55,250,250,250, 0, 60,128,128,128,128,50, 0, 0, 0, 0,250,250,250, 250,250]
132+
#54): #// 1
133+
action55=[250,250,250,250, 20,130,128,128,128,128,100, 0, 0, 0, 0,250,250,250, 250,250]
134+
#55): #// 拇指和小指掐
135+
action56=[160,250,250,250,160, 60,128,128,128,128,50, 0, 0, 0, 0,100,250,250, 250, 80]
136+
#56): #// 1
137+
action57=[250,250,250,250,250,130,128,128,128,128,100, 0, 0, 0, 0,250,250,250, 50, 250]
138+
#57): #// 拇指和无名指掐
139+
action58=[160,250,250,150,250,100,128,128,128,128,50, 0, 0, 0, 0,100,250,250, 80, 250]
140+
#58): #// 1
141+
action59=[250,250,250,250,250,180,128,128,128,128,100, 0, 0, 0, 0, 250,250, 50, 250, 250]
142+
#59): #// 拇指和中指掐
143+
action60=[160,250,150,250,250,135,128,128,128,128,70, 0, 0, 0, 0,100,250,85, 250, 250]
144+
#60): #// 1
145+
action61=[250,250,250,250,250,220,128,128,128,128,100, 0, 0, 0, 0, 250, 50,250, 250, 250]
146+
#61): #// 拇指和食指掐
147+
action62=[165,150,250,250,250,170,128,128,128,128,70, 0, 0, 0, 0,100,80,250, 250, 250]
148+
#62): #// 1
149+
action63=[250,250,250,250,250,250,128,128,128,128,250, 0, 0, 0, 0, 250,250,250, 250, 250]
150+
151+
# 新增:将action1到action63填充到action_group数组中
152+
action_group = [
153+
action1, action2, action3, action4, action5, action6, action7, action8, action9, action10,
154+
action11, action12, action13, action14, action15, action16, action17, action18, action19, action20,
155+
action21, action22, action23, action24, action25, action26, action27, action28, action29, action30,
156+
action31, action32, action33, action34, action35, action36, action37, action38, action39, action40,
157+
action41, action42, action43, action44, action45, action46, action47, action48, action49, action50,
158+
action51, action52, action53, action54, action55, action56, action57, action58, action59, action60,
159+
action61, action62, action63
160+
]
161+
162+
# 新增:以[1, 2, 3, ..., 63]形式创建action_time数组,便于直观查看和修改
163+
action_time = [
164+
2, 0.33, 1, 0.34, 0.34, 0.5, 0.34, 0.34, 0.34, 0.34,
165+
0.5, 0.5, 0.5, 0.5, 1.34, 0.34, 1, 0.5, 0.5, 0.5,
166+
0.5, 0.34, 0.67, 1.34, 1, 1.67, 0.34, 0.5, 0.67, 0.5,
167+
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1.34, 1.34, 1,
168+
1.34, 0.5, 0.5, 0.5, 0.5, 0.5, 1.67, 1.67, 0.67, 1.17,
169+
0.67, 1.17, 0.67, 1.34, 0.67, 1.34, 0.67, 1.17, 0.67, 1.17,
170+
0.67, 1.17, 2
171+
]
172+
173+
poses = action_group
174+
count = 0
175+
while True:
176+
# 获取当前动作
177+
position = count % len(poses)
178+
current_pose = poses[position]
179+
current_time = action_time[position]
180+
181+
if current_pose == "sleep":
182+
print("休眠1s")
183+
time.sleep(1)
184+
count += 1
185+
continue
186+
print(f"执行动作 {count % len(poses) + 1}: {current_pose}")
187+
188+
# 执行动作
189+
hand.finger_move(pose=current_pose)
190+
#hand_r.finger_move(pose=current_pose)
191+
# 计数增加
192+
count += 1
193+
194+
# 等待4秒
195+
time.sleep(current_time)
196+
197+
if __name__ == "__main__":
198+
main()

0 commit comments

Comments
 (0)