<commit_before>// RobotBuilder Version: 1.5
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.


package org.usfirst.frc4915.MecanumDrive.commands;

import java.util.Arrays;
import java.util.List;

import org.usfirst.frc4915.MecanumDrive.Robot;
import org.usfirst.frc4915.MecanumDrive.RobotMap;

import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.command.Command;

/**
 *
 */
public class  MoveStraightGivenDistanceCommand extends Command {
	public static List <CANTalon> motors;
	public double inputDistance;

    public MoveStraightGivenDistanceCommand(double inputDistance) {
    	requires(Robot.mecanumDriveControls1); 
    	this.inputDistance = inputDistance;
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);

        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    	 motors = Arrays.asList(RobotMap.mecanumDriveControls1LeftFront1, 
    			RobotMap.mecanumDriveControls1LeftRear2, 
    			RobotMap.mecanumDriveControls1RightFront3,
    			RobotMap.mecanumDriveControls1RightRear4 );
    }
    
    double getDistanceForMotor(CANTalon motor, long elapsed){
    	int ticksPerRevolution = 1000;
    	double circumferenceOfWheel = 6*Math.PI;
    	int inchesPerFoot = 12;
    	return motor.getSpeed()*elapsed/ticksPerRevolution*circumferenceOfWheel/inchesPerFoot;
    }
    
    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	if (inputDistance < 0)
    		Robot.mecanumDriveControls1.driveStraight(-0.2);
    	else 
    		Robot.mecanumDriveControls1.driveStraight(0.2);
    	long elapsed = 0;
    	long startTime = System.currentTimeMillis();
    	long endTime = 0;
    	double distance = 0;
    	while(Math.abs(distance) < Math.abs(inputDistance)){
    		try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    		endTime = System.currentTimeMillis();
    		elapsed = endTime - startTime;
    		double distanceSinceElapsed = 0;
    		for(CANTalon motor : motors){
    			double distanceForMotor = getDistanceForMotor (motor, elapsed);
    			distanceSinceElapsed = Math.max(distanceForMotor, distanceSinceElapsed);
    		}
    		distance+=distanceSinceElapsed;
    		startTime=endTime;
    	}
    	end();
    	
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    	Robot.mecanumDriveControls1.getRobotDrive().stopMotor(); 
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    	end();
    }
}<commit_msg>Added comments and changed the method of waiting in the MoveStraight command<commit_after>// RobotBuilder Version: 1.5
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.


package org.usfirst.frc4915.MecanumDrive.commands;

import java.util.Arrays;
import java.util.List;

import org.usfirst.frc4915.MecanumDrive.Robot;
import org.usfirst.frc4915.MecanumDrive.RobotMap;

import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.command.Command;

/**
 *
 */
public class  MoveStraightGivenDistanceCommand extends Command {
	public static List <CANTalon> motors;
	public double inputDistance;

    public MoveStraightGivenDistanceCommand(double inputDistance) {
    	requires(Robot.mecanumDriveControls1); 
    	this.inputDistance = inputDistance;
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);

        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    	 motors = Arrays.asList(RobotMap.mecanumDriveControls1LeftFront1, 
    			RobotMap.mecanumDriveControls1LeftRear2, 
    			RobotMap.mecanumDriveControls1RightFront3,
    			RobotMap.mecanumDriveControls1RightRear4 );
    }
    // calculates the distance traveled using the wheel circumference and the number of wheel rotations. 
    double getDistanceForMotor(CANTalon motor, long elapsed){
    	int ticksPerRevolution = 1000;
    	double circumferenceOfWheel = 6*Math.PI;
    	int inchesPerFoot = 12;
    	return motor.getSpeed()*elapsed/ticksPerRevolution*circumferenceOfWheel/inchesPerFoot;
    }
    
    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	// This loop allows for a negative input that will have the robot run backwards. 
    	if (inputDistance < 0)
    		Robot.mecanumDriveControls1.driveStraight(-0.2);
    	else 
    		Robot.mecanumDriveControls1.driveStraight(0.2);
    	// Creates variables for use in determining the time so we can compute the distance traveled 
    	long elapsed = 0;
    	long startTime = System.currentTimeMillis();
    	long endTime = 0;
    	// creates a variable to keep track of the time. 
    	double distance = 0;
    	// creates two variables for use in determining the wait. 
    	double wait = System.currentTimeMillis();
    	double time = 0;
    	// creates a loop to track the distance traveled
    	while(Math.abs(distance) < Math.abs(inputDistance)){
    		if (time < 100){
    			time = System.currentTimeMillis() - wait;}
    		else
    			// uses the time to determine the distance traveled since the last time the robot was sampled.
    			endTime = System.currentTimeMillis();
    			elapsed = endTime - startTime;
    			double distanceSinceElapsed = 0;
    			for(CANTalon motor : motors){
    				double distanceForMotor = getDistanceForMotor (motor, elapsed);
    				distanceSinceElapsed = Math.max(distanceForMotor, distanceSinceElapsed);
    		}
    		distance+=distanceSinceElapsed;
    		startTime=endTime;
    	}
    	end();
    	
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    	Robot.mecanumDriveControls1.getRobotDrive().stopMotor(); 
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    	end();
    }
}
{'fraction_non_alphanumeric': 0.0760693015701137, 'fraction_numerical': 0.012317271250676774, 'mean_word_length': 3.1816638370118846, 'pattern_counts': {'":': 0, '<': 10, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837336', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2196, 'n_words': 647}