So my biggest issue I have encountered is being able to “link” the three source files together. If I constructed a motor or sensor in initialize.cpp, I could not use it in autonomous.cpp or opcontrol.cpp. I did find rather sketchy work arounds for these, but when it came to wanting to use the gyroscope, which needs to be calibrated, I have to construct and initialize it in initialize.cpp, but then I don’t know how to access the gyroscope’s abilities in autonomous.cpp
initialize.cpp or motorConfig.cpp
pros::Motor left_FrontDrive (LEFT_FRONT_PORT); pros::Motor left_BackDrive (LEFT_BACK_PORT); pros::Motor right_FrontDrive (RIGHT_FRONT_PORT, true); pros::Motor right_BackDrive (RIGHT_BACK_PORT, true); pros::Controller master (CONTROLLER_MASTER);
main.h or motorConfig.hpp
extern pros::Motor left_FrontDrive; extern pros::Motor left_BackDrive; extern pros::Motor right_FrontDrive; extern pros::Motor right_BackDrive; extern pros::Controller master;
Now include that header file into all the other files
And you have access to the motors throughout multiple files
So when I include the header file to all the other files, and put the proper stuff in the initialize.cpp and main.h files, I get no errors, but when I compile I get an error saying it can not link the project with okapilib,libpros.
is there an error code number?
So I took of screenshot of the terminal, and I just made a motor called ‘test’
I deleted some comments that weren’t relevant or helpful to the issue.
@Parker we need a bit more info. Can you share where you’ve defined the test function, declared it, and are using it inside opcontrol? see also declaration vs definition.
So I declared the motor test in main.h, and then defined it in initialize.cpp. I am also getting another fun error. I talked to my advisor (who is a programmer) and we tinkered around with the code so it is not exactly the error is a bit more than what it was yesterday.
You are including initialize.cpp inside both autonomous and opcontrol, that’s what is causing errors, it should be removed from both. Only include header files in .cpp files.
Also, don’t add you own declarations to main.h, it’s bad practise, create a new header file.