Help with Autonomous

Soooo Im not sure why but my code won’t start the mini autonomous that I made im not sure if I phrased it right or if their is an internal error but im really hopping someone can guide me on autonomous.


here's the code.

#include "main.h"
#define R 20
#define L 11
#define R2 19
#define L2 12


pros::Controller controller1(pros::E_CONTROLLER_MASTER);
pros:: Motor frontRight(20);
pros:: Motor frontLeft(11);
pros:: Motor backRight(19);
pros:: Motor backLeft(12);


 int JoystickAxis1(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
   return toReturn;
 }

 int JoystickAxis2(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
   return toReturn;
 }

 int JoystickAxis3(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
   return toReturn;
 }

 int JoystickAxis4(){
   int toReturn = controller1.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_X);
   return toReturn;
}


void drive_straight(int straight_ticks, int speed) {
frontLeft.move_relative(straight_ticks, speed);
backLeft.move_relative(straight_ticks, speed);
frontRight.move_relative(straight_ticks, speed);
backRight.move_relative(straight_ticks, speed);
}


void on_center_button() {
	static bool pressed = false;
	pressed = !pressed;
	if (pressed) {
		pros::lcd::set_text(2, "I was pressed!");
	} else {
		pros::lcd::clear_line(2);
	}
}

void auton() {
	if(controller1.get_digital(DIGITAL_A)){
	       autonomous();
	}
}


void initialize() {
	pros::lcd::initialize();
	pros::lcd::set_text(1, "Scar Is here!!!!");

	pros::lcd::register_btn1_cb(on_center_button);
}


void disabled() {}


void competition_initialize() {}




void autonomous() {

  drive_straight(1000,100);

}





void opcontrol() {

/**

Arm Example! :)

ControllerButton btnUp(E_CONTROLLER_DIGITAL_R1);
ControllerButton btnDown(E_CONTROLLER_DIGITAL_R2);
Motor lift(LIFT_MOTOR);

void opcontrol() {
  while (true) {
    if (btnUp.isPressed()) {
      lift.moveVoltage(12000);
    } else if (btnDown.isPressed()) {
      lift.moveVoltage(-12000);
    } else {
      lift.moveVoltage(0);
    }
	*/

	while (true) {


		//int left = controller1.get_analog(ANALOG_LEFT_Y);
	//	int right = controller1.get_analog(ANALOG_RIGHT_Y);
	frontLeft.move_velocity(JoystickAxis3() + JoystickAxis1() + JoystickAxis4()*2);
	frontRight.move_velocity(JoystickAxis3() - JoystickAxis1() - JoystickAxis4()*2);
	backLeft.move_velocity(JoystickAxis3() + JoystickAxis1() - JoystickAxis4()*2);
	backRight.move_velocity(JoystickAxis3() - JoystickAxis1() + JoystickAxis4()*2);

	if(controller1.get_digital(pros::E_CONTROLLER_DIGITAL_X)){
		autonomous();
	}

		pros::delay(20);

	}
}
1 Like

You might want to recategorize this bc a lot of people have iq muted

1 Like

In the future, please wrap your code in [code]...[/code] tags or triple backtics (```) to get code formatting in your post.

I’m not super experienced in PROS but here are a couple of things I spotted that might be causing problems - some additional description of the specific problem you’re experiencing would be helpful in further debugging your code (e.g., what is the desired functionality of your code and how does its current functionality, if any, differ from that).

  • In the function auton(), you call the function autonomous(), which is declared later in the file - this should prevent your code from compiling (unless the PROS toolchain is doing something fancy) because the function doesn’t exist yet when you call it.

  • auton() is only called if button X is pressed, and it only does anything if button A is pressed when it’s called. Thus, to get what I’m guessing is the desired outcome, you must press X while A is being held down - is this the intended functionality of the program?

4 Likes

Where would I recategorize?

Thank you for the tips also I didn’t mean to put the button to X and A how do I take out button X ?

You would edit your post by pressing on the pencil icon.