PROS Code Help

I am new to PROS. I am trying to do a normal four-wheel drive code. However, the code I was working on had some issues that I cannot figure out. It is a whole new project, which I opened a new file named main.cpp.
The code I wrote:

#include “main.h”
#include “API.h”

#define FRONTRIGHT 1
#define FRONTLEFT 2
#define BACKRIGHT 19
#define BACKLEFT 20
Controller master(E_CONTROLLER_MASTER);
pros::Motor frontright(1, motor_18, true, E_MOTOR_ENCODER_DEGREES);
pros::Motor frontleft(2, motor_18, false, E_MOTOR_ENCODER_DEGREES);
pros::Motor backright(19, motor_18, true, E_MOTOR_ENCODER_DEGREES);
pros::Motor backleft(20, motor_18, false, E_MOTOR_ENCODER_DEGREES);
void opcontrol()
{
while (true)
{
/int leftx = master.get_analog(E_CONTROLLER_ANALOG_LEFT_X);
int lefty = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);
int rightx = master.get_analog(E_CONTROLLER_ANALOG_RIGHT_X);
int righty = master.get_analog(E_CONTROLLER_ANALOG_RIGHT_Y);
int mover = leftx - lefty;
int movel = leftx + lefty;
/
frontright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
frontleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
backright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
backleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
pros::delay(20);
}
}
int main()
{
while(!Competition::is_autonomous())
{
opcontrol();
}
}

The errors:

