<commit_before>package org.erhsroboticsclub.robo2013;

import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import org.erhsroboticsclub.robo2013.utilities.MathX;
import org.erhsroboticsclub.robo2013.utilities.Messenger;
import org.erhsroboticsclub.robo2013.utilities.PIDControllerX;

public class LinearAccelerator {

    private CANJaguar primaryWheel;
    private CANJaguar secondaryWheel;
    private CANJaguar elevatorMotor;
    private PWM loadArmM1, loadArmM2;
    private DigitalInput limitSwitch;
    public AnalogChannel anglePotentiometer;
    private Messenger msg = new Messenger();
    private PIDControllerX pid;    
    private double angle = 31;
    
    public static final double AUTO_SHOOT_SPEED = -.8;    

    public LinearAccelerator() {
        loadArmM1 = new PWM(RoboMap.LOAD_ARM_MOTOR1);
        loadArmM2 = new PWM(RoboMap.LOAD_ARM_MOTOR2);
        limitSwitch = new DigitalInput(RoboMap.LIMIT_SWITCH);
        anglePotentiometer = new AnalogChannel(RoboMap.LAUNCHER_ANGLE_POT);
        pid = new PIDControllerX(RoboMap.LAUNCHER_PID_P, RoboMap.LAUNCHER_PID_I, 
                                 RoboMap.LAUNCHER_PID_D);
        pid.capOutput(RoboMap.LAUNCH_PID_MIN, RoboMap.LAUNCH_PID_MAX);
        
        try {
            primaryWheel = new CANJaguar(RoboMap.PRIMARY_LAUNCH_MOTOR);
            secondaryWheel = new CANJaguar(RoboMap.SECONDARY_LAUNCH_MOTOR);
            elevatorMotor = new CANJaguar(RoboMap.ELEVATOR_MOTOR);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Sets the speed of both launch wheels separately
     * @param primary The speed of the first launch wheel
     * @param secondary The speed of the second launch wheel
     */
    public void setWheels(double primary, double secondary) {
        try {
            primaryWheel.setX(primary);
            secondaryWheel.setX(secondary);
        } catch (CANTimeoutException e) {
        }
    }
    
    /**
     * Sets both launch wheels to the same speed
     * @param speed The speed for both launch wheels
     */
    public void setWheels(double speed) {
        this.setWheels(speed, speed);
    }

    /**
     * Launches a Frisby
     */
    public void launch() {
        loadArmM1.setRaw(1);
        loadArmM2.setRaw(1);
        try {
            double start  = System.currentTimeMillis();
            while(System.currentTimeMillis() - start < 500) {
                setWheels(LinearAccelerator.AUTO_SHOOT_SPEED);
                adjustAngle();
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        double time = System.currentTimeMillis();
        while (true) {
            if (!limitSwitch.get()) {
                break;
            }
            // stops the launch if it has taken more than 10 seconds
            if (System.currentTimeMillis() - time > 10000) {
                msg.printLn("Limit switch not found!");
                msg.printLn("Stopping launch...");
                break;
            }
            setWheels(LinearAccelerator.AUTO_SHOOT_SPEED);
            adjustAngle();
        }
        loadArmM1.setRaw(127);
        loadArmM2.setRaw(127);
    }
    
    /**
     * Runs the PID loop for the specified amount of time
     * @param sleep The amount of time in milliseconds to run the PID 
     */<commit_msg>changing shoot timeout to 5 seconds<commit_after>package org.erhsroboticsclub.robo2013;

import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import org.erhsroboticsclub.robo2013.utilities.MathX;
import org.erhsroboticsclub.robo2013.utilities.Messenger;
import org.erhsroboticsclub.robo2013.utilities.PIDControllerX;

public class LinearAccelerator {

    private CANJaguar primaryWheel;
    private CANJaguar secondaryWheel;
    private CANJaguar elevatorMotor;
    private PWM loadArmM1, loadArmM2;
    private DigitalInput limitSwitch;
    public AnalogChannel anglePotentiometer;
    private Messenger msg = new Messenger();
    private PIDControllerX pid;    
    private double angle = 31;
    
    public static final double AUTO_SHOOT_SPEED = -.8;    

    public LinearAccelerator() {
        loadArmM1 = new PWM(RoboMap.LOAD_ARM_MOTOR1);
        loadArmM2 = new PWM(RoboMap.LOAD_ARM_MOTOR2);
        limitSwitch = new DigitalInput(RoboMap.LIMIT_SWITCH);
        anglePotentiometer = new AnalogChannel(RoboMap.LAUNCHER_ANGLE_POT);
        pid = new PIDControllerX(RoboMap.LAUNCHER_PID_P, RoboMap.LAUNCHER_PID_I, 
                                 RoboMap.LAUNCHER_PID_D);
        pid.capOutput(RoboMap.LAUNCH_PID_MIN, RoboMap.LAUNCH_PID_MAX);
        
        try {
            primaryWheel = new CANJaguar(RoboMap.PRIMARY_LAUNCH_MOTOR);
            secondaryWheel = new CANJaguar(RoboMap.SECONDARY_LAUNCH_MOTOR);
            elevatorMotor = new CANJaguar(RoboMap.ELEVATOR_MOTOR);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Sets the speed of both launch wheels separately
     * @param primary The speed of the first launch wheel
     * @param secondary The speed of the second launch wheel
     */
    public void setWheels(double primary, double secondary) {
        try {
            primaryWheel.setX(primary);
            secondaryWheel.setX(secondary);
        } catch (CANTimeoutException e) {
        }
    }
    
    /**
     * Sets both launch wheels to the same speed
     * @param speed The speed for both launch wheels
     */
    public void setWheels(double speed) {
        this.setWheels(speed, speed);
    }

    /**
     * Launches a Frisby
     */
    public void launch() {
        loadArmM1.setRaw(1);
        loadArmM2.setRaw(1);
        try {
            double start  = System.currentTimeMillis();
            while(System.currentTimeMillis() - start < 500) {
                setWheels(LinearAccelerator.AUTO_SHOOT_SPEED);
                adjustAngle();
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        double time = System.currentTimeMillis();
        while (true) {
            if (!limitSwitch.get()) {
                break;
            }
            // stops the launch if it has taken more than 10 seconds
            if (System.currentTimeMillis() - time > 5000) {
                msg.printLn("Limit switch not found!");
                msg.printLn("Stopping launch...");
                break;
            }
            setWheels(LinearAccelerator.AUTO_SHOOT_SPEED);
            adjustAngle();
        }
        loadArmM1.setRaw(127);
        loadArmM2.setRaw(127);
    }
    
    /**
     * Runs the PID loop for the specified amount of time
     * @param sleep The amount of time in milliseconds to run the PID 
     */
{'fraction_non_alphanumeric': 0.08402184567987676, 'fraction_numerical': 0.01316342248984736, 'mean_word_length': 2.22583559168925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '674397', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2203, 'n_words': 469}