Skip to content

Commit 79ab256

Browse files
committed
Finished overhauling creating drivetrain.
1 parent 058bff1 commit 79ab256

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

docs/programming/driving_robot.md

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,6 @@ Now it’s time to make an arcadeDrive from our differentialDrive!
511511

512512
## Making our robot controllable
513513

514-
### Creating the Joystick
515-
516-
In order to drive our robot, it needs to know what will be controlling it. To do so, we will create a new joystick in RobotContainer.java, and an operator constant for the joystick port.
517-
518-
!!! summary ""
519-
**1)** Open Constants.java
520-
Check and make sure the `kDriverControllerPort` constant is present.
521-
**2)** Open RobotContainer.java
522-
- Change all `ExampleSubsystem` references to `DriveSubsystem`
523-
524-
<!-- TODO: add details on how to find joystick port in driverstation tips -->
525-
526514
### Creating the Drivearcade Command
527515

528516
- Remember that **methods** tell the robot what it can do but in order to make it do these things we must give it a **command**. See [Command Based Robot](../basics/wpilib.md#command-based-robot){target=_blank}
@@ -553,7 +541,7 @@ Before we begin we must create the class file for the DriveArcade command. See [
553541
#### In the constructor
554542

555543
!!! summary ""
556-
**1)** Inside the parenthesis of the the constructor `#!java DriveArcade()` add 3 variables:
544+
**1)** Inside the parenthesis of the the constructor `driveArcade()` add 3 variables:
557545
```Java
558546
public DriveCommand(
559547
DoubleSupplier xSpeed, DoubleSupplier zRotation, DriveSubsystem driveSubsystem)
@@ -585,7 +573,6 @@ Before we begin we must create the class file for the DriveArcade command. See [
585573
#### In the execute method
586574

587575
!!! summary ""
588-
!!! summary ""
589576
**1)** In the execute method we will we want to call the **arcadeDrive** method we created in **Drivetrain** and give it the variables **moveSpeed** `xspeed` and **rotateSpeed** `zrotation` we created as parameters.
590577

591578
In the execute() method below rotateSpeed type:
@@ -700,54 +687,58 @@ Since we will be using this command to control the robot we want it to run indef
700687
```
701688
</details>
702689

703-
### Connecting the Joystick
704-
- In RobotContainer We will now add the code to take the joystick inputs and use them to move the robot.
690+
### Creating the Joystick
705691

706-
!!! summary ""
707-
The joystick code goes inside the `configureBindings()` method.
708-
- We will the default command for the drive subsystem to an instance of the DriveCommand with the values provided by the joystick axes on the driver controller.
709-
- The Y axis of the controller is inverted so that pushing the stick away from you (a negative value) drives the robot forwards (a positive value).
710-
- Similarly for the X axis where we need to flip the value so the joystick matches the WPILib convention of counter-clockwise positive
692+
In order to drive our robot, it needs to know what will be controlling it. To do so, we will use the joystick in `RobotContainer.java`, as `m_drivecontroller`.
711693

712-
694+
!!! summary ""
695+
**1)** Open Constants.java
696+
Check and make sure the `kDriverControllerPort` constant is present.
697+
**2)** Open RobotContainer.java
698+
- Change all `ExampleSubsystem` references to `DriveSubsystem`
713699

714-
```Java
715-
driveSubsystem.setDefaultCommand(new DriveCommand(
716-
() -> -driverController.getLeftY() *
717-
(driverController.getHID().getRightBumperButton() ? 1 : 0.5),
718-
() -> -driverController.getRightX(),
719-
driveSubsystem));
720-
```
700+
<!-- TODO: add details on how to find joystick port in driverstation tips -->
721701

722702
### Using setDefaultCommand
723703

724-
- Commands passed to this method will run when the robot is enabled.
725-
- They also run if no other commands using the subsystem are running.
726-
- This is why we write **addRequirements(Robot.m_subsystemName)** in the commands we create, it ends currently running commands using that subsystem to allow a new command is run.
727704

