Lesson 4 - frc2052/2023-KnightKrawlerJavaTraining GitHub Wiki
Romi Robots
Now that your feeling a little more comfortable with Java programming we are going to program our first robot! We are going to use Romi Robots, which are like mini FRC robots. They use the same code we run on our big robots so they are great for getting started with robots!
Assignment A: Running the sample project
- Go to docs.wpilib.org and follow the instructions to create a new project.
- Once you have set up your project, go to Run > Run without debugging to run your code.
- Connect a joystick to your computer (one of the silver and black 3-axis joysticks)
- When the robot simulator window opens up drag your joystick from "system joysticks" on the left over to
Joysticks[0]
in the middle like so:
Then switch the robot mode to "Teleoperated" in the top left. Your robot should be ready to drive!
Assignment B: Tank Drive
Our default Romi project uses "Arcade Drive", which means we control the robot using a single joystick.
An alternative method of controlling a robot is "Tank Drive", which uses two joysticks. In Tank Drive, each joystick's Y-axis controls one wheel. To go forward you push both joysticks forward. To turn right you push just the left joystick forward (or push the left joystick forward and pull the right joystick back to rotate in place).
In this lesson you will update your Romi to drive using Tank Drive instead of Arcade Drive.
- Open the
DriveTrain
class and create a newtankDrive()
method. It will look similar to thearcadeDrive()
method, but instead of an x-axis speed and a z-axis/rotation it will take aleftSpeed
andrightSpeed
. - Create a new class called
TankDrive
. It should look similar toArcadeDrive
, but it should also take different variables and it will call our newtankDrive()
method instead ofarcadeDrive()
. - Open
RobotContainer
and add a new method calledgetTankDriveCommand()
that creates a new instance ofTankDrive
. This method will look similar togetArcadeDriveCommand()
. - Update
configureButtonBindings()
to callgetTankDriveCommand()
instead ofgetArcadeDriveCommand()
.
Assignment C: Autonomous mode
This assignment is a little more free-form!
First, set up an obstacle course using whatever materials you have available.
Then create a new class called AutonomousObstacleCommand
and follow the pattern from the existing AutonomousTime
class to program your robot to get through the obstacle course. Note that AutonomousTime
is a SequentialCommandGroup
- it runs one or more commands in sequence (one after thee other), and then it is done.
The sample project comes with four commands that you can use to help:
DriveTime
will drive for a fixed amount of timeDriveDistance
will drive a specified distanceTurnTime
will turn the robot for a fixed amount of timeTurnDegrees
will turn the robot a specified number of degrees
Make sure to update the configureButtonBindings()
method in RobotContainer
to add your autonomous mode to the list of automonous modes on the dashboard.