-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriveTrain.java
56 lines (47 loc) · 1.7 KB
/
DriveTrain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.usfirst.frc.team4541.robot.subsystems;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SPI;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.usfirst.frc.team4541.robot.commands.DriveWithJoystick;
import com.ctre.CANTalon;
import com.kauailabs.navx.frc.AHRS;
/**
* The DriveTrain subsystem incorporates the sensors and actuators attached to
* the robots chassis. This includes four drive motors and a gyro.
*/
public class DriveTrain extends Subsystem {
private CANTalon frontLeftMotor = new CANTalon(0);
private CANTalon rearLeftMotor = new CANTalon(1);
private CANTalon frontRightMotor = new CANTalon(2);
private CANTalon rearRightMotor = new CANTalon(3);
private RobotDrive drive = new RobotDrive(frontLeftMotor, rearLeftMotor, frontRightMotor, rearRightMotor);
private AHRS gyro = new AHRS(SPI.Port.kMXP);
public DriveTrain() {
super();
}
/** When no other command is running let the operator drive around using the joystick*/
@Override
public void initDefaultCommand() {
setDefaultCommand(new DriveWithJoystick());
}
/**The log method puts interesting information to the SmartDashboard.*/
public void log() {
SmartDashboard.putNumber("Gyro", gyro.getYaw());
}
public void drive(double xrate, double yrate, double rrate){
//for 2017 robot may have to map the values differently//
double a=yrate;
yrate = rrate;
rrate = a;
drive.mecanumDrive_Cartesian(xrate, yrate, rrate, gyro.getYaw());
}
/* Method to get current robot heading*/
public double getGyroYaw() {
return gyro.getYaw();
}
/**Reset the robots sensors to the zero states.*/
public void reset() {
gyro.reset();
}
}