728705
!!! summary ""
729-
**1)** Back in **RobotContainer.java** in the constructor we will call the `setDefaultCommand` of `m_drivetrain` and pass it the `DriveArcade` command
730-
731-
In the **RobotContainer.java** constructor type:
732-
733-
```java
734-
m_drivetrain.setDefaultCommand(new DriveArcade());
706+
**1)** Back in **RobotContainer.java** We will need to remove everything inside the `configureBindings` method.
707+
**2)** in the `configureBindings`we will call the `setDefaultCommand` of `m_drivetrain` and create a new `DriveArcade` command with parameters.
708+
709+
- Commands in this method will run when the robot is enabled.
710+
- They also run if no other commands using the subsystem are running.
711+
- This is why we write **addRequirements(Robot.m_subsystemName)** in the commands we create, it ends currently running commands using that subsystem to allow a new command is run.
712+
- We will the default command for the drive subsystem to an instance of the `DriveArcade` with the values provided by the joystick axes on the driver controller.
713+
- The Y axis of the controller is inverted so that pushing the stick away from you (a negative value) drives the robot forwards (a positive value).
714+
- Similarly for the X axis where we need to flip the value so the joystick matches the WPILib convention of counter-clockwise positive
715+
716+
```Java
717+
driveSubsystem.setDefaultCommand(new DriveArcade(
718+
() -> -m_driverController.getLeftY() *
719+
(m_driverController.getHID().getRightBumperButton() ? 1 : 0.5),
720+
() -> -m_driverController.getRightX(),
721+
driveSubsystem));
735722
```
736723

737724
!!! Tip
738725
Remember to use the light bulb for importing if needed!
726+
!!! Tip
727+
The `New` keyword creates a new instance of a class (object)
739728

740-
??? Example
729+
<details><summary>Example</summary>
741730

742731
Your full **RobotContainer.java** should look like this:
743732

744733
```java
745734
package frc.robot;
746735

747-
import edu.wpi.first.wpilibj.Joystick;
748-
import frc.robot.commands.*;
749-
import frc.robot.subsystems.*;
750-
import edu.wpi.first.wpilibj2.command.Command;
736+
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
737+
import edu.wpi.first.wpilibj2.command.button.Trigger;
738+
import frc.robot.Constants.OperatorConstants;
739+
import frc.robot.commands.Autos;
740+
import frc.robot.commands.ExampleCommand;
741+
import frc.robot.subsystems.ExampleSubsystem;
751742

752743
/**
753744
* This class is where the bulk of the robot should be declared. Since Command-based is a
@@ -757,12 +748,12 @@ Since we will be using this command to control the robot we want it to run indef
757748
*/
758749
public class RobotContainer {
759750
// The robot's subsystems and commands are defined here...
760-
public static final Drivetrain m_drivetrain = new Drivetrain();
751+
public static final DriveSubsystem drivetrain = new DriveSubsystem();
761752
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();
762753

763754
private final ExampleCommand m_autoCommand = new ExampleCommand(m_exampleSubsystem);
764-
765-
public Joystick driverController = new Joystick(Constants.DRIVER_CONTROLLER);
755+
private final CommandXboxController m_driverController =
756+
new CommandXboxController(OperatorConstants.kDriverControllerPort);
766757

767758
/**
768759
* The container for the robot. Contains subsystems, OI devices, and commands.
@@ -771,8 +762,7 @@ Since we will be using this command to control the robot we want it to run indef
771762
// Configure the button bindings
772763
configureButtonBindings();
773764

774-
// Set default commands on subsystems
775-
m_drivetrain.setDefaultCommand(new DriveArcade());
765+
776766
}
777767

778768
/**
@@ -782,6 +772,11 @@ Since we will be using this command to control the robot we want it to run indef
782772
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
783773
*/
784774
private void configureButtonBindings() {
775+
driveSubsystem.setDefaultCommand(new DriveSubSystem(
776+
() -> -driverController.getLeftY() *
777+
(driverController.getHID().getRightBumperButton() ? 1 : 0.5),
778+
() -> -driverController.getRightX(),
779+
driveSubsystem));
785780
}
786781

787782

@@ -796,3 +791,4 @@ Since we will be using this command to control the robot we want it to run indef
796791
}
797792
}
798793
```
794+
</details>

0 commit comments

Comments
 (0)