Compiling src/main.cpp [WARNINGS]
src/main.cpp:8:1: error: ‘Controller’ does not name a type; did you mean ‘_strtoll_r’?
Controller master(E_CONTROLLER_MASTER);
^~~~~~~~~~
_strtoll_r
src/main.cpp:9:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor frontright(1, motor_18, true, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp:10:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor frontleft(2, motor_18, false, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp:11:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor backright(19, motor_18, true, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp:12:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor backleft(20, motor_18, false, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp: In function ‘void opcontrol()’:
src/main.cpp:23:3: error: ‘frontright’ was not declared in this scope
frontright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~~
src/main.cpp:23:19: error: ‘E_CONTROLLER_ANALOG_LEFT_X’ was not declared in this scope
frontright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:24:3: error: ‘frontleft’ was not declared in this scope
frontleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~
src/main.cpp:25:3: error: ‘backright’ was not declared in this scope
backright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~
src/main.cpp:26:3: error: ‘backleft’ was not declared in this scope
backleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~
src/main.cpp:27:3: error: ‘pros’ has not been declared
pros::delay(20);
^~~~
src/main.cpp: In function ‘int main()’:
src/main.cpp:32:10: error: ‘Competition’ has not been declared
while(!Competition::is_autonomous())
^~~~~~~~~~~
Capturing metadata for PROS Editor…

If anyone would help, that will be very appreciated. Thank you very much.

Are you trying to #include the PROS api.h file, or is that a header file you created? From what I can tell, this is causing most of the compiler errors.

You need to specify that the Controller class and the E_CONTROLLER_MASTER value are in the pros namespace, like so:

pros::Controller controller (pros::E_CONTROLLER_MASTER);

When running PROS code, the V5 brain will run initialize() when the program is run, autonomous() when the Brain is enabled to run autonomous, and opcontrol() when the Brain is enabled to run in driver control mode. Any other functions will be ignored, so declaring an int main() function is pointless.

I don’t know what motor_18 is supposed to be (I’m guessing you were attempting to pass in the internal motor gearset), but motor_18 is not a valid value for that Motor class constructor, so the motors were never created. This caused the “error: (insert motor name) was not declared in this scope”.

Competition is neither a class or a namespace that is a part of the PROS API, so I have no idea what you’re trying to do here.

Please look at the PROS Documentation, as that could have provided the needed information to fix your issues. In addition, you should probably read a fair bit of the Getting Started guide as well as the tutorials in the documentation, because there are a lot of issues in the formatting of this code

3 Likes

Thank you for your reply. I looked through some of the documentation and tutorials. However, for the controller, it shows the error " ‘pros’ does not name a type". Did I miss something? For the uploading part, I don’t know if I can specify which port from 1-8 in the brain to upload. Is there any way to do so? Thank you!

Can you post your entire main.cpp code again along with the output when you try to compile? I want to see what could be causing the issue

To upload to a specific slot, just include the --slot flag followed by the program slot you want to upload to. For example, prosv5 upload --slot 8 would upload to slot 8 on the brain.

1 Like

Sure.
Here is the new code:

#include “main.h”
#include “api.h”

#define FRONTRIGHT 1
#define FRONTLEFT 2
#define BACKRIGHT 19
#define BACKLEFT 20
pros::Controller controller (pros::E_CONTROLLER_MASTER);
pros::Motor frontright(1, motor_18, true, E_MOTOR_ENCODER_DEGREES);
pros::Motor frontleft(2, motor_18, false, E_MOTOR_ENCODER_DEGREES);
pros::Motor backright(19, motor_18, true, E_MOTOR_ENCODER_DEGREES);
pros::Motor backleft(20, motor_18, false, E_MOTOR_ENCODER_DEGREES);
void opcontrol()
{
while (true)
{
/int leftx = master.get_analog(E_CONTROLLER_ANALOG_LEFT_X);
int lefty = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);
int rightx = master.get_analog(E_CONTROLLER_ANALOG_RIGHT_X);
int righty = master.get_analog(E_CONTROLLER_ANALOG_RIGHT_Y);
int mover = leftx - lefty;
int movel = leftx + lefty;
/
frontright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
frontleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
backright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
backleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
pros::delay(20);
}
}
int main()
{
while(!Competition::is_autonomous())
{
opcontrol();
}
}

and this is the output:

Compiling src/main.cpp [WARNINGS]
src/main.cpp:8:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Controller controller (pros::E_CONTROLLER_MASTER);
^~~~
puts
src/main.cpp:9:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor frontright(1, motor_18, true, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp:10:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor frontleft(2, motor_18, false, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp:11:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor backright(19, motor_18, true, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp:12:1: error: ‘pros’ does not name a type; did you mean ‘puts’?
pros::Motor backleft(20, motor_18, false, E_MOTOR_ENCODER_DEGREES);
^~~~
puts
src/main.cpp: In function ‘void opcontrol()’:
src/main.cpp:23:3: error: ‘frontright’ was not declared in this scope
frontright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~~
src/main.cpp:23:19: error: ‘E_CONTROLLER_ANALOG_LEFT_X’ was not declared in this scope
frontright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.cpp:24:3: error: ‘frontleft’ was not declared in this scope
frontleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~
src/main.cpp:25:3: error: ‘backright’ was not declared in this scope
backright.move(E_CONTROLLER_ANALOG_LEFT_X - E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~~
src/main.cpp:26:3: error: ‘backleft’ was not declared in this scope
backleft.move(E_CONTROLLER_ANALOG_LEFT_X + E_CONTROLLER_ANALOG_LEFT_X);
^~~~~~~~
src/main.cpp:27:3: error: ‘pros’ has not been declared
pros::delay(20);
^~~~
src/main.cpp: In function ‘int main()’:
src/main.cpp:32:10: error: ‘Competition’ has not been declared
while(!Competition::is_autonomous())
^~~~~~~~~~~
Capturing metadata for PROS Editor…

Sorry if I am asking some elementary questions. Thank you.

Okay, you really didn’t change much of anything in the code. Take a look at the “Programming the Clawbot” tutorial on the PROS documentation to see how they coded a drivetrain (it’s only 2 motors, but I think it’s easy to understand how to add two motors). Then, try to rewrite your program similar to how the documentation did it.

I would also like to point out that the PROS project template includes a working 2-motor drive code:

void opcontrol() {
	pros::Controller master(pros::E_CONTROLLER_MASTER);
	pros::Motor left_mtr(1);
	pros::Motor right_mtr(2);

	while (true) {

		int left = master.get_analog(ANALOG_LEFT_Y);
		int right = master.get_analog(ANALOG_RIGHT_Y);

		left_mtr = left;
		right_mtr = right;
		pros::delay(20);
	}
}

Also try to understand this code before attempting to fix your own

4 Likes

Thank you for your help. I will change the drive code for the clawbot but by bit and see if which part has any issues.