"""Episode distance from physics-clock poses, independent of viewer polling.""" import math def planar_twist(linear, angular, forward): """Measured world velocities expressed in the rover's horizontal heading. Yaw rate is the derivative of atan2(forward_y, forward_x), including pitch; world angular-Z alone is not that derivative on inclined ground. """ if any(len(v) != 3 or not all(math.isfinite(x) for x in v) for v in (linear, angular, forward)): raise ValueError('Invalid physical velocity observation') fx, fy, fz = forward horizontal = fx*fx + fy*fy if horizontal <= 1e-12: raise ValueError('Heading is undefined for a vertical body axis') length = math.sqrt(horizontal) vx = (linear[0]*fx + linear[1]*fy) / length vy = (-linear[0]*fy + linear[1]*fx) / length yaw = angular[2] - fz*(fx*angular[0] + fy*angular[1]) / horizontal return vx, vy, yaw class PlanarDistance: def __init__(self): self.metres = 0.0 self.previous = None def observe(self, xy): xy = tuple(xy) if len(xy) != 2 or not all(math.isfinite(value) for value in xy): raise ValueError('Invalid distance observation') if self.previous is not None: self.metres += math.dist(self.previous, xy) self.previous = xy return self.metres