Program debugging

MY PROS Project won’t work no matter how hard i try. Can someone debug this for me?

#include "main.h"
 pros::Motor LBack(10,pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor LFront(9,pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor RBack(1,pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor RFront(8,pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor Arm(6,pros::E_MOTOR_GEARSET_36, false, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor Angler(5,pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor LIntake(19,pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Motor RIntake(11,pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
	pros::Controller Controller(pros::E_CONTROLLER_MASTER);

//Drive
//FINDS THE AVERAGE ENOCDER VALUE TO GET A BASIS ON WHERE THE ROBOT IS

//SIMPLE WAY TO MAKE THE ROBOT TO MOVE FORWARD
void driveSpeed(int left, int right){
	LBack = left;
  LFront = left;
	RBack = right;
	RFront = right;
}
//BASE DRIVER CONTROL COMMAND
void setDriveMotor(){
	int leftJoystick = Controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
  int rightJoystick = Controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
//CONTROLLER DEADZONE

}
//WAY TO MOVE DURING AUTONOMOUS


//Intake

void setIntake(int power) {
	LIntake = power;
	RIntake = power;

}

void setIntakeMotors(){
	int intakePower = 127 * (Controller.get_digital(pros::E_CONTROLLER_DIGITAL_L2))-(Controller.get_digital(pros::E_CONTROLLER_DIGITAL_L1));
	setIntake(intakePower);
}
//Arm
void setArm(int power) {
	Arm = power;

}

void setArmMotor(){
	int ArmPower = 127 * (Controller.get_digital(pros::E_CONTROLLER_DIGITAL_R2))-(Controller.get_digital(pros::E_CONTROLLER_DIGITAL_R1));
	setArm(ArmPower);
}
//Angler
void setAngler(int power) {
	Angler = power;

}

void setAnglerMotor(){
	int AnglerPower = 127 * (Controller.get_digital(pros::E_CONTROLLER_DIGITAL_UP))-(Controller.get_digital(pros::E_CONTROLLER_DIGITAL_DOWN));
	setAngler(AnglerPower);
	if(AnglerPower == 127){
		setIntake(30);
	}
	if (AnglerPower == -127){
		setIntake(-30);
	}
}

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

void initialize() {
	pros::lcd::initialize();
	pros::lcd::set_text(1, "avgEncoderValue()");
LBack.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
RBack.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
LFront.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
RFront.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
Arm.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
LIntake.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
RIntake.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
Angler.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);

}

void disabled() {}


void competition_initialize() {}




void autonomous() {


}


void opcontrol() {
	while(true){
		setArmMotor();
		setDriveMotor();
		setIntakeMotors();
		setAnglerMotor();
		pros::delay(10);
	}
}

No matter how i hard i try i can’t seem to get this program to work. Can someone debug this for me?

Can someone debug this?

There’s no need to create multiple topics asking the same question, I merged them altogether for you and also placed into the PROS support category.

8 Likes

Can you give a bit more detail then it isn’t working? How does it not work? What are you expecting it to do?

2 Likes

Like @Johnmandrake said, what isn’t working.

From a cursory look, the only thing I see is driveSpeed(leftJoystick,rightJoystick) is not called in setDriveMotors().

A non-technical issue I see is that you have L2-L1 and R2-R1. It may not be wrong but since L1 is above L2 on the controller, I’d expect L1 to make a mechanism go “up/forward/out” with a positive motor voltage and L2 make it go “down/backward/in” with a negative motor voltage. Since you are not commenting your code no one else knows what’s suppose to happen. It may be that the motor is placed so it works that way but it is not obvious. I’d explicitly make it obvious at least in comments.

3 Likes

It doesn’t move or do anything except the intake works:)

It said that I could only put 1 picture per post so created multiple. Sorry about the inconvenience!

Count your parentheses in arm, intake and angler. Mult takes precedence over sub.

You shouldn’t split it up to so many functions. Its hard to read and confusing.
Try that first.
Also, i dont recommend you using tank drive (one y axis for one side of the drive).
Instead, do something like this:

void opcontrol(){
    int y,x;
    while(1)(){
        y = Controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
        x = Controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_X);
        LFront = y+x;
        LBack = y+x;
        RFront = y-x
        RBack = y-x
    }
}

Firstly, this will use only use one joystick to control front back left right.
Also, [Motor_Name] = [Speed] is an operator for you to easily assign speeds to a motor.
Lastly, try spitting up your files into files named like auto, opcontrol, and place your functions in it.

4 Likes