Class Motor

java.lang.Object
com.pocolifo.robobase.motor.Motor
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
Wheel

public class Motor extends Object implements 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
    final com.qualcomm.robotcore.hardware.DcMotor
    The DcMotor associated with this motor.
    final double
    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, double tickCount)
    Instantiate a Motor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the internal DcMotor device.
    void
    drive(double speed)
    Starts moving the motor at a given speed.
    double
    gets the number of motor rotations
    int
    Gets the current encoder position
    void
    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 Details

    • motor

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

      public final double 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 Details

    • Motor

      public Motor(com.qualcomm.robotcore.hardware.DcMotor motor, double tickCount)
      Instantiate a Motor. Also uses an encoder. Todo: add interesting methods incorporating encoder
      Parameters:
      motor - The DcMotor that is associated with this Motor.
      tickCount - The number of ticks for a full revolution of this motor.
  • Method Details

    • 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.
    • getPosition

      public int getPosition()
      Gets the current encoder position
    • getMotorRotations

      public double getMotorRotations()
      gets the number of motor rotations
    • close

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