Class Motor

java.lang.Object
me.autobot.lib.robot.Device
me.autobot.lib.robot.Motor
All Implemented Interfaces:
Logger
Direct Known Subclasses:
HoverboardWheel, Servo

public class Motor extends Device
A moving device that can be controlled by the robot, such as a motor.
  • Constructor Details

    • Motor

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

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

    • connectToI2C

      public void connectToI2C(int pin)
      Actually connects the motor to the I2C bus using the given pin. This must be overridden by subclasses, it will throw a warning if not. Note: The parent must be set before calling this method.
      Parameters:
      pin - The pin the motor is connected to on the motor controller.
    • connectToSerial

      public void connectToSerial(String port)
      Connects the motor to the Serial. This must be overridden by subclasses, it will throw a warning if not.
      Parameters:
      port - The port to connect to.
    • setSpeed

      public void setSpeed(double speed)
      Sets the speed of the motor.
      Parameters:
      speed - The speed of the motor, from -1 to 1.
    • stop

      public void stop()
      Stops the motor (sets speed to 0).
    • invert

      public void invert()
      Inverts the motor's direction.
    • brake

      public void brake()
      Brakes the motor. Should be overridden by subclasses.
    • reportSpeed

      protected void reportSpeed()
      Sends the speed to the motor controller. This should be overridden by subclasses due to the difference in motor controllers.
    • emergencyStop

      public void emergencyStop()
      Emergency stops the motor. Runs both #stop and #brake.
      Overrides:
      emergencyStop in class Device
      See Also:
    • inSimulation

      public boolean inSimulation()
      Returns whether the motor is currently in simulation mode.
      Overrides:
      inSimulation in class Device
      Returns:
      Whether the motor is in simulation mode.
    • getAddress

      public int getAddress()
      Returns the I2C address of the motor controller.
      Returns:
      The I2C address of the motor controller.
    • getBus

      public int getBus()
      Returns the I2C bus the motor controller is connected to.
      Returns:
      The I2C bus the motor controller is connected to.
    • isInverted

      public boolean isInverted()
      Returns if the motor direction is inverted.
      Returns:
      If the direction is inverted.
    • getIdentifier

      public int getIdentifier()
      Returns the identifier of the motor.
      Returns:
      The identifier of the motor.