Class Motor

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    Wheel

    public class Motor
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Represents a motor. This class is needed because DcMotor misses some metrics, like the tick count of the motor. The tick count is necessary to use motor encoders (i.e. moving the wheels exactly 1 meter forward).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      com.qualcomm.robotcore.hardware.DcMotor motor
      The DcMotor associated with this motor.
      int tickCount
      The amount of motor ticks that make one full revolution of the motor.
    • Constructor Summary

      Constructors 
      Constructor Description
      Motor​(com.qualcomm.robotcore.hardware.DcMotor motor, int tickCount)
      Instantiate a Motor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the internal DcMotor device.
      void drive​(double speed)
      Starts moving the motor at a given speed.
      void stopMoving()
      Stop the movement of the motor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • motor

        public final com.qualcomm.robotcore.hardware.DcMotor motor
        The DcMotor associated with this motor.
      • tickCount

        public final int tickCount
        The amount of motor ticks that make one full revolution of the motor. It's different for every motor, you may need to search up what the tick count is for your motor.
    • Constructor Detail

      • Motor

        public Motor​(com.qualcomm.robotcore.hardware.DcMotor motor,
                     int tickCount)
        Instantiate a Motor.
        Parameters:
        motor - The DcMotor that is associated with this Motor.
        tickCount - The number of ticks for a full revolution of this motor.
    • Method Detail

      • drive

        public void drive​(double speed)
        Starts moving the motor at a given speed.
        Parameters:
        speed - Determines the speed at which the motor should move.
      • stopMoving

        public void stopMoving()
        Stop the movement of the motor.
      • close

        public void close()
        Closes the internal DcMotor device. THIS SHOULD BE CALLED WHEN MOTORS ARE DONE BEING USED!
        Specified by:
        close in interface java.lang.AutoCloseable