<commit_before>package ev3dev.actuators.lego.motors;

import ev3dev.hardware.EV3DevMotorDevice;
import ev3dev.sensors.Battery;
import lejos.hardware.port.Port;
import lejos.robotics.RegulatedMotor;
import lejos.robotics.RegulatedMotorListener;
import lejos.utility.Delay;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Abstraction for a Regulated motors motors.
 * The basic control methods are:
 *  <code>forward, backward, reverseDirection, stop</code>
 * and <code>flt</code>. To set each motors's velocity, use {@link #setSpeed(int)
 * <code>setSpeed  </code> }.
 * The maximum velocity of the motors is limited by the battery voltage and load.
 * With no load, the maximum degrees per second is about 100 times the voltage
 * (for the large EV3 motors).  <br>
 * The velocity is regulated by comparing the tacho count with velocity times elapsed
 * time, and adjusting motors power to keep these closely matched. Changes in velocity
 * will be made at the rate specified via the
 * <code> setAcceleration(int acceleration)</code> method.
 * The methods <code>rotate(int angle) </code> and <code>rotateTo(int ange)</code>
 * use the tachometer to control the position at which the motors stops, usually within 1 degree
 * or 2.<br>
 *  <br> <b> Listeners.</b>  An object implementing the {@link lejos.robotics
 * <code> RegulatedMotorListener </code> } interface  may register with this class.
 * It will be informed each time the motors starts or stops.
 * <br> <b>Stall detection</b> If a stall is detected or if for some other reason
 * the speed regulation fails, the motors will stop, and
 * <code>isStalled()</code >  returns <b>true</b>.
 * <br>Motors will hold their position when stopped. If this is not what you require use
 * the flt() method instead of stop().
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public abstract class BaseRegulatedMotor extends EV3DevMotorDevice implements RegulatedMotor {

    private static final Logger log = org.slf4j.LoggerFactory.getLogger(BaseRegulatedMotor.class);

    // Following should be set to the max SPEED (in deg/sec) of the motor when free running and powered by 9V
    protected final int MAX_SPEED_AT_9V;

    private int speed = 360;
    protected int acceleration = 6000;

    private boolean regulationFlag = true;

    private final List<RegulatedMotorListener> listenerList = Collections.synchronizedList(new ArrayList());

    /**
     * Constructor
     * @param motorPort motor port
     * @param moveP moveP
     * @param moveI moveI
     * @param moveD moveD
     * @param holdP holdP
     * @param holdI holdI
     * @param holdD holdD
     * @param offset offset
     * @param maxSpeed maxSpeed
     */
    public BaseRegulatedMotor(final Port motorPort, float moveP, float moveI, float moveD,
                              float holdP, float holdI, float holdD, int offset, int maxSpeed) {

        if(log.isInfoEnabled())
            log.info("Configuring motor connected on Port: {}", motorPort.getName());

        MAX_SPEED_AT_9V = maxSpeed;
        final String port = this.getMotorPort(motorPort);

        if(log.isDebugEnabled())
            log.debug("Detecting motor on port: {}", port);
        this.detect(LEGO_PORT, port);
        if(log.isDebugEnabled())
            log.debug("Setting port in mode: {}", TACHO_MOTOR);
        this.setStringAttribute(MODE, TACHO_MOTOR);
        Delay.msDelay(500);
        this.detect(TACHO_MOTOR, port);<commit_msg>Removing compilation warning<commit_after>package ev3dev.actuators.lego.motors;

import ev3dev.hardware.EV3DevMotorDevice;
import ev3dev.sensors.Battery;
import lejos.hardware.port.Port;
import lejos.robotics.RegulatedMotor;
import lejos.robotics.RegulatedMotorListener;
import lejos.utility.Delay;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Abstraction for a Regulated motors motors.
 * The basic control methods are:
 *  <code>forward, backward, reverseDirection, stop</code>
 * and <code>flt</code>. To set each motors's velocity, use {@link #setSpeed(int)
 * <code>setSpeed  </code> }.
 * The maximum velocity of the motors is limited by the battery voltage and load.
 * With no load, the maximum degrees per second is about 100 times the voltage
 * (for the large EV3 motors).  <br>
 * The velocity is regulated by comparing the tacho count with velocity times elapsed
 * time, and adjusting motors power to keep these closely matched. Changes in velocity
 * will be made at the rate specified via the
 * <code> setAcceleration(int acceleration)</code> method.
 * The methods <code>rotate(int angle) </code> and <code>rotateTo(int ange)</code>
 * use the tachometer to control the position at which the motors stops, usually within 1 degree
 * or 2.<br>
 *  <br> <b> Listeners.</b>  An object implementing the {@link lejos.robotics
 * <code> RegulatedMotorListener </code> } interface  may register with this class.
 * It will be informed each time the motors starts or stops.
 * <br> <b>Stall detection</b> If a stall is detected or if for some other reason
 * the speed regulation fails, the motors will stop, and
 * <code>isStalled()</code >  returns <b>true</b>.
 * <br>Motors will hold their position when stopped. If this is not what you require use
 * the flt() method instead of stop().
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>ña Moral
 */
public abstract class BaseRegulatedMotor extends EV3DevMotorDevice implements RegulatedMotor {

    private static final Logger log = org.slf4j.LoggerFactory.getLogger(BaseRegulatedMotor.class);

    // Following should be set to the max SPEED (in deg/sec) of the motor when free running and powered by 9V
    protected final int MAX_SPEED_AT_9V;

    private int speed = 360;
    protected int acceleration = 6000;

    private boolean regulationFlag = true;

    private final List<RegulatedMotorListener> listenerList;

    /**
     * Constructor
     * @param motorPort motor port
     * @param moveP moveP
     * @param moveI moveI
     * @param moveD moveD
     * @param holdP holdP
     * @param holdI holdI
     * @param holdD holdD
     * @param offset offset
     * @param maxSpeed maxSpeed
     */
    public BaseRegulatedMotor(final Port motorPort, float moveP, float moveI, float moveD,
                              float holdP, float holdI, float holdD, int offset, int maxSpeed) {

        List<RegulatedMotorListener> list = new ArrayList<>();
        listenerList = Collections.synchronizedList(list);

        if(log.isInfoEnabled())
            log.info("Configuring motor connected on Port: {}", motorPort.getName());

        MAX_SPEED_AT_9V = maxSpeed;
        final String port = this.getMotorPort(motorPort);

        if(log.isDebugEnabled())
            log.debug("Detecting motor on port: {}", port);
        this.detect(LEGO_PORT, port);
        if(log.isDebugEnabled())
            log.debug("Setting port in mode: {}", TACHO_MOTOR);
        this.setStringAttribute(MODE, TACHO_MOTOR);
        Delay.msDelay(500);
        this.detect(TACHO_MOTOR, port);
{'fraction_non_alphanumeric': 0.09387241186345831, 'fraction_numerical': 0.007274762171236709, 'mean_word_length': 3.5477099236641223, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563674', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2065, 'n_words': 740}