@@ -33,17 +33,24 @@ def build_common_reset_randomization(env: Any, num_reset: int) -> ResetRandomiza
3333 payload .base_com_offset = base_com_offset
3434
3535 num_actuators = getattr (env , "_num_action" , None )
36- if num_actuators is not None and getattr (domain_rand , "randomize_kp" , False ):
37- low , high = domain_rand .kp_multiplier_range
38- kp_multiplier = np .random .uniform (low , high , size = (num_reset , 1 ))
39- base_kp = float (env .cfg .control_config .Kp )
40- payload .kp = np .broadcast_to (base_kp * kp_multiplier , (num_reset , num_actuators )).copy ()
41-
42- if num_actuators is not None and getattr (domain_rand , "randomize_kd" , False ):
43- low , high = domain_rand .kd_multiplier_range
44- kd_multiplier = np .random .uniform (low , high , size = (num_reset , 1 ))
45- base_kd = float (env .cfg .control_config .Kd )
46- payload .kd = np .broadcast_to (base_kd * kd_multiplier , (num_reset , num_actuators )).copy ()
36+ need_kp = num_actuators is not None and getattr (domain_rand , "randomize_kp" , False )
37+ need_kd = num_actuators is not None and getattr (domain_rand , "randomize_kd" , False )
38+
39+ if need_kp or need_kd :
40+ backend = getattr (env , "_backend" , None )
41+ if backend is not None and hasattr (backend , "get_actuator_gains" ):
42+ base_kp , base_kd = backend .get_actuator_gains ()
43+ else :
44+ base_kp = np .full (num_actuators , float (env .cfg .control_config .Kp ))
45+ base_kd = np .full (num_actuators , float (env .cfg .control_config .Kd ))
46+
47+ if need_kp :
48+ low , high = domain_rand .kp_multiplier_range
49+ payload .kp = (base_kp * np .random .uniform (low , high , (num_reset , 1 ))).astype (np .float64 )
50+
51+ if need_kd :
52+ low , high = domain_rand .kd_multiplier_range
53+ payload .kd = (base_kd * np .random .uniform (low , high , (num_reset , 1 ))).astype (np .float64 )
4754
4855 return None if payload .is_empty () else payload
4956
0 commit comments