Drive Code Issue

Hi everyone,

My team is having some problems with our drive code. Basically, while driving, the front right motor randomly keeps going even when the joystick is not being touched. This is a new problem as of yesterday. We had been using the same drive code for months. However, we don’t see how it could be a mechanical issue. We also tried using a different controller but the same thing happened. If anyone could take a look I would really appreciate it!

int main() {
  
  vexcodeInit();
  while(1==1){
    int rightSpeed= (Controller1.Axis3.position(vex::percentUnits::pct)+(Controller1.Axis2.position(vex::percentUnits::pct)
    +Controller1.Axis1.position(vex::percentUnits::pct)));

    int leftSpeed= (Controller1.Axis3.position(vex::percentUnits::pct)-(Controller1.Axis2.position(vex::percentUnits::pct)
    +Controller1.Axis1.position(vex::percentUnits::pct)));

    if(rightSpeed>10||rightSpeed<-10){
      fRight.spin(vex::directionType::fwd,rightSpeed,vex::velocityUnits::pct);
      bRight.spin(vex::directionType::fwd,rightSpeed,vex::velocityUnits::pct);
    }
    else{
      fRight.spin(vex::directionType::fwd,0,vex::velocityUnits::pct);
      bRight.spin(vex::directionType::fwd,0,vex::velocityUnits::pct);

    }

    if(leftSpeed>10||leftSpeed<-10){
      fLeft.spin(vex::directionType::fwd,leftSpeed,vex::velocityUnits::pct);
      bLeft.spin(vex::directionType::fwd,leftSpeed,vex::velocityUnits::pct);
    }
    else{
      fLeft.spin(vex::directionType::fwd,0,vex::velocityUnits::pct);
      bLeft.spin(vex::directionType::fwd,0,vex::velocityUnits::pct);

 
    }```

Have you checked your wiring thoroughly? Sorry, I’m not much of a programmer, so I’m not really sure how I can help with your code.

What drive mode do you use? Tank or arcade? What wheels do you use? It is strange that you combine three axis of controller together.

Does front right motor alway randomly spin when your controller is on the ground and no one touch it?

1 Like

Thank you for the reply, we ended up figuring out that it was a problem with the port on the brain

Thank you, it was a problem with the port on the brain