Package com.pocolifo.robobase.motor
Class Motor
java.lang.Object
com.pocolifo.robobase.motor.Motor
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
Wheel
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 -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
motor
public final com.qualcomm.robotcore.hardware.DcMotor motorTheDcMotor
associated with this motor. -
tickCount
public final double tickCountThe 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 aMotor
. Also uses an encoder. Todo: add interesting methods incorporating encoder- Parameters:
motor
- TheDcMotor
that is associated with thisMotor
.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 internalDcMotor
device. THIS SHOULD BE CALLED WHEN MOTORS ARE DONE BEING USED!- Specified by:
close
in interfaceAutoCloseable
-