@@ -90,34 +90,34 @@ def sub_keyboard_event(event, *args, **kwargs) -> bool:
9090 if len (custom_rl_env .base_command ) > 0 :
9191 if event .type == carb .input .KeyboardEventType .KEY_PRESS :
9292 if event .input .name == 'W' :
93- custom_rl_env .base_command [0 ] = [1 , 0 , 0 ]
93+ custom_rl_env .base_command ["0" ] = [1 , 0 , 0 ]
9494 if event .input .name == 'S' :
95- custom_rl_env .base_command [0 ] = [- 1 , 0 , 0 ]
95+ custom_rl_env .base_command ["0" ] = [- 1 , 0 , 0 ]
9696 if event .input .name == 'A' :
97- custom_rl_env .base_command [0 ] = [0 , 1 , 0 ]
97+ custom_rl_env .base_command ["0" ] = [0 , 1 , 0 ]
9898 if event .input .name == 'D' :
99- custom_rl_env .base_command [0 ] = [0 , - 1 , 0 ]
99+ custom_rl_env .base_command ["0" ] = [0 , - 1 , 0 ]
100100 if event .input .name == 'Q' :
101- custom_rl_env .base_command [0 ] = [0 , 0 , 1 ]
101+ custom_rl_env .base_command ["0" ] = [0 , 0 , 1 ]
102102 if event .input .name == 'E' :
103- custom_rl_env .base_command [0 ] = [0 , 0 , - 1 ]
103+ custom_rl_env .base_command ["0" ] = [0 , 0 , - 1 ]
104104
105105 if len (custom_rl_env .base_command ) > 1 :
106106 if event .input .name == 'I' :
107- custom_rl_env .base_command [1 ] = [1 , 0 , 0 ]
107+ custom_rl_env .base_command ["1" ] = [1 , 0 , 0 ]
108108 if event .input .name == 'K' :
109- custom_rl_env .base_command [1 ] = [- 1 , 0 , 0 ]
109+ custom_rl_env .base_command ["1" ] = [- 1 , 0 , 0 ]
110110 if event .input .name == 'J' :
111- custom_rl_env .base_command [1 ] = [0 , 1 , 0 ]
111+ custom_rl_env .base_command ["1" ] = [0 , 1 , 0 ]
112112 if event .input .name == 'L' :
113- custom_rl_env .base_command [1 ] = [0 , - 1 , 0 ]
113+ custom_rl_env .base_command ["1" ] = [0 , - 1 , 0 ]
114114 if event .input .name == 'U' :
115- custom_rl_env .base_command [1 ] = [0 , 0 , 1 ]
115+ custom_rl_env .base_command ["1" ] = [0 , 0 , 1 ]
116116 if event .input .name == 'O' :
117- custom_rl_env .base_command [1 ] = [0 , 0 , - 1 ]
117+ custom_rl_env .base_command ["1" ] = [0 , 0 , - 1 ]
118118 elif event .type == carb .input .KeyboardEventType .KEY_RELEASE :
119119 for i in range (len (custom_rl_env .base_command )):
120- custom_rl_env .base_command [i ] = [0 , 0 , 0 ]
120+ custom_rl_env .base_command [str ( i ) ] = [0 , 0 , 0 ]
121121 return True
122122
123123
@@ -138,25 +138,23 @@ def cmd_vel_cb(msg, num_robot):
138138 x = msg .linear .x
139139 y = msg .linear .y
140140 z = msg .angular .z
141- custom_rl_env .base_command [num_robot ] = [x , y , z ]
141+ custom_rl_env .base_command [str ( num_robot ) ] = [x , y , z ]
142142
143143
144144
145145def add_cmd_sub (num_envs ):
146146 node_test = rclpy .create_node ('position_velocity_publisher' )
147147 for i in range (num_envs ):
148- node_test .create_subscription (Twist , f'robot{ i } /cmd_vel' , lambda msg : cmd_vel_cb (msg , i ), 10 )
148+ node_test .create_subscription (Twist , f'robot{ i } /cmd_vel' , lambda msg , i = i : cmd_vel_cb (msg , str ( i ) ), 10 )
149149 # Spin in a separate thread
150- thread = threading .Thread (target = rclpy .spin , args = (node_test , ), daemon = True )
150+ thread = threading .Thread (target = rclpy .spin , args = (node_test ,), daemon = True )
151151 thread .start ()
152152
153153
154154
155155def specify_cmd_for_robots (numv_envs ):
156- base_cmd = []
157- for _ in range (numv_envs ):
158- base_cmd .append ([0 , 0 , 0 ])
159- custom_rl_env .base_command = base_cmd
156+ for i in range (numv_envs ):
157+ custom_rl_env .base_command [str (i )] = [0 , 0 , 0 ]
160158def run_sim ():
161159
162160 # acquire input interface
0 commit comments