Esempio n. 1
0
  @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();
  }
Esempio n. 2
0
  @Override
  public void paint(Graphics2D g, StateRenderer2D renderer) {

    if ((System.currentTimeMillis() - lastStateMillis) > 2000) return;

    Point2D pt = renderer.getScreenPosition(simulatedState.getPosition());
    g.translate(pt.getX(), pt.getY());
    g.rotate(-renderer.getRotation() + simulatedState.getYaw() + Math.PI);

    g.setStroke(new BasicStroke(2f));
    g.setColor(Color.cyan.darker().darker());
    g.draw(path);
    g.setColor(Color.cyan.brighter().brighter());
    g.fill(path);
    g.drawString("S", -4, -4);
  }