Rename multi-segment functions to two-concept names; polish docstrings
Naming pass: rename functions whose third+ segment is redundant or implementation-detail, sticking to the codebase's preferred ``noun_verb`` / ``verb_noun`` two-concept idiom. Renames are atomic across definitions, callers, and tests. is_penned_position → is_penned modulate_speed_near_sheep → modulate_speed mecanum_kinematics_step → mecanum_step policy_forward_mean → forward_mean Two-concept patterns like ``velocity_to_wheels`` / ``detections_from_scan`` / ``make_strombom_predictor`` are left alone — they're idiomatic converters / factories that read as a single concept, and the longer form aids grep-ability. Docstring polish: * ``herding/config.py`` header drops the "previously lived as a module-level literal" historical framing — we ship as a single thing, so the refactor anecdote no longer earns its keep. The usage examples now mention both ``HERDING_WEBOTS`` and ``HERDING_MEC_WEBOTS`` presets. 126 pytest cases still pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -55,7 +55,7 @@ def build_model(net_arch_pi, net_arch_vf, log_std_init: float,
|
||||
return model, env
|
||||
|
||||
|
||||
def policy_forward_mean(policy, obs_batch):
|
||||
def forward_mean(policy, obs_batch):
|
||||
"""Return the deterministic mean action for an obs batch.
|
||||
|
||||
SB3's ActorCriticPolicy routes ``forward`` through a Distribution
|
||||
@@ -177,7 +177,7 @@ def main():
|
||||
ob_batch = ob_batch.to(args.device)
|
||||
act_batch = act_batch.to(args.device)
|
||||
optimizer.zero_grad()
|
||||
mean_action = policy_forward_mean(policy, ob_batch)
|
||||
mean_action = forward_mean(policy, ob_batch)
|
||||
loss, mse_val, cos_val = combined_loss(mean_action, act_batch)
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
@@ -196,7 +196,7 @@ def main():
|
||||
for ob_batch, act_batch in val_loader:
|
||||
ob_batch = ob_batch.to(args.device)
|
||||
act_batch = act_batch.to(args.device)
|
||||
mean_action = policy_forward_mean(policy, ob_batch)
|
||||
mean_action = forward_mean(policy, ob_batch)
|
||||
bs = ob_batch.size(0)
|
||||
val_total += nn.functional.mse_loss(
|
||||
mean_action, act_batch, reduction="sum",
|
||||
|
||||
@@ -28,7 +28,7 @@ from gymnasium import spaces
|
||||
|
||||
from herding.world.diffdrive import (
|
||||
heading_speed_to_wheels, kinematics_step,
|
||||
mecanum_kinematics_step, velocity_to_mecanum_wheels, velocity_to_wheels,
|
||||
mecanum_step, velocity_to_mecanum_wheels, velocity_to_wheels,
|
||||
)
|
||||
from herding.world.flocking_sim import (
|
||||
FLEE_SPEED, MAX_SPEED, WANDER_SPEED, compute_heading_speed,
|
||||
@@ -40,7 +40,7 @@ from herding.world.geometry import (
|
||||
GATE_X, GATE_Y, MAX_SHEEP,
|
||||
PEN_ENTRY, PEN_X, PEN_Y,
|
||||
SHEEP_MAX_WHEEL_OMEGA, SHEEP_WHEEL_BASE, SHEEP_WHEEL_RADIUS,
|
||||
WEBOTS_DT, clip_to_field, is_penned_position,
|
||||
WEBOTS_DT, clip_to_field, is_penned,
|
||||
)
|
||||
from herding.perception.lidar_perception import detections_from_scan
|
||||
from herding.perception.lidar_sim import simulate_scan
|
||||
@@ -302,7 +302,7 @@ class HerdingEnv(gym.Env):
|
||||
if robot_cfg is not None else 1.0)
|
||||
strafe_bleed = (robot_cfg.strafe_to_forward_bleed
|
||||
if robot_cfg is not None else 0.0)
|
||||
self.dog_x, self.dog_y, self.dog_heading = mecanum_kinematics_step(
|
||||
self.dog_x, self.dog_y, self.dog_heading = mecanum_step(
|
||||
self.dog_x, self.dog_y, self.dog_heading,
|
||||
w_fl, w_fr, w_rl, w_rr,
|
||||
DOG_WHEEL_RADIUS,
|
||||
@@ -337,7 +337,7 @@ class HerdingEnv(gym.Env):
|
||||
self._step_one_sheep(i)
|
||||
for i in range(self.n_sheep):
|
||||
if (not self.sheep_penned[i]
|
||||
and is_penned_position(self.sheep_x[i], self.sheep_y[i])):
|
||||
and is_penned(self.sheep_x[i], self.sheep_y[i])):
|
||||
self.sheep_penned[i] = True
|
||||
|
||||
# LiDAR perception runs after sheep move; feeds the obs and the
|
||||
|
||||
Reference in New Issue
Block a user