So I have recently switched to PROS and wrote an auton selection program.
I stored the selected auton in a variable (in “init.c”) but I don’t know how to access it from the “auto.c” file.
Can someone please explain how to include a header file in PROS?
There’s a couple ways to do this. The simplest way could be:
init.c:
int selectedAutonomous = 0;
void initialize() {
selectedAutonomous = 4; // you put whatever logic you want to select the auton
}
auto.c
extern int selectedAutonomous;
void autonomous() {
printf("Autonomous selected was %d\n", selectedAutonomous);
switch(selectedAutonomous) {
case 0:
// do whatever 0
break;
case 1:
// do whatever 1
break;
// etc.
}
}
You can just write
#include "myHeader.h"
at the top of the file. Anything you write in myHeader.h will be copied into that file. Most header files look like:
As an alternative, what you could do instead of using
#include "anotherHeader.h"
for every header file you want to use in each .c file, what you could do is put
#include
for every header file you use into your
main.h
file, and then in each of your source files use
#include "main.h"
. For example-
main.h:
#ifndef MAIN_H_
// This prevents multiple inclusion, which isn't bad for this file but is good practice
#define MAIN_H_
#include <API.h>
#include "library.h"
#include "motor.h"
#include "subsystems.h"
#include "opcontrolActions.h"
#include "autolibrary.h"
#include "PID.h"
#include "autonTasks.h"
#include "autonSkills.h"
// Allow usage of this file in C++ programs
#ifdef __cplusplus
extern "C" {
#endif
void autonomous();
void initializeIO();
void initialize();
void operatorControl();
// End C++ export structure
#ifdef __cplusplus
}
#endif
#endif