@@ -57,6 +57,7 @@ def __init__(self, namespace, robot_name, walk_as_node):
57
57
def objective (self , trial ):
58
58
# get parameter to evaluate from optuna
59
59
self .suggest_walk_params (trial )
60
+ self .reset ()
60
61
61
62
cost = 0
62
63
# starting with hardest first, to get faster early termination
@@ -70,7 +71,7 @@ def objective(self, trial):
70
71
d = 0
71
72
for direction in self .directions :
72
73
d += 1
73
- self .reset ()
74
+ self .reset_position ()
74
75
early_term , cost_try = self .evaluate_direction (* direction , trial , eval_try )
75
76
cost += cost_try
76
77
# check if we failed in this direction and terminate this trial early
@@ -88,13 +89,13 @@ def suggest_walk_params(self, trial):
88
89
raise NotImplementedError
89
90
90
91
def evaluate_direction (self , x , y , yaw , trial : optuna .Trial , iteration ):
91
- start_time = rospy .get_time ()
92
+ start_time = self . sim .get_time ()
92
93
self .set_cmd_vel (x * iteration , y * iteration , yaw * iteration )
93
94
print (F'cmd: { x * iteration } { y * iteration } { yaw * iteration } ' )
94
95
95
96
# wait till time for test is up or stopping condition has been reached
96
97
while not rospy .is_shutdown ():
97
- passed_time = rospy .get_time () - start_time
98
+ passed_time = self . sim .get_time () - start_time
98
99
if passed_time > self .time_limit :
99
100
# reached time limit, stop robot
100
101
self .set_cmd_vel (0 , 0 , 0 )
@@ -176,6 +177,13 @@ def compute_cost(self, x, y, yaw):
176
177
early_term = True
177
178
return early_term , cost
178
179
180
+ def reset_position (self ):
181
+ height = self .current_params ['trunk_height' ] + self .reset_height_offset
182
+ pitch = self .current_params ['trunk_pitch' ]
183
+ (x , y , z , w ) = tf .transformations .quaternion_from_euler (0 , pitch , 0 )
184
+
185
+ self .sim .reset_robot_pose ((0 , 0 , height ), (x , y , z , w ))
186
+
179
187
def reset (self ):
180
188
# reset simulation
181
189
# self.sim.reset()
@@ -193,11 +201,7 @@ def reset(self):
193
201
else :
194
202
self .run_walking (duration = 2 )
195
203
self .sim .set_gravity (True )
196
- height = self .current_params ['trunk_height' ] + self .reset_height_offset
197
- pitch = self .current_params ['trunk_pitch' ]
198
- (x , y , z , w ) = tf .transformations .quaternion_from_euler (0 , pitch , 0 )
199
-
200
- self .sim .reset_robot_pose ((0 , 0 , height ), (x , y , z , w ))
204
+ self .reset_position ()
201
205
if self .walk_as_node :
202
206
self .sim .run_simulation (duration = 2 , sleep = 0.01 )
203
207
else :
@@ -215,8 +219,8 @@ def set_cmd_vel(self, x, y, yaw):
215
219
216
220
217
221
class WolfgangWalkOptimization (AbstractWalkOptimization ):
218
- def __init__ (self , namespace , gui ):
219
- super (WolfgangWalkOptimization , self ).__init__ (namespace , 'wolfgang' )
222
+ def __init__ (self , namespace , gui , walk_as_node ):
223
+ super (WolfgangWalkOptimization , self ).__init__ (namespace , 'wolfgang' , walk_as_node )
220
224
self .reset_height_offset = 0.005
221
225
self .directions = [[0.1 , 0 , 0 ],
222
226
[- 0.1 , 0 , 0 ],
@@ -237,36 +241,59 @@ def suggest_walk_params(self, trial):
237
241
def add (name , min_value , max_value ):
238
242
param_dict [name ] = trial .suggest_uniform (name , min_value , max_value )
239
243
240
- add ('double_support_ratio' , 0.0 , 1.0 )
241
- add ('freq' , 0.1 , 5 )
242
- add ('foot_apex_phase' , 0.0 , 1.0 )
244
+ add ('double_support_ratio' , 0.0 , 0.45 )
245
+ add ('freq' , 1.5 , 3 )
243
246
add ('foot_distance' , 0.1 , 0.3 )
244
- add ('foot_rise' , 0.01 , 0.1 )
245
- add ('foot_overshoot_phase' , 0.0 , 1.0 )
246
- add ('foot_overshoot_ratio' , 0.0 , 1.0 )
247
- add ('trunk_height' , 0.25 , 0.5 )
247
+ add ('trunk_height' , 0.38 , 0.45 )
248
248
add ('trunk_phase' , - 0.5 , 0.5 )
249
- add ('trunk_pitch' , - 0.5 , 0.5 )
250
249
add ('trunk_swing' , 0.0 , 1.0 )
251
- add ('trunk_x_offset' , - 0.05 , 0.05 )
252
- add ('trunk_y_offset' , - 0.05 , 0.05 )
253
- add ('first_step_swing_factor' , 0.5 , 2 )
254
- add ('first_step_trunk_phase' , - 0.5 , 0.5 )
250
+ add ('trunk_x_offset' , - 0.03 , 0.03 )
255
251
256
252
add ('trunk_x_offset_p_coef_forward' , - 1 , 1 )
257
253
add ('trunk_x_offset_p_coef_turn' , - 1 , 1 )
258
- add ('trunk_pitch_p_coef_forward' , - 5 , 5 )
259
- add ('trunk_pitch_p_coef_turn' , - 5 , 5 )
260
- add ('foot_z_pause' , 0 , 1 )
261
- add ('foot_put_down_phase' , 0 , 1 )
262
- add ('trunk_pause' , 0 , 1 )
254
+
255
+ # add('first_step_swing_factor', 0.0, 2)
256
+ # add('first_step_trunk_phase', -0.5, 0.5)
257
+ param_dict ['first_step_swing_factor' ] = 1
258
+ param_dict ['first_step_trunk_phase' ] = - 0.5
259
+
260
+ # add('foot_overshoot_phase', 0.0, 1.0)
261
+ # add('foot_overshoot_ratio', 0.0, 1.0)
262
+ param_dict ['foot_overshoot_phase' ] = 1
263
+ param_dict ['foot_overshoot_ratio' ] = 0.0
264
+
265
+ # add('trunk_y_offset', -0.03, 0.03)
266
+ # add('foot_rise', 0.04, 0.08)
267
+ # add('foot_apex_phase', 0.0, 1.0)
268
+ param_dict ['trunk_y_offset' ] = 0
269
+ param_dict ['foot_rise' ] = 0.1
270
+ param_dict ['foot_apex_phase' ] = 0.5
271
+ # todo put this as addition arguments to trial
272
+
273
+ # add('trunk_pitch', -1.0, 1.0)
274
+ # add('trunk_pitch_p_coef_forward', -5, 5)
275
+ # add('trunk_pitch_p_coef_turn', -5, 5)
276
+ param_dict ['trunk_pitch' ] = 0
277
+ param_dict ['trunk_pitch_p_coef_forward' ] = 0
278
+ param_dict ['trunk_pitch_p_coef_turn' ] = 0
279
+
280
+ # add('foot_z_pause', 0, 1)
281
+ # add('foot_put_down_phase', 0, 1)
282
+ # add('trunk_pause', 0, 1)
283
+ param_dict ['foot_z_pause' ] = 0
284
+ param_dict ['foot_put_down_phase' ] = 1
285
+ param_dict ['trunk_pause' ] = 0
263
286
264
287
# todo 'trunk' nochmal ander nennen? body?
265
288
266
289
# todo also find PID values, maybe in a second step after finding walking params
267
290
# todo de/activate phase reset while searching params? yes
268
291
269
- self .set_params (param_dict )
292
+ if self .walk_as_node :
293
+ self .set_params (param_dict )
294
+ else :
295
+ self .current_params = param_dict
296
+ self .walk .set_engine_dyn_reconf (param_dict )
270
297
271
298
272
299
class DarwinWalkOptimization (AbstractWalkOptimization ):
@@ -275,9 +302,13 @@ def __init__(self, namespace, gui, walk_as_node):
275
302
self .reset_height_offset = 0.09
276
303
self .directions = [[0.05 , 0 , 0 ],
277
304
[- 0.05 , 0 , 0 ],
305
+ [0 , 0.025 , 0 ],
306
+ [0 , - 0.025 , 0 ],
278
307
[0 , 0 , 0.25 ],
279
308
[0 , 0 , - 0.25 ],
280
- [0.05 , 0 , 0.25 ],
309
+ [0.05 , 0.25 , 0 ],
310
+ [0.05 , - 0.25 , 0 ],
311
+ [0.05 , 0 , - 0.25 ],
281
312
[- 0.05 , 0 , 0.25 ],
282
313
]
283
314
self .sim = WebotsSim (self .namespace , gui )
@@ -288,31 +319,34 @@ def suggest_walk_params(self, trial):
288
319
def add (name , min_value , max_value ):
289
320
param_dict [name ] = trial .suggest_uniform (name , min_value , max_value )
290
321
291
- # todo try without overshoot
292
- # todo try without apex phase
293
- # todo try without pitch values, only x offset
294
- add ('double_support_ratio' , 0.0 , 0.8 )
295
- add ('freq' , 0.5 , 3 )
322
+ add ('double_support_ratio' , 0.0 , 0.5 )
323
+ add ('freq' , 1.5 , 3 )
296
324
add ('foot_distance' , 0.08 , 0.17 )
297
- add ('foot_overshoot_phase' , 0.0 , 1.0 )
298
- add ('foot_overshoot_ratio' , 0.0 , 1.0 )
299
325
add ('trunk_height' , 0.18 , 0.24 )
300
326
add ('trunk_phase' , - 0.5 , 0.5 )
301
327
add ('trunk_swing' , 0.0 , 1.0 )
302
328
add ('trunk_x_offset' , - 0.03 , 0.03 )
303
- add ('first_step_swing_factor' , 0.0 , 2 )
304
- add ('first_step_trunk_phase' , - 0.5 , 0.5 )
305
329
306
330
add ('trunk_x_offset_p_coef_forward' , - 1 , 1 )
307
331
add ('trunk_x_offset_p_coef_turn' , - 1 , 1 )
308
332
333
+ #add('first_step_swing_factor', 0.0, 2)
334
+ #add('first_step_trunk_phase', -0.5, 0.5)
335
+ param_dict ['first_step_swing_factor' ] = 1
336
+ param_dict ['first_step_trunk_phase' ] = - 0.5
337
+
338
+ #add('foot_overshoot_phase', 0.0, 1.0)
339
+ #add('foot_overshoot_ratio', 0.0, 1.0)
340
+ param_dict ['foot_overshoot_phase' ] = 1
341
+ param_dict ['foot_overshoot_ratio' ] = 0.0
342
+
309
343
# add('trunk_y_offset', -0.03, 0.03)
310
344
# add('foot_rise', 0.04, 0.08)
311
345
# add('foot_apex_phase', 0.0, 1.0)
312
346
param_dict ['trunk_y_offset' ] = 0
313
- param_dict ['foot_rise' ] = 0.04
347
+ param_dict ['foot_rise' ] = 0.05
314
348
param_dict ['foot_apex_phase' ] = 0.5
315
- # todo put this as addition arguments to trail
349
+ # todo put this as addition arguments to trial
316
350
317
351
# add('trunk_pitch', -1.0, 1.0)
318
352
# add('trunk_pitch_p_coef_forward', -5, 5)
0 commit comments