PROS Question

  1. 4 days ago

    this might be a dumb question, but I've never worked with PROS before, so do I declare my motors in all of the cpp files or how am I able to define the motors once and use them in other files?

    @kaami this might be a dumb question, but I've never worked with PROS before, so do I declare my motors in all of the cpp files or how am I able to define the motors once and use them in other files?

    I had the same problem when I started a few weeks ago. Only define the motors in one file - any file. Then, for each motor/sensor/variable/function that needs global scope, in your "main.h" file, declare each of those at the top of the file. Add the extern keyword at the beginning. So, each of your motors will have the following syntax:

    extern pros::Motor motor1;
    extern pros::Motor motor2;

    Run prosv5 make clean (or pros make clean if you're running on Cortex) and then pros make. I tend to do that every time I make a change to main.h.

  2. The Electrobotz

    Jan 12 Answer Virginia 20181X

    @kaami this might be a dumb question, but I've never worked with PROS before, so do I declare my motors in all of the cpp files or how am I able to define the motors once and use them in other files?

    I had the same problem when I started a few weeks ago. Only define the motors in one file - any file. Then, for each motor/sensor/variable/function that needs global scope, in your "main.h" file, declare each of those at the top of the file. Add the extern keyword at the beginning. So, each of your motors will have the following syntax:

    extern pros::Motor motor1;
    extern pros::Motor motor2;

    Run prosv5 make clean (or pros make clean if you're running on Cortex) and then pros make. I tend to do that every time I make a change to main.h.

  3. edjubuh

    Jan 12 V5 Beta Moderator West Lafayette, IN

    @The Electrobotz has the correct answer.

    @The Electrobotz I had the same problem when I started a few weeks ago. Only define the motors in one file - any file.

    To clarify, you should define the motors in any one C++ source file (not just any file) and include them in a header file such as main.h.

  4. The Electrobotz

    Jan 13 Virginia 20181X

    @edjubuh @The Electrobotz has the correct answer.

    To clarify, you should define the motors in any one C++ source file (not just any file) and include them in a header file such as main.h.

    Sorry, that's what I meant. By any file I was referring to any source file. I apologize for the confusion.

 

or Sign Up to reply!