Pros Linking Files

#1

What is the proper way use header and include files on pros. My main goal is to be able configurate and set up motors on a separate file and then be able to use those configurated motors on on the autonomous.cpp and operator.cpp files as well as the initalize file. Using latest pros version with C++

0 Likes

#2

extern your motors and stuff in main.h, then define them in a normal file somewhere. For example, I have this in my main.h file:

 extern pros::Motor left1;
 extern pros::Motor left2;
 extern pros::Motor right1;
 extern pros::Motor right2;

 extern pros::Motor flywheel_top;
 extern pros::Motor intake1;
 extern pros::Motor intake2;
 extern pros::Motor lift;

and this in my opcontrol.cpp file:

 pros::Motor left1(1);
 pros::Motor left2(2);
 pros::Motor right1(3, true);
 pros::Motor right2(4, true);

 pros::Motor flywheel_top(5, pros::E_MOTOR_GEARSET_06, true);
 pros::Motor intake1(7);
 pros::Motor intake2(6, true);
 pros::Motor lift(9, pros::E_MOTOR_GEARSET_36, true);
1 Like

#4

where in main.h do your extern your motors?

0 Likes

#5

it would need to be after you include the pros api or if using okapi then that one…

#define PROS_USE_LITERALS

#include "pros/apix.h"

/**
 * You should add more #includes here
 */
#include "okapi/api.hpp"
//#include "pros/api_legacy.h"

// put includes and other forward declaration here
#include "robot.h"
#include "robot_gui.h"

You may even want to do those after the “using namespace …” selection.

1 Like