3131
3232ONNX_MODEL = os .path .join (get_package_share_directory ("bitbots_rl_walk" ), "models" , "wolfgang_kick_ppo.onnx" )
3333
34- PREPARATION_STATE = np .array (
35- [
36- 0 , # RShoulderPitch
37- 0 , # RShoulderRoll
38- 0 , # RElbow (angewinkelt)
39- 0 , # LShoulderPitch
40- 0 , # LShoulderRoll
41- 0 , # LElbow (angewinkelt)
42- 0 , # RHipYaw
43- 0 , # RHipRoll
44- 0 , # RHipPitch
45- 0 , # RKnee (durchgestreckt)
46- - 0.2 , # RAnklePitch (leichte Verlagerung nach hinten)
47- 0 , # RAnkleRoll
48- 0 , # LHipYaw
49- 0 , # LHipRoll
50- 0 , # LHipPitch
51- 0 , # LKnee (durchgestreckt)
52- 0.2 , # LAnklePitch (leichte Verlagerung nach hinten)
53- 0 , # LAnkleRoll
54- ],
55- dtype = np .float32 ,
56- )
57-
58- PREPARATION_STATE2 = np .array (
59- [
60- 0 , # RShoulderPitch
61- 0 , # RShoulderRoll
62- 0 , # RElbow
63- 0 , # LShoulderPitch
64- 0 , # LShoulderRoll
65- 0 , # LElbow
66- 0 , # RHipYaw
67- 0 , # RHipRoll
68- 0 , # RHipPitch ← stark reduziert (oder probiere +0.10, falls negativ = vorne)
69- - 1.0 , # RKnee ← deutlich weniger Beugung → sanfter
70- 0.60 , # RAnklePitch ← stärker Zehen hoch → mehr Gegengewicht nach hinten
71- 0 , # RAnkleRoll
72- 0 , # LHipYaw
73- 0 , # LHipRoll
74- 0 , # LHipPitch ← symmetrisch – teste ggf. -0.10
75- 1.0 , # LKnee ← symmetrisch weniger Beugung
76- - 0.60 , # LAnklePitch ← stärker kompensierend
77- 0 , # LAnkleRoll
78- ],
79- dtype = np .float32 ,
80- )
81-
82- PREPARATION_STATE3 = np .array (
83- [
84- 0 , # RShoulderPitch
85- 0 , # RShoulderRoll
86- 0 , # RElbow
87- 0 , # LShoulderPitch
88- 0 , # LShoulderRoll
89- 0 , # LElbow
90- 0.012 , # RHipYaw ← leichter Übergang zu 0.024
91- - 0.05 , # RHipRoll ← leichter zu -0.104
92- - 0.32 , # RHipPitch ← Mittel zwischen -0.10 und -0.735 (weniger vorwärts)
93- - 1.06 , # RKnee ← Mittel zwischen -0.80 und -1.323
94- 0.57 , # RAnklePitch ← etwas stärker als in STATE2 (mehr nach hinten)
95- - 0.06 , # RAnkleRoll ← leichter zu -0.129
96- - 0.008 , # LHipYaw ← zu -0.016
97- 0.04 , # LHipRoll ← zu 0.073
98- 0.32 , # LHipPitch ← Mittel zwischen 0.10 und 0.742 (mirrored Sign)
99- 1.07 , # LKnee ← Mittel zwischen 0.80 und 1.335
100- - 0.57 , # LAnklePitch ← mirrored, stärker kompensierend
101- 0.04 , # LAnkleRoll ← zu 0.074
102- ],
103- dtype = np .float32 ,
104- )
105-
10634WALKREADY_STATE = np .array (
10735 [
10836 0 ,
@@ -187,21 +115,10 @@ def __init__(self):
187115 # First send the walkready state to the robot for 100 iterations
188116 joint_command = JointCommand ()
189117 joint_command .joint_names = ORDERED_RELEVANT_JOINT_NAMES
190- joint_command .positions = PREPARATION_STATE
191118 joint_command .velocities = [0.2 ] * len (ORDERED_RELEVANT_JOINT_NAMES )
192119 joint_command .accelerations = [- 1.0 ] * len (ORDERED_RELEVANT_JOINT_NAMES )
193120 joint_command .max_currents = [- 1.0 ] * len (ORDERED_RELEVANT_JOINT_NAMES ) # -1.0 means no limit
194121 joint_command .header .stamp = self .get_clock ().now ().to_msg ()
195- self ._joint_command_pub .publish (joint_command )
196- time .sleep (8 )
197-
198- joint_command .positions = PREPARATION_STATE2
199- self ._joint_command_pub .publish (joint_command )
200- time .sleep (12 )
201-
202- joint_command .positions = PREPARATION_STATE3
203- self ._joint_command_pub .publish (joint_command )
204- time .sleep (12 )
205122
206123 joint_command .positions = WALKREADY_STATE
207124 self ._joint_command_pub .publish (joint_command )
@@ -219,6 +136,19 @@ def _goal_pose_callback(self, msg: PoseStamped):
219136 def _imu_callback (self , msg : Imu ):
220137 self ._imu_data = msg
221138
139+ def _calculate_target_from_direction (self , kick_direction ):
140+ # Convert the kick direction quaternion to a 2D unit vector
141+ kick_direction_mat = quat2mat (
142+ [
143+ kick_direction .w ,
144+ kick_direction .x ,
145+ kick_direction .y ,
146+ kick_direction .z ,
147+ ]
148+ )
149+ kick_direction_vec = kick_direction_mat @ np .array ([1 , 0 , 0 ], dtype = np .float32 )
150+ return kick_direction_vec [:2 ]
151+
222152 def _timer_callback (self ):
223153 """Timer callback to publish joint commands based on the ONNX policy."""
224154 if self ._imu_data is None or self ._joint_state is None or self ._cmd_vel is None :
@@ -230,8 +160,8 @@ def _timer_callback(self):
230160 if self ._joint_state is None :
231161 self .get_logger ().warning ("Waiting for joint state data" , throttle_duration_sec = 1.0 )
232162 if self ._cmd_vel is None :
233- # self.get_logger().warning("Waiting for cmd_vel data", throttle_duration_sec=1.0)
234- self ._cmd_vel = Twist (x = 0.3 , y = 0.0 , z = 0.0 ) # Testing purpose
163+ self .get_logger ().warning ("Waiting for cmd_vel data" , throttle_duration_sec = 1.0 )
164+ # self._cmd_vel = Twist(x=0.3, y=0.0, z=0.0) # Testing purpose
235165
236166 return
237167
@@ -287,7 +217,9 @@ def _timer_callback(self):
287217 dtype = np .float32 ,
288218 )
289219
290- rel_target_pos = np .array ([])
220+ kick_direction = self ._goal_pose .pose .orientation
221+
222+ rel_target_pos = self ._calculate_target_from_direction (kick_direction )
291223
292224 obs = np .hstack (
293225 [
0 commit comments