1201
Picking the Best Project Structure

Go back to 0000 Index

The best project structure depends on what you are doing. That's it. However, there are some general rules to stay by. For starters, here is the general folder structure you should have:

teamcode
|- opmodes
|  |- auto
|  |- teleop
|  |- test
|- utilities
   |- math
   |- hardware
   |- subsystems
   |- robot

Firstly, all code for the robot stays in the teamcode folder. Now, let's break down the subfolders.

The opmodes Folder

This folder is where you store all of your OpModes (more on how to make those later). Under this folder is 3 subfolders. The first two, auto and teleop, should be self explanatory. The test folder is not required, but could be useful depending on how many tests you are adding to your robot. If you are just adding one or two tests while in development, but nothing permanent, you probably don't need this folder. However, if you are making lasting tests that will be used outside of development or frequently throughout the development process, you should probably make a test folder for test OpModes.

The utilities Folder

This folder should, yet again, be self explanatory. Any utilities you have for your robot should go in this folder. However, this is a little more broad than just utilities. Lots of your robot's code could be going in here because this folder is where your hardware utilities and subsystems go (within their respective folders). This is also where your code that simplifies the control logic (so you don't need to set raw motor powers in your OpModes) goes. The large majority of your code will be in this folder and its subfolders.

A note about the math folder: This folder may not be needed depending on the competition. Some competitions require lots of math, others don't. Some competitions you can get away with one organized MathUtils file.

No matter how you organize your utilities folder, keep in mind that it needs to be organized. If you have a 2000 line Utils file, it needs to be broken up. Generally, the more split up your code is (within reason), the more concise and clear the purpose of it is. You might want to split up your MathUtils file into BasicMath and LinearAlgebra.

Now, for the part that should probably go at the top but that I put down here so you could read my very opinionated thoughts on how code should be organized.

It Doesn't Really Matter

Before you get too excited, your project structure does matter, but not that much. As long as your robot works and the code is easily readable by someone who does not have intimate knowledge of your codebase, you should be fine. You should keep the opmodes folder, but you could do away with the subfolders if you want to. If you only have 2 OpModes, what's the point? Of course, do your best to stay organized, but in the end, it doesn't really matter as long as it works.