Code is not working

Whenever I move the joysticks the motors dont move at all. Here is my drive.cpp file and the setDrive function.

void setDrive( int lateral, int linear, int rotation ) {


lateral = controller1.get_analog (ANALOG_LEFT_X);
linear = controller1.get_analog (ANALOG_LEFT_Y);
rotation = controller1.get_analog (ANALOG_RIGHT_X);

 // Y component, X component, Rotation
 topLeftDrive.move( -linear - lateral - rotation);
 topRightDrive.move(  linear - lateral - rotation);
 backLeftDrive.move(  linear + lateral - rotation);
 backRightDrive.move( -linear + lateral - rotation);

 if (abs( lateral ) < 10) {
   lateral  = 0 ;
 }
 if (abs( linear ) < 10) {
   linear = 0 ;
 }
 if (abs( rotation ) < 10) {
   rotation = 0 ;
 }

}

This is what I have in my opcontrol file.

void opcontrol() {

 while ( true ) {

  setDrive(0,0,0);

}
		pros::delay(20);

	}

Im still not sure whats going on and what im doing wrong.

I believe that you do not need the part at the top defining your variables. You could just put that when you are defining your functions. So, your program should look like:

void setDrive(void){
int lateral = controller1.get_analog (ANALOG_LEFT_X);
int linear = controller1.get_analog (ANALOG_LEFT_Y);
int rotation = controller1.get_analog (ANALOG_RIGHT_X);
//et cetera et cetera et cetera
3 Likes

I dont believe it changes anything but ill give that a shot.
EDIT : it did not change anything

I was looking through the api and I realized that it should be

lateral = controller1.get_analog (E_CONTROLLER_ANALOG_LEFT_X );
linear = controller1.get_analog (E_CONTROLLER_ANALOG_LEFT_Y);
rotation = controller1.get_analog (E_CONTROLLET_ANALOG_RIGHT_X);
1 Like

they both do the same thing but thanks for looking lol

1 Like

Maybe try printing out the values for lateral, rotatiom, and linear on v5 brain? They could just be reporting in as zero for some reason.

Ill give that a shot i guess

In the code you posted there are a number of issues.
no need to pass parameters and then immediately redefine them.
The deadband needs to be before passing the values to the motors.
and you need a delay in opcontrol, you have it outside the while loop.

void setDrive() {
 int lateral = controller1.get_analog (ANALOG_LEFT_X);
 int linear = controller1.get_analog (ANALOG_LEFT_Y);
 int rotation = controller1.get_analog (ANALOG_RIGHT_X);

 if (abs( lateral ) < 10) {
   lateral  = 0 ;
 }
 if (abs( linear ) < 10) {
   linear = 0 ;
 }
 if (abs( rotation ) < 10) {
   rotation = 0 ;
 }

 // Y component, X component, Rotation
 topLeftDrive.move( -linear - lateral - rotation);
 topRightDrive.move(  linear - lateral - rotation);
 backLeftDrive.move(  linear + lateral - rotation);
 backRightDrive.move( -linear + lateral - rotation);
}
void opcontrol() {

  while ( true ) {
    setDrive();
    pros::delay(20);
  }
}
5 Likes

Still doesnt seem to be working.