This is an archive of G2M. Please refer to this post for more information. Archived on 2026-01-09.

Arm position code not working

OrangeMan
04/19/2023 at 10:03:41 AM PDT

I am trying to code my robot arm to move down if it goes too high but the code is not working. it never goes back down if it goes too high. This is the code that I have right now.

int main() {
  while (1) {
   
    TurretMotor1.setVelocity(Controller1.Axis4.position(), percent);
    armMotor2.setVelocity(Controller1.Axis3.position(), percent);
    TurretMotor1.spin(forward);
    armMotor2.spin(forward);
    /*
    Controller1.Screen.print(PotentiometerA.angle(percent));
    //Controller1.Screen.print();
    wait(0.1, seconds);
    Controller1.Screen.clearLine(1);
    */
    Controller1.Screen.print(PotentiometerA.angle(percent));
    wait(.1, seconds);
    Controller1.Screen.clearScreen();
    Controller1.Screen.setCursor(1, 1);
    
    if (PotentiometerA.angle(percent)>95) {
      armMotor2.stop();
      armMotor2.setVelocity(50, percent);
      armMotor2.spin(forward);

      
    }
    
  }  
}

Dragon
04/19/2023 at 02:52:27 PM PDT

I know nothing about this, but it seems that maybe the arm has no time to go back down because it is instantly set back to the controller velocity before it can move? So maybe you should add a line that makes the code wait for a bit.