PROS Basic tank drive code

Howdy, y’all. Recently, I downloaded PROS with the intention of using it this year, so that I can add odometry to my toolkit for auton. I started by looking at the API and writing a simple tank drive program using the examples on the PROS tutorial website. However, when I upload it to the robot, both joysticks control all four motors, and the axes that are being used for some reason are channel 3 on the left joystick and channel 1 on the right joystick. Why might this be?

Code is here:

void opcontrol() {
	pros::Controller master(pros::E_CONTROLLER_MASTER);
	pros::MotorGroup left_mg({1, 9});    
	pros::MotorGroup right_mg({-2, -10});  


	while (true) {
	
		// Tank control scheme
		int leftSpeed = master.get_analog(ANALOG_LEFT_Y);    
		int rightSpeed = master.get_analog(ANALOG_RIGHT_Y);  		 
                left_mg.move(leftSpeed);                      // Sets left motor voltage
		right_mg.move(rightSpeed);                     // Sets right motor voltage
		pros::delay(20);                               // Run for 20 ms then update
	}
}```

master.get_analog(ANALOG_LEFT_Y); is wrong

int leftSpeed = master.get_anglog(pros::E_ANALOG_LEFT_Y);
int rightSpeed = master.get_analog(pros::E_ANALOG_LEFT_Y);
left_mg.move(leftSpeed);
right_mg.move(rightSpeed);

This should work

1 Like

Update: This worked, however, now one side of the robot is inverted, and no matter what I reverse, whether it be ports, or the speed variables themselves, one side remains inverted.

Yes sorry I wrote the code wrong and maybe that will fix it
Switch from

rightSpeed = master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y

TO

rightSpeed = master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y

This that doesn’t work please lmk

Last post was inaccurate. the fix worked, but I had to tinker with it some more to get everything working right. setting gearsets in the constructors does not work and causes problems, so I used left_mg.set_gearing(pros::E_MOTOR_GEARSET_06); and right_mg.set_gearing(pros::E_MOTOR_GEARSET_06); to fix it. Final code actually looks like this for future reference:

void opcontrol() {
	pros::Controller master(pros::E_CONTROLLER_MASTER);
	pros::MotorGroup left_mg({-3, -9});    // Creates a motor group with forwards ports 1 and 9
	pros::MotorGroup right_mg({2, 10});  // Creates a motor group with reversed ports 2 and 10
	right_mg.set_gearing(pros::E_MOTOR_GEARSET_06);
	left_mg.set_gearing(pros::E_MOTOR_GEARSET_06);

	while (true) {
	
		// Tank control scheme
		double leftSpeed = master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
		double rightSpeed = master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
		left_mg.move(leftSpeed);                      // Sets left motor voltage
		right_mg.move(rightSpeed);                     // Sets right motor voltage
		pros::delay(20);                               // Run for 20 ms then update
	}
}

and oh boy, does it work like a dream. thanks for the help!

I did not know set gearing was a thing outside of a constructor, glad I could help.