Lesson 8: 2024 Code overview¶
+Agenda¶
+-
+
Overview of last years code
+Every command and subsystem
+Vision code
+QnA
+Watch old matches for strategy and inspiration
+
diff --git a/dev/.buildinfo b/dev/.buildinfo index 5eeb38e..16b7be8 100644 --- a/dev/.buildinfo +++ b/dev/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 2839a83f3f51511cfae5994f1925ab88 +config: 034acb39d946dc73d8a045dab9491358 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/dev/PreseasonTraining/2024CodeOverview/index.html b/dev/PreseasonTraining/2024CodeOverview/index.html new file mode 100644 index 0000000..dfd6215 --- /dev/null +++ b/dev/PreseasonTraining/2024CodeOverview/index.html @@ -0,0 +1,393 @@ + + +
+ + + + + +Overview of last years code
Every command and subsystem
Vision code
QnA
Watch old matches for strategy and inspiration
TODO: Import https://titanrobotics2022.notion.site/5-4-Arm-91d67fab859a40968919a2f86e20ffcf
+Add torque gravity(?)
Talk about PIDF usage
TODO: Import https://titanrobotics2022.notion.site/3-Autonomous-1717871dea664a40b1e3d33cb9062274
+What is Java
+A JIT (compiled “Just-In-Time”) language
+Compiled into Java bytecode
Then bytecode is translated into machine code on target platform
Makes code more cross-platform than C/C++, which is directly compiled
Statically typed
+Every variable has a “type”
E.g. “int” == integer number, “double” == decimal number, “string” == text, etc
Lower case type is primitive type: basic type included with java
Upper case type is class type: complex type, see next
Object oriented programming
+Everything is an “object” of a certain “class”
Each class can have “variables” and “functions”
There’s also “constructors”, which are methods that run when you create an object
There’s also modifiers: “public”, “private”, “readonly”, “static”
Private things can only be accessed inside the object
Static are the same for all object instances of a class
Readonly cant be modified after creation, all readonly are static
Btw, “variable” == “member” == “attribute” and “function” == “method”
Python and C++ also have classes
Example class:
1class Car {
+ 2 public Engine engine = new Engine();
+ 3public float fuel = 0; // Unit is gallons
+ 4public mileage = 0; // Unit is miles
+ 5
+ 6// The constructor
+ 7public Car(float fuel, float mileage) {
+ 8 this.fuel = fuel;
+ 9 this.mileage = mileage;
+10}
+11
+12// This method drives the car by X miles
+13public void driveCar(float miles) {
+14 this.mileage += miles;
+15 this.fuel -= miles / 33.0; // 33 miles per gallon
+16}
+17
+18// Adds fuel to car
+19 public void addFuel(float fuel) {
+20 this.fuel += fuel;
+21 }
+22}
+
1// ...
+2Car hondaCivic = new Car(0, 0); // Brand new car with zero mileage
+3car.addFuel(10.0); // Filled it up
+4car.driveCar(30.0); // Drove the car to IMSA
+5// ...
+
Libraries
+Other code you import, typically written by other people
Consists of classes
Standard library is included with java
WPILib is the library we use for FRC
It has stuff like classes for motors and sensors
We also have a library for our gyroscope written by the manufacturer
And also our own library for reusable code: Titan Algorithms
Walkthrough practice: inventory manager
1class Item {
+2 public string Name;
+3 public int Quantity;
+4
+5 public Item(string name, int quantity) {
+6 this.Name = name;
+7 this.Quantity = quantity;
+8 }
+9}
+
1class Inventory {
+ 2private ArrayList<Item> items = new ArrayList<Item>();
+ 3
+ 4public Inventory() {}
+ 5
+ 6public void addItem(Item item) {
+ 7items.add(item);
+ 8}
+ 9
+10public String search(String query) {
+11 String result = "";
+12 for (int i = 0; i < items.size(); i++) {
+13 If (items.get(i).Name.contains(query)) {
+14 // Yes you can add strings
+15 // "\n" or "\r\n" on Windows is special character for new line
+16 result += items.get(i).Name + "\r\n";
+17 }
+18}
+19}
+20}
+
1import java.util.Scanner; // Import standard library for print, this is done automatically by VSCode
+ 2
+ 3// Name of our program
+ 4class InventoryManager {
+ 5 public static void main(String[] args) {
+ 6 // Java’s print function
+ 7 System.out.println("Welcome to inventory manager.");
+ 8 System.out.println("Type ‘/add [item name] [quantity]’ to add an item. No spaces in name.");
+ 9 System.out.println("Type ‘/search [item name]’ to find an item.");
+10 System.out.println("Type ‘/exit’ to leave the program.");
+11
+12 // Scanner object used to record user input
+13Scanner inputScanner = new Scanner(System.in);
+14
+15// Our inventory
+16Inventory inventory = new Inventory();
+17
+18 // While loops run if the condition is true
+19 boolean isRunning = true;
+20 while (isRunning) {
+21String userInput = inputScanner.nextLine(); // Get command input
+22String[] splittedCommand = userInput.split("\\s+"); // Array with each word
+23
+24 If (userInput.startsWith("/exit")) {
+25 isRunning = false;
+26System.out.println("Exiting.");
+27 } else if (userInput.startsWith("/add")) {
+28 // Item count is a string but has to be converted to an integer type
+29 Item newItem = new Item(splittedCommand[1], Integer.parseInt(
+30splittedCommand[2]));
+31 inventory.addItem(newItem);
+32System.out.println("Item added.");
+33 } else if (userInput.startsWith("/search")) {
+34 String query = splittedCommand[1];
+35 System.out.println(inventory.search(query));
+36 } else {
+37 System.out.println("Unknown command.");
+38 }
+39 }
+40 }
+41}
+
TODO: Migrate https://titanrobotics2022.notion.site/1-LED-Programming-a513f3e774704473a6b4b1377751d5ee here.
+Provide:
+Swerve subsystem
Localizer
Utils, etc
Measurements
Motor and sensor IDs
Resources and links
Programming subsystems and commands
Split into groups for subsystems
+Group 1: intake, indexer, LEDs
Group 2: elevator
Group 3: shooter
Give hints and implementation details for some subsystems (e.g. shooter positioning math)
Provide vision localizer
Teach PathPlanner
TODO: Figure out where we put the tutorial!
+What does FRC programming do
+Make best/smoothest driving experience for the drivers
+Reduce amount of thinking and time wasted during the game
We do that through optimizing driving and automating tasks
Score as much points in autonomous 15 second period
+Good autonomous can make a bad robot perform good
Structure
+All project files stored on Github, project management software like Bild
Vision code is on the coprocessors, robot control code is on the roborio
roboRIO
+Most important part of the robot
Should always be accessible
Can be plugged into a computer through USB, ethernet, or WiFi
Driver Station
+Press enter to disable
Press space to emergency stop (the robot has to restart to be enabled again)
All these lights have to be green for it it work
Phoenix Tuner X
+Can be used to control or monitor motors, here’s how to do it
Needs driver station to work
What non programmers need to know (remember this)
+We can’t make the robot fly
+Software is not a substitute for bad hardware
Hard stops >>> software stops
DI only has two customers: the programming team and the drive team
Please ask us while designing, not after!!
Links
+Cheatsheets
+Driver Station + Phoenix Tuner X + REV Hardware Client
Git
WPILib VSCode + WPILib overview
Linux
Homework for programming subteam
+Download Java, VSCode, WPILib, and Git + sign-in
TODO: Import https://titanrobotics2022.notion.site/2-Tank-Drive-1291dde0e33245d3aa9b26da1b6b99b4
+Add more friction physics
Talk about PIDF usage