@Override public SystemPositionAndAttitude step(SystemPositionAndAttitude state, double timestep) { model.setState(state); double distToDestination = state.getPosition().getDistanceInMeters(destination); if (loiterType.equalsIgnoreCase("circular")) { if (distToDestination - 2 > radius) { model.guide( destination, speed, destination.getDepth() >= 0 ? null : -destination.getDepth()); if (!enteredLoiter) loiterTime = 0; } else { enteredLoiter = true; double perpend = state.getPosition().getXYAngle(destination) + Math.PI / 2; LocationType loc = new LocationType(state.getPosition()); loc.setDepth(destination.getDepth()); if (clockwise) loc.translatePosition(Math.cos(perpend) * -20, Math.sin(perpend) * -20, 0); else loc.translatePosition(Math.cos(perpend) * 20, Math.sin(perpend) * 20, 0); model.guide(loc, speed, destination.getDepth() >= 0 ? null : -destination.getDepth()); loiterTime += timestep; } } else { if (distToDestination < speed * 2) loiterTime += timestep; else model.guide( destination, speed, destination.getDepth() >= 0 ? null : -destination.getDepth()); } model.advance(timestep); if (loiterTime > duration) finished = true; return model.getState(); }