-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrivetrain.java
More file actions
74 lines (59 loc) · 2.6 KB
/
Copy pathDrivetrain.java
File metadata and controls
74 lines (59 loc) · 2.6 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot.subsystems;
import com.revrobotics.PersistMode;
import com.revrobotics.ResetMode;
import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.config.SparkMaxConfig;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.SparkLowLevel.MotorType;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class Drivetrain extends SubsystemBase {
public final SparkMax frontLeft;
public final SparkMax frontRight;
// public final SparkMax backLeft;
// public final SparkMax backRight;
public DifferentialDrive drive;
/** Creates a new Drivetrain. */
public Drivetrain() {
frontLeft = new SparkMax(4, MotorType.kBrushed);
// backLeft = new SparkMax(4, MotorType.kBrushed);
frontRight = new SparkMax(1, MotorType.kBrushed);
// backRight = new SparkMax(2, MotorType.kBrushed);
SparkMaxConfig frontLeftConfig = new SparkMaxConfig();
frontLeftConfig.idleMode(IdleMode.kBrake);
frontLeftConfig.inverted(false);
frontLeft.configure(frontLeftConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
SparkMaxConfig backLeftConfig = new SparkMaxConfig();
backLeftConfig.idleMode(IdleMode.kBrake);
backLeftConfig.inverted(false);
backLeftConfig.follow(frontLeft.getDeviceId());
//backLeft.configure(backLeftConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
SparkMaxConfig frontRightConfig = new SparkMaxConfig();
frontRightConfig.idleMode(IdleMode.kBrake);
frontRightConfig.inverted(false);
frontRight.configure(frontRightConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
SparkMaxConfig backRightConfig = new SparkMaxConfig();
backRightConfig.idleMode(IdleMode.kBrake);
backRightConfig.inverted(false);
backRightConfig.follow(frontRight.getDeviceId());
//backRight.configure(backRightConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
drive = new DifferentialDrive(frontLeft, frontRight);
}
public void drive (double ySpeed, double rotSpeed){
if (Math.abs(rotSpeed) <= 0.05) {
drive.tankDrive(ySpeed,-0.7*ySpeed);
} else {
drive.tankDrive(rotSpeed, 0.7*rotSpeed);
}
}
public void stop() {
drive.tankDrive(0, 0);
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
}