Class Servo

All Implemented Interfaces:
Logger

public class Servo extends Motor
The servo motor class. This class is used to control a servo motor via the I2C bus.
  • Constructor Details

    • Servo

      public Servo(int identifier, int address)
      Creates a new servo with the given address on the default I2C bus.
      Parameters:
      identifier - The identifier of the servo.
      address - The I2C address of the controller.
    • Servo

      public Servo(int identifier, int address, int bus)
      Creates a new servo with the given address on the given I2C bus.
      Parameters:
      identifier - The identifier of the servo.
      address - The I2C address of the controller.
      bus - The I2C bus the controller is connected to.
  • Method Details

    • connectToI2C

      public void connectToI2C(int pin)
      Connects the servo to the I2C bus. This is assuming that the bot has the standard interpreter for the Arduino. If you're using a different interpreter, you'll need to change this method or create a different subclass.
      Overrides:
      connectToI2C in class Motor
      Parameters:
      pin - The pin to connect the servo to.
    • setRawSpeed

      public void setRawSpeed(double speed)
      Sets the speed of the servo to a number between 0 and 180.
      Parameters:
      speed - The speed to set the servo to.
    • setSpeed

      public void setSpeed(double speed)
      Sets the speed of the servo to a number between -1 and 1.
      Overrides:
      setSpeed in class Motor
      Parameters:
      speed - The speed to set the servo to.
    • stop

      public void stop()
      Stops the servo via setting the speed to 90 (halfway point).
      Overrides:
      stop in class Motor
    • reportSpeed

      protected void reportSpeed()
      Reports the speed of the servo to the I2C bus.
      Overrides:
      reportSpeed in class Motor