PROS help

So I have 2 questions about PROS:

  1. 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.

  2. Can someone please explain how to include a header file in PROS?

Take a look at this

The magic of PROS is that it is just C. You can google any c question and find a hundred answers all of which apply directly to PROS.

  1. 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.
    }
}

  1. 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:


#ifndef _MY_HEADER_H_
#define _MY_HEADER_H_

#include "anotherHeader.h"

void myFunction();
void myOtherFunction();

extern int myVariable;

#endif

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

and in opcontrol.c:


#include "main.h"

void operatorControl(){
  
  while(1){
    opcontrolTankDrive();
    opcontrolMobileGoal();
    opcontrolLinearGear();
    opcontrolChainBar();
	opcontrolConeGrabber();
    opcontrolStack();
	opcontrolPanic();
    
    opcontrolDebug();
    delay(20);
  }
}