move instantiation of physical components to map
[3501/3501-spark-go] / src / org / usfirst / frc / team3501 / robot / subsystems / Drivetrain.java
CommitLineData
b449387d
LH
1package org.usfirst.frc.team3501.robot.subsystems;
2
3import org.usfirst.frc.team3501.robot.RobotMap;
3e4790a8 4import org.usfirst.frc.team3501.robot.commands.DriveWithJoysticks;
b449387d 5
b449387d
LH
6import edu.wpi.first.wpilibj.RobotDrive;
7import edu.wpi.first.wpilibj.command.Subsystem;
8
9public class Drivetrain extends Subsystem {
10
56625a79 11 private final RobotDrive robotDrive;
b449387d
LH
12
13 public Drivetrain() {
b449387d
LH
14
15 robotDrive = new RobotDrive(
56625a79 16 RobotMap.frontLeft, RobotMap.rearLeft,
17 RobotMap.frontRight, RobotMap.rearRight);
b449387d
LH
18 }
19
20 public void drive(double forward, double twist) {
21 if (Math.abs(forward) < RobotMap.MIN_DRIVE_JOYSTICK_INPUT)
22 forward = 0;
3cd438bd 23 if (Math.abs(twist) < RobotMap.MIN_DRIVE_JOYSTICK_INPUT)
b449387d
LH
24 twist = 0;
25
26 robotDrive.arcadeDrive(
27 RobotMap.MAX_DRIVE_SPEED * adjust(forward),
28 RobotMap.MAX_DRIVE_SPEED * adjust(twist),
29 false);
30 }
31
e81578e3
LH
32 public void driveRaw(double forward, double twist) {
33 robotDrive.arcadeDrive(forward, twist, false);
34 }
35
b449387d
LH
36 public void goForward(double speed) {
37 robotDrive.arcadeDrive(speed, 0);
38 }
39
40 public void stop() {
41 robotDrive.arcadeDrive(0, 0);
42 }
43
44 // output is avg of `x` and `sqrt(x)`
45 private double adjust(double x) {
46 return (x + Math.signum(x) * Math.sqrt(Math.abs(x))) / 2;
47 }
48
3e4790a8
LH
49 public void initDefaultCommand() {
50 setDefaultCommand(new DriveWithJoysticks());
51 }
b449387d 52}