FRCteam3952 / FRC2023

2022 - 2023 Season Robot Code
Other
11 stars 17 forks source link

Code autonomous modes #50

Open maxchen132 opened 1 year ago

maxchen132 commented 1 year ago

The autonomous mode is the 15 second period at the beginning of the match in which the robot operates without any input from the drivers. We want to have different autonomous commands to run. Your task is to code different autonomous mode commands, according to instructions provided by Jaci probably which I will post here later probably once I receive specific instructions.

There are multiple things you'll want to understand before you start this. First, you'll want to know how to use PathWeaver, since we will be using PathWeaver to move the robot efficiently along trajectories during autonomous. Whenever we want to move the robot from point A to point B, most of the time we will want to use PathWeaver to draw a trajectory between two points. Documentation of PathWeaver can be found in issue #35 .

Second of all, you'll want to understand our autonomous command structure and the way in which commands work. Documentation on commands can also be found in the Read documentation issue.

Explanation for autonomous command structure: Our autonomous command structure is made up of several parts:

  1. Code in RobotContainer.java: the code here initializes and passes the selected autonomous command to the robot to be run in autonomous mode. We select the different autonomous commands through SmartDashboard (a dashboard which we use to help control the robot), which is implemented in RobotContainer through SendableChooser<Command>. Furthermore, all trajectory commands generated by PathWeaver are retrieved from their JSON files and stored in RobotContainer.

  2. Code in Autons.java: Autons.java can be found in the commands.autocommands folder, and contains multiple factory methods which return create and return Commands to be run in RobotContainer (factory methods are methods that generate objects). Each factory method returns a Command that is passed in through SendableChooser to be an option on SmartDashboard, so that we can choose different autonomous commands to run depending on the situation during competition. In other words, each method in Autons.java represents one autonomous command.

  3. How to actually code autonomous commands: To create our autonomous commands, we will be using command compositions, which is the combination of smaller commands/actions to create larger commands (you can read about command compositions in the documentation). In order to generate instant actions/commands, we use this:

    Commands.runOnce(() -> {
    // Autonomous scenario code
    }, subsystem1, subsystem2);

If the -> operator is new to you, look up java lambdas. subsystem1 and subsystem2 can be any number of subsystems that the command needs to access. You will most likely use this structure to code all of the arm instructions, as the drive instructions will be handled by the trajectory commands stored in RobotContainer. These instant commands can be concatenated with other commands using the .andThen() and .alongWith() decorators, which is how we will be calling both the instant commands and trajectory commands together as one command. Additionally, you will need to add the subsystems that you want to use as parameters to the factory method you are working on (see comments in Auton.java for more details). TLDR: use command compositions to create autonomous commands to be passed in to the robot to be run during autonomous modes.

As always, if there are any questions feel free to ask. Sorry for the wall of text, some of it might be hard to understand cuase Im tired

maxchen132 commented 1 year ago

Instructions from Jaci (These are all separate autonomous commands that we might want to use):

  1. https://media.discordapp.net/attachments/580895270154272768/1081697873281949746/AC3301A0-CAF5-4193-8E22-1828A99CEDFE.jpg?width=496&height=884

  2. https://media.discordapp.net/attachments/580895270154272768/1081697873521033326/0B36A142-E045-476E-9F46-D79B38950F8E.jpg?width=496&height=884

  3. https://media.discordapp.net/attachments/580895270154272768/1081697873768493238/F1687916-6FBA-4A28-A254-8EB84465247B.jpg?width=496&height=884

  4. 1 and 2 combined (combine the logic, don't just copy paste one after the other)

maxchen132 commented 1 year ago

1 has been completed (mostly, excluding any necessary initial calibrations) as an example of how an auton command is implemented (probably, may be subject to future change)

maxchen132 commented 1 year ago

Since our first competition is coming up so soon, I'm going to start working on this issue as well. If there's a part of this issue you want to work on, comment on this issue and I'll let you do it. Otherwise, I'm going to assume no one is taking this and just finish it because we need it for competition.

maxchen132 commented 1 year ago

Currently, 1 is finished (tentatively, still need to test) and most of 2 has been completed by Ivan.

maxchen132 commented 1 year ago

3 tentatively completed.

maxchen132 commented 1 year ago

4 tentatively completed, all autons are still open to adjustments and suggestions

maxchen132 commented 1 year ago

Requires testing

maxchen132 commented 1 year ago

If you have any ideas for auton, feel free to make them as well, these 4 don't have to be the only options we have