-
Notifications
You must be signed in to change notification settings - Fork 714
Expand file tree
/
Copy pathRobot.java
More file actions
138 lines (116 loc) · 5.23 KB
/
Copy pathRobot.java
File metadata and controls
138 lines (116 loc) · 5.23 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
132
133
134
135
136
137
138
// 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.wpilib.examples.hatchbotcmdv3;
import org.wpilib.command3.Command;
import org.wpilib.command3.Scheduler;
import org.wpilib.command3.button.CommandGamepad;
import org.wpilib.driverstation.DriverStation;
import org.wpilib.examples.hatchbotcmdv3.commands.Autos;
import org.wpilib.examples.hatchbotcmdv3.mechanisms.DriveMechanism;
import org.wpilib.examples.hatchbotcmdv3.mechanisms.HatchMechanism;
import org.wpilib.framework.TimedRobot;
import org.wpilib.smartdashboard.SendableChooser;
import org.wpilib.smartdashboard.SmartDashboard;
import org.wpilib.system.DataLogManager;
/**
* The methods in this class are called automatically corresponding to each mode, as described in
* the TimedRobot documentation. If you change the name of this class or the package after creating
* this project, you must also update the Main.java file in the project.
*/
public class Robot extends TimedRobot {
/**
* A chooser for autonomous commands. Drivers can choose between different autonomous modes on a
* dashboard before the start of a match.
*/
private final SendableChooser<Command> autonomousChooser = new SendableChooser<>();
// The driver's controller
private final CommandGamepad driverController =
new CommandGamepad(Constants.OIConstants.kDriverControllerPort);
// The robot's mechanisms
private final DriveMechanism robotDrive = new DriveMechanism();
private final HatchMechanism hatchMechanism = new HatchMechanism();
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
public Robot() {
// Configure the button bindings
configureButtonBindings();
// Configure default commands
// Set the default drive command to split-stick arcade drive with forward/backward controlled by
// the left hand, and turning controlled by the right.
robotDrive.setDefaultCommand(
robotDrive.arcadeDrive(
() -> -driverController.getLeftY(), () -> -driverController.getRightX()));
// Add commands to the autonomous command chooser
autonomousChooser.setDefaultOption("Simple Auto", Autos.simpleAuto(robotDrive));
autonomousChooser.addOption("Complex Auto", Autos.complexAuto(robotDrive, hatchMechanism));
// Put the chooser on the dashboard
SmartDashboard.putData("Autonomous", autonomousChooser);
// Start recording to data log
DataLogManager.start();
// Record DS control and joystick data.
// Change to `false` to not record joystick data.
DriverStation.startDataLog(DataLogManager.getLog(), true);
}
/** Use this method to define your button->command mappings. */
private void configureButtonBindings() {
// Grab the hatch when the Circle button is pressed.
driverController.faceRight().onTrue(hatchMechanism.grabHatchCommand());
// Release the hatch when the Square button is pressed.
driverController.faceLeft().onTrue(hatchMechanism.releaseHatchCommand());
// While holding R1, drive at half speed
driverController
.rightBumper()
.onTrue(Command.noRequirements(_ -> robotDrive.setMaxOutput(0.5)).named("Set half speed"))
.onFalse(Command.noRequirements(_ -> robotDrive.setMaxOutput(1)).named("Set full speed"));
}
/**
* This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
* that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {
// Runs the scheduler. This is responsible for polling buttons, running scheduled commands,
// and removing finished or interrupted commands.
// This must be called from the robot's periodic block in order for anything in the
// Command-based framework to work.
Scheduler.getDefault().run();
}
/** This function is called once each time the robot enters Disabled mode. */
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
/** This autonomous runs the autonomous command selected by the {@link #autonomousChooser}. */
@Override
public void autonomousInit() {
Command autonomousCommand = autonomousChooser.getSelected();
// Schedule the autonomous command.
// Because we schedule this command in the autonomous mode, it will be automatically canceled
// when the autonomous mode ends.
if (autonomousCommand != null) {
Scheduler.getDefault().schedule(autonomousCommand);
}
}
/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {}
@Override
public void teleopInit() {}
/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}
@Override
public void utilityInit() {
// Cancel all running commands at the start of utility mode.
Scheduler.getDefault().cancelAll();
}
/** This function is called periodically during utility mode. */
@Override
public void utilityPeriodic() {}
}