Lesson 5 - PROS Project Structure
When you open the PROS project that you just created, these are the folders that should appear.
Link to the Default PROS Project
(Note: your interface will be different depending on what file explorer you are using. Just ensure that your project contains the folders “bin,” “firmware,” “include,” and “src.” Here are explanations of what is in each of the folders.
Bin (optional reading)
When you compile a C++ program, the compiler does two things. (1) Ensure the syntax is proper (2) The Compiler creates “object files” (extension is .o) for every .cpp file (that is why you should see a main.o file).
Object files are important because something called the “Linker”
The “Linker”:
Reads all of these different machine-language files
Allows the usage of libraries through library files
Ensures the function of multiple-file programming.
By doing all of this, the linker creates a single, executable (.exe) file of your program/project.
Also, you will see files with the ending of .bin and .elf. “Bin” files are nothing more than just a file that stores information in binary. “Elf” files are essentially a standard lower-level instruction file. The linker creates these files (they are the linker’s output).
Firmware (optional reading)
Files ending in “.a” are very similar to .o files. However, there are some differences during linking. We are keeping this explanation brief as understanding this is not essential to programming. However, for further reading, we suggest exploring the process of Compiling and Linking (static vs dynamic) through a Google Search.
Include (optional reading but needed for multiple-file programming)
This folder typically includes the header files used in the program. We will go into more detail about what header files are later on in Unit 5. The only thing needed to be known right now is that headers files (end in .h / .hpp) go in the “include” folder.
Src (Essential)
This folder is where all the .cpp files will be contained. Main.cpp is where you would write the pre-autonomous initialization routine, final autonomous code, and the driver control. Let’s now explore main.cpp in greater detail.
Main.cpp
If you open the PROS project and open the “src” folder, one of the first things that you will see is a file with the name of “main.cpp.” This link is what the code inside main.cpp should look like.
You may notice that there are functions
OPTIONAL: void on_center_button(){...}
This is a function that ensures the brain’s green display center button works appropriately. This was written by those who developed the PROS platform.
OPTIONAL: void initialize(){}
As in the comments, this function runs immediately after the program starts. Right now, the code you see within this function was once again written by those who developed the PROS platform. The code is simply setting up the green display that you will see on the brain when running the program.
OPTIONAL: void disabled(){}
This function runs after the initialize function and after both autonomous and opcontrol. Typically, you can leave the body of this function blank.
void competition_initialize(){}
This will run immediately before autonomous. If you are using any sensors you will need to calibrate -- IMU, Gyroscope, Accelerometer -- the calibration code will go within this section. We will talk more about sensors later.
void autonomous(){}
The body of this function will be executed during the autonomous period of the competition.
void opcontrol(){}
The body of this function will be executed during the user control period of the competition.
You also might notice there is an infinite while loop within this function. In order for the robot to continuously check for whenever input / buttons are being pressed, the user control code you will be writing typically goes within the while loop.
immediately before that on lines 79 - 81, there is a Controller with the name “master” and two motors “left_mtr” and “right_mtr” for the rest of the program to use. This is just an example PROS gives, you should delete this and declare your motors at the top of the main.cpp file.