All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.silverspoon.bulldog.devices.actuators.movement.Sweep Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package io.silverspoon.bulldog.devices.actuators.movement;

import io.silverspoon.bulldog.devices.actuators.Actuator;

public class Sweep implements Move {

   private int durationMilliseconds;

   public Sweep(int durationMilliseconds) {
      this.durationMilliseconds = durationMilliseconds;
   }

   @Override
   public void execute(Actuator actuator) {
      double currentPosition = actuator.getPosition();
      double totalDistance = (180.0 - currentPosition) + 180.0;

      double timeFactorFirstMove = (180.0 - currentPosition) / totalDistance;
      double timeFactorSecondMove = 1.0 - timeFactorFirstMove;

      new LinearMove(180.0, (int) Math.round(durationMilliseconds * timeFactorFirstMove)).execute(actuator);
      new LinearMove(0.0, (int) Math.round(durationMilliseconds * timeFactorSecondMove)).execute(actuator);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy