generated from DeepBlueRobotics/EmptyProject2024
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RobotContainer.java
161 lines (142 loc) · 6.22 KB
/
RobotContainer.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 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 org.carlmontrobotics;
//199 files
// import org.carlmontrobotics.subsystems.*;
import org.carlmontrobotics.commands.*;
import static org.carlmontrobotics.Constants.OI;
import static org.carlmontrobotics.Constants.Arm.*;
import org.carlmontrobotics.Constants.OI;
import org.carlmontrobotics.subsystems.Arm;
import org.carlmontrobotics.Constants;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController.Axis;
import edu.wpi.first.wpilibj.XboxController.Button;
//commands
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.PrintCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
//control bindings
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.POVButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
public class RobotContainer {
// defaultCommands: elevator, dt
// (pass in controller!)
// set up subsystems / controllers / limelight
// 1. using GenericHID allows us to use different kinds of controllers
// 2. Use absolute paths from constants to reduce confusion
public final GenericHID driverController = new GenericHID(OI.Driver.port);
public final GenericHID manipulatorController = new GenericHID(OI.Manipulator.port);
public Arm arm = new Arm();
public RobotContainer() {
setDefaultCommands();
setBindingsDriver();
setBindingsManipulator();
}
private void setDefaultCommands() {
// drivetrain.setDefaultCommand(new TeleopDrive(
// drivetrain,
// () -> ProcessedAxisValue(driverController, Axis.kLeftY)),
// () -> ProcessedAxisValue(driverController, Axis.kLeftX)),
// () -> ProcessedAxisValue(driverController, Axis.kRightX)),
// () -> driverController.getRawButton(OI.Driver.slowDriveButton)
// ));
arm.setDefaultCommand(new ArmTeleop(arm, () -> inputProcessing(getStickValue(manipulatorController, Axis.kLeftY))));
}
private void setBindingsDriver() {
new JoystickButton(driverController, Button.kX.value)
.whileTrue(arm.sysIdQuasistatic(SysIdRoutine.Direction.kForward));
new JoystickButton(driverController, Button.kY.value)
.whileTrue(arm.sysIdQuasistatic(SysIdRoutine.Direction.kReverse));
new JoystickButton(driverController, Button.kB.value).whileTrue(arm.sysIdDynamic(SysIdRoutine.Direction.kForward));
new JoystickButton(driverController, Button.kA.value).whileTrue(arm.sysIdDynamic(SysIdRoutine.Direction.kReverse));
// 4 cardinal directions on arrowpad
// slowmode toggle on trigger
// 3 cardinal directions on letterpad
}
private void setBindingsManipulator() {
// intake/outtake on triggers
// Left trigger will be intake whilst right trigger will be outtake
// 3 setpositions of arm on letterpad
// Up is Speaker, down is ground, right is Amp
// right joystick used for manual arm control
// COMMENT THESE OUT DURING SYSID TESTING
// Speaker Buttons
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_SPEAKER_POD_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(PODIUM_ANGLE_RAD);
}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_SPEAKER_NEXT_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(SUBWOFFER_ANGLE_RAD);
}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_SPEAKER_SAFE_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(SAFE_ZONE_ANGLE_RAD);
}));
// Amp and Intake Buttons
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_AMP_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(AMP_ANGLE_RAD);
}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_GROUND_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(INTAKE_ANGLE_RAD);
}));
// Cimber Buttons
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_CLIMBER_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(CLIMBER_UP_ANGLE_RAD);
}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.LOWER_TO_CLIMBER_BUTTON)
.onTrue(new InstantCommand(() -> {
arm.setArmTarget(CLIMBER_DOWN_ANGLE_RAD);
}));
// ----------------------------------------------------------------------
}
public Command getAutonomousCommand() {
return Commands.print("No autonomous command configured");
}
/**
* Flips an axis' Y coordinates upside down, but only if the select axis is a
* joystick axis
*
* @param hid The controller/plane joystick the axis is on
* @param axis The processed axis
* @return The processed value.
*/
private double getStickValue(GenericHID hid, Axis axis) {
return hid.getRawAxis(axis.value) * (axis == Axis.kLeftY || axis == Axis.kRightY ? -1 : 1);
}
/**
* Processes an input from the joystick into a value between -1 and 1,
* sinusoidally instead of linearly
*
* @param value The value to be processed.
* @return The processed value.
*/
private double inputProcessing(double value) {
double processedInput;
// processedInput =
// (((1-Math.cos(value*Math.PI))/2)*((1-Math.cos(value*Math.PI))/2))*(value/Math.abs(value));
processedInput = Math.copySign(((1 - Math.cos(value * Math.PI)) / 2) * ((1 - Math.cos(value * Math.PI)) / 2),
value);
return processedInput;
}
/**
* Combines both getStickValue and inputProcessing into a single function for
* processing joystick outputs
*
* @param hid The controller/plane joystick the axis is on
* @param axis The processed axis
* @return The processed value.
*/
private double ProcessedAxisValue(GenericHID hid, Axis axis) {
return inputProcessing(getStickValue(hid, axis));
}
}