-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultDrive.java
More file actions
131 lines (103 loc) · 4.05 KB
/
DefaultDrive.java
File metadata and controls
131 lines (103 loc) · 4.05 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot.commands;
import java.util.List;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.controller.PIDController;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.CommandGroup;
import edu.wpi.first.wpilibj.geometry.Pose2d;
import edu.wpi.first.wpilibj.geometry.Rotation2d;
import edu.wpi.first.wpilibj.geometry.Translation2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.trajectory.Trajectory;
import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
import frc.robot.Constants;
import frc.robot.Constants.AutoConstants;
import frc.robot.Constants.SwerveDriveConstants;
import frc.robot.subsystems.*;
public class DefaultDrive extends Command {
private final SwerveDrive m_drive;
private final Joystick m_joystick;
private double m_xSpeed, m_ySpeed, m_rot;
private final boolean m_fieldRelative;
private double heading;
private PIDController pid = new PIDController(0.05, 0, 0.01);
private JoystickButton butX;
private boolean slow;
private int mode;
private double multiplier;
/**
* Creates a new DefaultDrive.
*
* @param subsystem The drive subsystem this command will run on
* @param driver The joystick to be used for calculations in speed and rotation
* @param multiplier The mode of the robot -- multiplied with x, y, and rot speed
*/
public DefaultDrive(SwerveDrive subsystem, Joystick driver, double multiplier) {
requires(subsystem);
// Use addRequirements() here to declare subsystem dependencies.
m_drive = subsystem;
m_joystick = driver;
m_xSpeed = 0;
m_ySpeed = 0;
m_rot = 0;
m_fieldRelative = true;
this.multiplier = multiplier;
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
heading = m_drive.getAngle().getDegrees();
butX = new JoystickButton(m_joystick, 2);
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
// deadzone
SmartDashboard.putNumber("MODE", mode);
if (m_drive.getGyroReset()) {
heading = m_drive.getAngle().getDegrees();
m_drive.setGyroReset(false);
}
m_xSpeed = 0;
m_ySpeed = 0;
m_rot = 0;
// y should be 0 when robot is facing ^ (and intake is facing driver station)
// x should be negative when intake facing driver station %
if (Math.abs(m_joystick.getRawAxis(0)) > 0.1) {
m_ySpeed = -m_joystick.getRawAxis(0) * 0.5 * multiplier * Constants.SwerveDriveConstants.kMaxSpeedMetersPerSecond;
}
if (Math.abs(m_joystick.getRawAxis(1)) > 0.1) {
m_xSpeed = -m_joystick.getRawAxis(1) * 0.5 * multiplier * Constants.SwerveDriveConstants.kMaxSpeedMetersPerSecond;
}
if (Math.abs(m_joystick.getRawAxis(4)) > 0.2) {
m_rot = m_joystick.getRawAxis(4) * 0.5 * multiplier * (Math.PI);
}
double curHead = m_drive.getAngle().getDegrees();
if (m_rot == 0) {
m_drive.drive(m_xSpeed, m_ySpeed, pid.calculate(curHead, heading), m_fieldRelative);
} else {
m_drive.drive(m_xSpeed, m_ySpeed, m_rot, m_fieldRelative);
heading = m_drive.getAngle().getDegrees();
}
// fill with correct button
if (m_joystick.getRawButtonPressed(6)) {
// to zero all wheels
}
// sidestep
if (m_joystick.getRawButtonPressed(1)) {
}
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}