1+ import time
2+ import sys
3+ from unitree_sdk2py .core .channel import ChannelSubscriber , ChannelFactoryInitialize
4+ from unitree_sdk2py .g1 .arm .g1_arm_action_client import G1ArmActionClient
5+ from unitree_sdk2py .g1 .arm .g1_arm_action_client import action_map
6+ from dataclasses import dataclass
7+
8+ @dataclass
9+ class TestOption :
10+ name : str
11+ id : int
12+
13+ option_list = [
14+ TestOption (name = "release arm" , id = 0 ),
15+ TestOption (name = "shake hand" , id = 1 ),
16+ TestOption (name = "high five" , id = 2 ),
17+ TestOption (name = "hug" , id = 3 ),
18+ TestOption (name = "high wave" , id = 4 ),
19+ TestOption (name = "clap" , id = 5 ),
20+ TestOption (name = "face wave" , id = 6 ),
21+ TestOption (name = "left kiss" , id = 7 ),
22+ TestOption (name = "heart" , id = 8 ),
23+ TestOption (name = "right heart" , id = 9 ),
24+ TestOption (name = "hands up" , id = 10 ),
25+ TestOption (name = "x-ray" , id = 11 ),
26+ TestOption (name = "right hand up" , id = 12 ),
27+ TestOption (name = "reject" , id = 13 ),
28+ TestOption (name = "right kiss" , id = 14 ),
29+ TestOption (name = "two-hand kiss" , id = 15 ),
30+
31+ ]
32+
33+ class UserInterface :
34+ def __init__ (self ):
35+ self .test_option_ = None
36+
37+ def convert_to_int (self , input_str ):
38+ try :
39+ return int (input_str )
40+ except ValueError :
41+ return None
42+
43+ def terminal_handle (self ):
44+ input_str = input ("Enter id or name: \n " )
45+
46+ if input_str == "list" :
47+ self .test_option_ .name = None
48+ self .test_option_ .id = None
49+ for option in option_list :
50+ print (f"{ option .name } , id: { option .id } " )
51+ return
52+
53+ for option in option_list :
54+ if input_str == option .name or self .convert_to_int (input_str ) == option .id :
55+ self .test_option_ .name = option .name
56+ self .test_option_ .id = option .id
57+ print (f"Test: { self .test_option_ .name } , test_id: { self .test_option_ .id } " )
58+ return
59+
60+ print ("No matching test option found." )
61+
62+
63+ if __name__ == "__main__" :
64+ if len (sys .argv ) < 2 :
65+ print (f"Usage: python3 { sys .argv [0 ]} networkInterface" )
66+ sys .exit (- 1 )
67+
68+ print ("WARNING: Please ensure there are no obstacles around the robot while running this example." )
69+ input ("Press Enter to continue..." )
70+
71+ ChannelFactoryInitialize (0 , sys .argv [1 ])
72+
73+ test_option = TestOption (name = None , id = None )
74+ user_interface = UserInterface ()
75+ user_interface .test_option_ = test_option
76+
77+ armAction_client = G1ArmActionClient ()
78+ armAction_client .SetTimeout (10.0 )
79+ armAction_client .Init ()
80+
81+ # actionList = armAction_client.GetActionList()
82+ # print("actionList\n",actionList)
83+
84+ print ("Input \" list\" to list all test option ..." )
85+ while True :
86+ user_interface .terminal_handle ()
87+
88+ print (f"Updated Test Option: Name = { test_option .name } , ID = { test_option .id } " )
89+
90+ if test_option .id == 0 :
91+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
92+ elif test_option .id == 1 :
93+ armAction_client .ExecuteAction (action_map .get ("shake hand" ))
94+ time .sleep (2 )
95+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
96+ elif test_option .id == 2 :
97+ armAction_client .ExecuteAction (action_map .get ("high five" ))
98+ time .sleep (2 )
99+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
100+ elif test_option .id == 3 :
101+ armAction_client .ExecuteAction (action_map .get ("hug" ))
102+ time .sleep (2 )
103+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
104+ elif test_option .id == 4 :
105+ armAction_client .ExecuteAction (action_map .get ("high wave" ))
106+ elif test_option .id == 5 :
107+ armAction_client .ExecuteAction (action_map .get ("clap" ))
108+ elif test_option .id == 6 :
109+ armAction_client .ExecuteAction (action_map .get ("face wave" ))
110+ elif test_option .id == 7 :
111+ armAction_client .ExecuteAction (action_map .get ("left kiss" ))
112+ elif test_option .id == 8 :
113+ armAction_client .ExecuteAction (action_map .get ("heart" ))
114+ time .sleep (2 )
115+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
116+ elif test_option .id == 9 :
117+ armAction_client .ExecuteAction (action_map .get ("right heart" ))
118+ time .sleep (2 )
119+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
120+ elif test_option .id == 10 :
121+ armAction_client .ExecuteAction (action_map .get ("hands up" ))
122+ time .sleep (2 )
123+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
124+ elif test_option .id == 11 :
125+ armAction_client .ExecuteAction (action_map .get ("x-ray" ))
126+ time .sleep (2 )
127+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
128+ elif test_option .id == 12 :
129+ armAction_client .ExecuteAction (action_map .get ("right hand up" ))
130+ time .sleep (2 )
131+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
132+ elif test_option .id == 13 :
133+ armAction_client .ExecuteAction (action_map .get ("reject" ))
134+ time .sleep (2 )
135+ armAction_client .ExecuteAction (action_map .get ("release arm" ))
136+ elif test_option .id == 14 :
137+ armAction_client .ExecuteAction (action_map .get ("right kiss" ))
138+ elif test_option .id == 15 :
139+ armAction_client .ExecuteAction (action_map .get ("two-hand kiss" ))
140+
141+ time .sleep (1 )
0 commit comments