Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Project 1 Basic Romi Drive/.Glass/glass-window.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"MainWindow": {
"GLOBAL": {
"height": "960",
"maximized": "0",
"style": "0",
"userScale": "2",
"width": "1280",
"xpos": "-1",
"ypos": "-1"
}
},
"Window": {
"###NetworkTables": {
"Collapsed": "0",
"Pos": "312,346",
"Size": "937,231"
},
"###NetworkTables Settings": {
"Collapsed": "0",
"Pos": "37,37",
"Size": "307,86"
},
"Debug##Default": {
"Collapsed": "0",
"Pos": "60,60",
"Size": "400,400"
}
}
}
1 change: 1 addition & 0 deletions Project 1 Basic Romi Drive/.Glass/glass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
12 changes: 9 additions & 3 deletions Project 1 Basic Romi Drive/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "java",
"name": "Launch Main",
"request": "launch",
"mainClass": "frc.robot.Main",
"projectName": "Project 1 Basic Romi Drive"
},
{
"type": "wpilib",
"name": "WPILib Desktop Debug",
"request": "launch",
"desktop": true,
"desktop": true
},
{
"type": "wpilib",
"name": "WPILib roboRIO Debug",
"request": "launch",
"desktop": false,
"desktop": false
}
]
}
4 changes: 4 additions & 0 deletions Project 1 Basic Romi Drive/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "2.0.0",
"tasks": []
}
9 changes: 6 additions & 3 deletions Project 1 Basic Romi Drive/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
public class Robot extends TimedRobot {

private final RomiDrivetrain mDrivetrain = new RomiDrivetrain();

private int controllerPort = 0;
private final XboxController controller = new XboxController(controllerPort);
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand Down Expand Up @@ -52,7 +53,9 @@ public void teleopInit() {}

/** This function is called periodically during operator control. HINT you code will be in this function*/
@Override
public void teleopPeriodic() {}
public void teleopPeriodic(){
mDrivetrain.arcadeDrive(controller.getY(Hand.kLeft), -1 * controller.getX(Hand.kRight));
}

/** This function is called once when the robot is disabled. */
@Override
Expand Down Expand Up @@ -87,4 +90,4 @@ public void robotPeriodic() {
public void simulationPeriodic() {
mDrivetrain.simulationPeriodic();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import edu.wpi.first.wpiutil.math.VecBuilder;
import edu.wpi.first.wpiutil.math.numbers.N2;

import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.GenericHID.Hand;

public class RomiDrivetrain extends SubsystemBase {

// Romi Encoder Constants
Expand All @@ -43,6 +46,10 @@ public class RomiDrivetrain extends SubsystemBase {
// Set up the differential drive controller
private final DifferentialDrive mDiffDrive = new DifferentialDrive(mLeftMotor, mRightMotor);

// Set up Xbox Controller
final int controllerPort = 0;
XboxController controller = new XboxController(controllerPort);


// SIMULATION STUFF

Expand Down Expand Up @@ -70,7 +77,7 @@ public RomiDrivetrain() {

/**
* Commands the drivetrain through an arcade drive style. HINT: this is useful for your purposes.
* @param xaxisSpeed The speed at which the robot goes forward and backward. Should be a number between -1 and 1.
* @param xaxisSpeed The speed at which the robot goes forward and backward. Should be a number between -1 and 1.
* @param zaxisRotate The speed at which the spins clockwise and counterclockwise. Should be a number between -1 and 1.
*/
public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
Expand Down
12 changes: 9 additions & 3 deletions Project 2 Basic State Machine/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "java",
"name": "Launch Main",
"request": "launch",
"mainClass": "frc.robot.Main",
"projectName": "Project 2 Basic State Machine"
},
{
"type": "wpilib",
"name": "WPILib Desktop Debug",
"request": "launch",
"desktop": true,
"desktop": true
},
{
"type": "wpilib",
"name": "WPILib roboRIO Debug",
"request": "launch",
"desktop": false,
"desktop": false
}
]
}
20 changes: 19 additions & 1 deletion Project 2 Basic State Machine/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.RomiDrivetrain.RomiState;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.GenericHID.Hand;

Expand All @@ -19,6 +20,8 @@
public class Robot extends TimedRobot {

private final RomiDrivetrain mDrivetrain = new RomiDrivetrain();
private int controllerPort = 0;
private final XboxController controller = new XboxController(controllerPort);

/**
* This function is run when the robot is first started up and should be used for any
Expand Down Expand Up @@ -52,7 +55,22 @@ public void teleopInit() {}

/** This function is called periodically during operator control. HINT you code will be in this function*/
@Override
public void teleopPeriodic() {}
public void teleopPeriodic() {
mDrivetrain.arcadeDrive(controller.getX(Hand.kLeft), controller.getY(Hand.kRight));

if (controller.getXButtonPressed()) {
mDrivetrain.setState(RomiState.SLOW);
}

if (controller.getYButtonPressed()) {
mDrivetrain.setState(RomiState.NORMAL);
}

if (controller.getBButtonPressed()) {
mDrivetrain.setState(RomiState.FAST);
}

}

/** This function is called once when the robot is disabled. */
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class RomiDrivetrain extends SubsystemBase {

private final DifferentialDriveOdometry mOdometry = new DifferentialDriveOdometry(Rotation2d.fromDegrees(0));



/** Creates a new RomiDrivetrain. */
public RomiDrivetrain() {
Expand All @@ -68,13 +68,40 @@ public RomiDrivetrain() {
resetEncoders();
}

//Normal Speed of Romi
private RomiState state = RomiState.NORMAL;

/**
* Commands the drivetrain through an arcade drive style. HINT: this is useful for your purposes.
* @param xaxisSpeed The speed at which the robot goes forward and backward. Should be a number between -1 and 1.
* @param zaxisRotate The speed at which the spins clockwise and counterclockwise. Should be a number between -1 and 1.
*/

public enum RomiState {
SLOW, NORMAL, FAST
}

public void setState(RomiState state){
this.state = state;
}

public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
mDiffDrive.arcadeDrive(xaxisSpeed, zaxisRotate);
switch (state) {
case SLOW:
System.out.println("The Romi is in Slow Mode");
mDiffDrive.arcadeDrive(xaxisSpeed * 0.5, zaxisRotate * 0.5);
break;

case NORMAL:
System.out.println("The Romi is in Normal Mode");
mDiffDrive.arcadeDrive(xaxisSpeed * 0.75, zaxisRotate * 0.75);
break;

case FAST:
System.out.println("The Romi is in Fast Mode");
mDiffDrive.arcadeDrive(xaxisSpeed, zaxisRotate);
break;
}
}

public void resetEncoders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.GenericHID.Hand;
import edu.wpi.first.wpilibj.XboxController.Button;
import frc.robot.commands.ExampleCommand;
import frc.robot.subsystems.RomiDrivetrain;
import frc.robot.subsystems.RomiDrivetrain.RomiState;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand All @@ -19,13 +24,26 @@
public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final RomiDrivetrain m_romiDrivetrain = new RomiDrivetrain();
private int controllerPort = 0;
private final XboxController controller = new XboxController(controllerPort);

private final ExampleCommand m_autoCommand = new ExampleCommand(m_romiDrivetrain);

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
// Configure the button bindings
configureButtonBindings();

// Configure default commands
// Set the default drive command to split-stick arcade drive
m_romiDrivetrain.setDefaultCommand(
// A split-stick arcade command, with forward/backward controlled by the left
// hand, and turning controlled by the right.
new RunCommand(
() ->
m_romiDrivetrain.arcadeDrive(
-controller.getX(Hand.kLeft), -1 * controller.getY(Hand.kRight)),
m_romiDrivetrain));
}

/**
Expand All @@ -34,7 +52,27 @@ public RobotContainer() {
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
* edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {}
private void configureButtonBindings() {

new JoystickButton(controller, Button.kX.value)
.whenPressed(
() -> {
m_romiDrivetrain.setState(RomiState.SLOW);
}, m_romiDrivetrain);

new JoystickButton(controller, Button.kY.value)
.whenPressed(
() -> {
m_romiDrivetrain.setState(RomiState.NORMAL);
}, m_romiDrivetrain);

new JoystickButton(controller, Button.kB.value)
.whenPressed(
() -> {
m_romiDrivetrain.setState(RomiState.FAST);
}, m_romiDrivetrain);

}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RomiDrivetrain extends SubsystemBase {

// Set up the differential drive controller
private final DifferentialDrive m_diffDrive = new DifferentialDrive(m_leftMotor, m_rightMotor);


/** Creates a new RomiDrivetrain. */
public RomiDrivetrain() {
Expand All @@ -34,8 +35,33 @@ public RomiDrivetrain() {
resetEncoders();
}

private RomiState state = RomiState.NORMAL;

public enum RomiState {
SLOW, NORMAL, FAST
}

public void setState(RomiState state) {
this.state = state;
}

public void arcadeDrive(double xaxisSpeed, double zaxisRotate) {
m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate);
switch (state) {
case SLOW:
System.out.println("The Romi is in" + state + " mode");
m_diffDrive.arcadeDrive(xaxisSpeed * 0.5, zaxisRotate * 0.5);
break;

case NORMAL:
System.out.println("The Romi is in" + state + " mode");
m_diffDrive.arcadeDrive(xaxisSpeed * 0.75, zaxisRotate * 0.75);
break;

case FAST:
System.out.println("The Romi is in" + state + " mode");
m_diffDrive.arcadeDrive(xaxisSpeed, zaxisRotate);
break;
}
}

public void resetEncoders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ public class RobotContainer {
private final RomiDrivetrain m_romiDrivetrain = new RomiDrivetrain();

// You will need to set this up.
private final SequentialCommandGroup mCommand = new SequentialCommandGroup();
private final SequentialCommandGroup mCommand = new SequentialCommandGroup(
new InstantCommand(
() ->
m_romiDrivetrain.setForwardSpeed(0.5), m_romiDrivetrain),
new WaitCommand(5),

new InstantCommand(
() ->
m_romiDrivetrain.setForwardSpeed(0), m_romiDrivetrain));

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
// Configure the button bindings
configureButtonBindings();


}

/**
Expand Down
Loading