All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.hardware.motor.UnregulatedMotor Maven / Gradle / Ivy

Go to download

leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.

The newest version!
package lejos.hardware.motor;

import lejos.hardware.port.Port;
import lejos.hardware.port.TachoMotorPort;
import lejos.robotics.Encoder;
import lejos.robotics.EncoderMotor;

/**
 * Abstraction for an NXT motor with no speed regulation.
 * 
 */
public class UnregulatedMotor extends BasicMotor implements EncoderMotor {
    protected Encoder encoderPort;

    /**
     * Create an instance of a NXTMotor using the specified motor port and
     * PWM operating mode.
     * @param port The motor port that the motor will be attached to.
     * @param PWMMode see {@link lejos.hardware.port.BasicMotorPort#PWM_FLOAT} and see {@link lejos.hardware.port.BasicMotorPort#PWM_BRAKE}
     */
    public UnregulatedMotor(Port port, int PWMMode)
    {
        this(port.open(TachoMotorPort.class), PWMMode);
        releaseOnClose(this.port);
    }
    
    /**
     * Create an instance of a NXTMotor using the specified motor port the
     * PWM operating mode will be PWM_BREAK {@link lejos.hardware.port.BasicMotorPort#PWM_BRAKE}
     * @param port The motor port that the motor will be attached to.
     */
    public UnregulatedMotor(Port port)
    {
        this(port, TachoMotorPort.PWM_BRAKE);
    }
    
    /**
     * Create an instance of a NXTMotor using the specified motor port and
     * PWM operating mode.
     * @param mport The motor port that the motor will be attached to.
     * @param PWMMode see {@link lejos.hardware.port.BasicMotorPort#PWM_FLOAT} and see {@link lejos.hardware.port.BasicMotorPort#PWM_BRAKE}
     */
    public UnregulatedMotor(TachoMotorPort mport, int PWMMode)
    {
        this.port = mport;
        // We use extra var to avoid cost of a cast check later
        encoderPort = mport;
        mport.setPWMMode(PWMMode);
    }
    
    /**
     * Create an instance of a NXTMotor using the specified motor port the
     * PWM operating mode will be PWM_BREAK {@link lejos.hardware.port.BasicMotorPort#PWM_BRAKE}
     * @param port The motor port that the motor will be attached to.
     */
    public UnregulatedMotor(TachoMotorPort port)
    {
        this(port, TachoMotorPort.PWM_BRAKE);
    }
    
    public int getTachoCount()
    {
        return encoderPort.getTachoCount();
    }

    public void resetTachoCount()
    {
        encoderPort.resetTachoCount();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy