Drift in my program HELP ME!

When I input some control input to the robot then stop inputting sometimes the motors continues going even if though I had stopped giving it input into the controller can someone give me an example of how to fix this? Someone previously explained to me that I should create deadzones for the joystick because the actual value is not hitting 0. How do I do that? I am not an experienced programmer. Here is my driver code:

int slowmode = 0;
double arcadeSpeedLeft;
double arcadeSpeedRight;

void usercontrol(void) {
  // User control code here, inside the loop
  while(1){

    if(slowmode == 0){
        arcadeSpeedLeft = -0.55Controller1.Axis4.position(percent)-Controller1.Axis3.position(percent);
       arcadeSpeedRight = -0.55Controller1.Axis4.position(percent)+Controller1.Axis3.position(percent);

    }
    else if(slowmode == 1){
      arcadeSpeedLeft = 0.5(-0.55Controller1.Axis4.position(percent)-Controller1.Axis3.position(percent));
      arcadeSpeedRight = 0.5(-0.55Controller1.Axis4.position(percent)+Controller1.Axis3.position(percent));
    }

    FrontLeft.setStopping(coast);
    FrontRight.setStopping(coast);
    BackLeft.setStopping(coast);
    BackRight.setStopping(coast);

    FrontLeft.setVelocity(-arcadeSpeedLeft,percent);
    FrontRight.setVelocity(arcadeSpeedRight,percent);
    BackLeft.setVelocity(-arcadeSpeedLeft,percent);
    BackRight.setVelocity(arcadeSpeedRight,percent);


    FrontLeft.spin(forward);
    BackLeft.spin(forward);
    BackRight.spin(forward);
    FrontRight.spin(forward);

    if(Controller1.ButtonY.pressing()){

    Controller1.Screen.print("Drivetrain: %.2f." , FrontLeft.temperature(percent));
    Controller1.Screen.newLine();
    Controller1.Screen.print("Manipulator: %.2f." , Manipulator.temperature(percent));
    Controller1.Screen.newLine();
    Controller1.Screen.print("Forklift: %.2f." , Forklift.temperature(percent));
    Controller1.Screen.newLine();
    Controller1.Screen.print("Lift: %.2f." , FourbarLeft.temperature(percent));
    Controller1.Screen.newLine();
    wait(0.5,sec);
    Controller1.Screen.setCursor(1,1);
    Controller1.Screen.clearScreen();

    } 


    if(Controller1.ButtonUp.pressing()){
      slowmode = 1;

      FrontLeft.setVelocity(50,percent);
      FrontRight.setVelocity(50,percent);
      BackLeft.setVelocity(50,percent);
      BackRight.setVelocity(50,percent);
    }



    if(Controller1.ButtonX.pressing()){
        Manipulator.setVelocity(-100,percent);
      Manipulator.spin(forward);
    }
    else if(Controller1.ButtonB.pressing()){
       Manipulator.setVelocity(100,percent);
      Manipulator.spin(forward);
    }
    else{
      Manipulator.stop(hold);
    }


if(Controller1.ButtonR2.pressing() && Forklift.position(degrees)>= -685){
      Forklift.setVelocity(-75,percent);
      Forklift.spin(forward);
    }
    else if(Controller1.ButtonR1.pressing() && Forklift.position(degrees)<=1){
       Forklift.setVelocity(75,percent);
      Forklift.spin(forward);
    }
    else{
      Forklift.stop(hold);



if(Controller1.ButtonL1.pressing()){
      FourbarLeft.setVelocity(-70,percent);
      FourbarLeft.spin(forward);
      FourbarRight.setVelocity(70,percent);
      FourbarRight.spin(forward);
    }
else if(Controller1.ButtonL2.pressing()){
      FourbarLeft.setVelocity(70,percent);
      FourbarLeft.spin(forward);
      FourbarRight.setVelocity(-70,percent);
      FourbarRight.spin(forward);
    }
    else{
      FourbarLeft.stop(hold);
      FourbarRight.stop(hold);
    }
    }

  }

    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to
    // update your motors, etc.
    // ........................................................................

    wait(20, msec); // Sleep the task for a short amount of time to
                    // prevent wasted resources.

}

Without going through your code - the big picture is the brain will keep going on last state until you tell it otherwise.

So for example, drive forward() … then you do a whole bunch of change speed, but never tell motors to stop - it will drive off the table (yup happened to me - but I caught the bot).

Keep that in mind - when will your robot be told to stay still?

2 Likes

The robot stays still after I counter out the drift then that cancels it. Do you know how to make a dead zone command in v5 text? Or do you know any other ways of how to stop this drift or what ever this is?

I think its just a problem how the joystick isn’t actually going to true 0 when you release the joy stick. But I don’t know how to do this or command

Search bar is your friend:

Hope this fixes your issue, but it may not.

2 Likes

Likely it should - was looking up the code example, you beat me to suitable example :slight_smile:

1 Like