Пример #1
0
 private void updateVelocity(long deltaTime) {
   if (turnRate > 0) {
     double deltaHeading = (deltaTime * turnRate) / MS_PER_SECOND;
     double newHeading = mCurrentVelocity.Direction() + deltaHeading;
     while (newHeading < 0.0f) newHeading += DEGREES_PER_CIRCLE;
     newHeading %= DEGREES_PER_CIRCLE;
     mCurrentVelocity.SetDirectionAndMagnitude(newHeading, mCurrentVelocity.Magnitude());
   }
 }
Пример #2
0
 private void updateLocation(long deltaTime) {
   Vector velocity = new Vector(mCurrentVelocity).Add(mWindVelocity);
   double deltaX = (velocity.X() / 3.6) * (deltaTime / 1000); // kph to m/s and ms to s
   double deltaY = (velocity.Y() / 3.6) * (deltaTime / 1000); // kph to m/s and ms to s
   mLatitude = mLatitude + (180 / Math.PI) * (deltaY / EARTH_RADIUS);
   mLongitude =
       mLongitude
           + (180 / Math.PI) * (deltaX / EARTH_RADIUS) / Math.cos(Math.PI / 180.0 * mLatitude);
 }
Пример #3
0
  private void generateTestData() {

    long currentTime = new Date().getTime();
    if (timeOfLastUpdate == 0) timeOfLastUpdate = currentTime;
    long deltaTime = currentTime - timeOfLastUpdate;

    if (mCurrentAltitude > startAltitude + 200
        && turnRate != 0.0
        && Angle.delta(mCurrentVelocity.Direction(), mWindVelocity.Direction()) < 20) {
      turnRate = 0.0;
      mCurrentVelocity.SetDirectionAndMagnitude(mCurrentVelocity.Direction(), 50);
    } else if (mCurrentAltitude < startAltitude && turnRate == 0.0) {
      turnRate = 15.0;
      mCurrentVelocity.SetDirectionAndMagnitude(mCurrentVelocity.Direction(), 30);
    }

    updateClimbRate();
    updateVelocity(deltaTime);
    updateAltitude(deltaTime);
    updateLocation(deltaTime);

    Vector combinedVelocity = new Vector(mCurrentVelocity).Add(mWindVelocity);
    HashMap<UUID, Double> values = new HashMap<>();

    values.put(MessageChannels.GROUNDSPEED, combinedVelocity.Magnitude() / 3.6);
    values.put(MessageChannels.BEARING, combinedVelocity.Direction());
    values.put(MessageChannels.VARIO, mCurrentClimbRate);
    values.put(MessageChannels.LONGITUDE, mLongitude);
    values.put(MessageChannels.LATITUDE, mLatitude);
    values.put(MessageChannels.ALTITUDE, mCurrentAltitude);

    sendMsg(
        new Configuration(id(), new HashSet<>(values.keySet())),
        new Date().getTime(),
        new DataMessage(values));

    timeOfLastUpdate = currentTime;
  }