How do I mount a Limelight on a moving mechanism?
withCameraOffset isn't limited to a fixed, one-time value. Call it every periodic loop with a pose computed from your mechanism's current position when the camera itself moves relative to robot center.
Example: camera mounted on a rotating turret
Adapted from YALL's TurretSubsystem example (LocalizationExamples):
@Override
public void periodic() {
limelight.getSettings()
.withRobotOrientation(new Orientation3d(new Rotation3d(swerveDrive.getOdometryHeading()),
new AngularVelocity3d(DegreesPerSecond.of(0),
DegreesPerSecond.of(0),
DegreesPerSecond.of(0))))
.withCameraOffset(cameraOffsetFromRobotCenter.rotateAround(
turretPivotCenterFromCamera,
new Rotation3d(0, 0, turret.getAngle().in(Radians))))
.save();
}cameraOffsetFromRobotCenter is the camera's pose when the turret sits at its zero angle. rotateAround re-derives the camera's current offset every loop by rotating that fixed pose around the turret's pivot point by the turret's live angle. Without this, MegaTag pose estimates silently assume the camera never moved and drift as the turret rotates.
Checklist
Measure
cameraOffsetFromRobotCenterand the turret pivot point once, physically, at turret-zero.Call
withCameraOffsetwith the recomputed pose every loop, not just once at startup.Still submit
withRobotOrientationevery loop for MegaTag2; the two settings are independent (robot heading vs. camera-to-robot offset).
See Also
Last updated
Was this helpful?