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