@Override
public void autonomousInit() {
- Scheduler.getInstance().add(new TimeDrive(1.5, 0.4));
+ TimeDrive timedrive = new TimeDrive(0.5, 0.2);
+ Scheduler.getInstance().add(timedrive);
}
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
-
+ Robot.getDriveTrain().correctStraightness();
}
@Override
public class DriveStraight extends Command {
double speedL, speedR, tempSpeedR, seconds;
- // double moveR = Robot.getDriveTrain().getLeftSpeed();
- // double moveL = Robot.getDriveTrain().getRightSpeed();
- public DriveStraight(double seconds) {
+ // Max speed at mv of 0.2 (RIGHT)
+ final double maxSpeedOneR = 16.1;
+ // Max speed at mv of 0.4 (RIGHT)
+ final double maxSpeedTwoR = 49;
+ // Max speed at mv of 0.6 (RIGHT)
+ final double maxSpeedThreeR = 75.2;
+ // Max speed at mv of 0.2 (LEFT)
+ final double maxSpeedOneL = 13.8;
+ // Max speed at mv of 0.4 (LEFT)
+ final double maxSpeedTwoL = 46.9;
+ // Max speed at mv of 0.6 (LEFT)
+ final double maxSpeedThreeL = 74;
+
+ public DriveStraight(double seconds, double mv) {
this.seconds = seconds;
requires(Robot.getDriveTrain());
speedL = Robot.getDriveTrain().getLeftSpeed();
@Override
public void execute() {
+ // Motor values for both motors
Double mvR = null, mvL = null;
- final double maxSpeedOneR = 16.1;
- final double maxSpeedTwoR = 49;
- final double maxSpeedThreeR = 75.2;
- final double maxSpeedOneL = 13.8;
- final double maxSpeedTwoL = 46.9;
- final double maxSpeedThreeL = 74;
+
+ // getting speed for both motors and exchanging them
speedL = Robot.getDriveTrain().getLeftSpeed();
speedR = Robot.getDriveTrain().getRightSpeed();
tempSpeedR = speedR;
speedR = speedL;
speedL = tempSpeedR;
+
+ // converting right motor speed to motor value
if (speedR <= maxSpeedOneR) {
mvR = speedR / maxSpeedOneR * 5;
} else if (speedR <= maxSpeedTwoR) {
} else if (speedR <= maxSpeedThreeR) {
mvR = speedR / maxSpeedThreeR * 1.66;
}
+
+ // converting left motor speed to motor value
if (speedL <= maxSpeedOneL) {
mvL = speedL / maxSpeedOneL * 5;
} else if (speedL <= maxSpeedTwoL) {
} else if (speedL <= maxSpeedThreeL) {
mvL = speedL / maxSpeedThreeL * 1.66;
}
+
+ // Setting motors at new motor values
if (mvR != null && mvL != null) {
Robot.getDriveTrain().setMotorValues(mvR, mvL); // we changed move to //
// speed
package org.usfirst.frc.team3501.robot.subsystems;
import org.usfirst.frc.team3501.robot.Constants;
+import org.usfirst.frc.team3501.robot.Robot;
import org.usfirst.frc.team3501.robot.commands.driving.JoystickDrive;
import com.ctre.CANTalon;
setMotorValues(0, 0);
}
+ public void correctStraightness() {
+
+ double speedL, speedR, tempSpeedR;
+
+ // Max speed at mv of 0.2 (RIGHT)
+ final double maxSpeedOneR = 16.1;
+ // Max speed at mv of 0.4 (RIGHT)
+ final double maxSpeedTwoR = 49;
+ // Max speed at mv of 0.6 (RIGHT)
+ final double maxSpeedThreeR = 75.2;
+ // Max speed at mv of 0.2 (LEFT)
+ final double maxSpeedOneL = 13.8;
+ // Max speed at mv of 0.4 (LEFT)
+ final double maxSpeedTwoL = 46.9;
+ // Max speed at mv of 0.6 (LEFT)
+ final double maxSpeedThreeL = 74;
+
+ speedL = Robot.getDriveTrain().getLeftSpeed();
+ speedR = Robot.getDriveTrain().getRightSpeed();
+
+ // Motor values for both motors
+ Double mvR = null, mvL = null;
+
+ // NOTE: Make threshold. Robot tends to go haywire.
+ // getting speed for both motors and exchanging them
+ speedL = Robot.getDriveTrain().getLeftSpeed();
+ speedR = Robot.getDriveTrain().getRightSpeed();
+ tempSpeedR = speedR;
+ speedR = speedL;
+ speedL = tempSpeedR;
+
+ // converting right motor speed to motor value
+ if (speedR <= maxSpeedOneR) {
+ mvR = speedR / maxSpeedOneR * 5;
+ } else if (speedR <= maxSpeedTwoR) {
+ mvR = speedR / maxSpeedTwoR * 2.5;
+ } else if (speedR <= maxSpeedThreeR) {
+ mvR = speedR / maxSpeedThreeR * 1.66;
+ }
+
+ // converting left motor speed to motor value
+ if (speedL <= maxSpeedOneL) {
+ mvL = speedL / maxSpeedOneL * 5;
+ } else if (speedL <= maxSpeedTwoL) {
+ mvL = speedL / maxSpeedTwoL * 2.5;
+ } else if (speedL <= maxSpeedThreeL) {
+ mvL = speedL / maxSpeedThreeL * 1.66;
+ }
+
+ // Setting motors at new motor values
+ if (mvR != null && mvL != null) {
+ Robot.getDriveTrain().setMotorValues(mvR, mvL); // we changed move to //
+ } // speed
+
+ }
+
public double getFrontLeftMotorVal() {
return frontLeft.get();
}