Hello I am trying to make my arm go a certain rotational degrees as long as my driver is holding the button. I want it to fall back to zero after he lets the button go. This is the current code I have. There are two problems. The first for the Armlevel2 the motor goes extremely slow and this is just the motor with default everything. The second ArmLevel1 is not working at all no matter what I do. The code is below. Any help is appreciated.
void ArmLevel1(void){
double RotationAmount = 300;
ArmLeft.setVelocity(100, vex::velocityUnits::pct);
ArmRight.setVelocity(100, vex::velocityUnits::pct);
if(Controller1.ButtonL1.pressing()){
ArmLeft.rotateTo(RotationAmount, vex::rotationUnits::deg, false);
ArmRight.rotateTo(RotationAmount, vex::rotationUnits::deg, false);
}else{
ArmLeft.rotateTo(0, vex::rotationUnits::deg, false);
ArmRight.rotateTo(0, vex::rotationUnits::deg, false);
}
}
void ArmLevel2(void){
double RotationAmount = 500;
ArmLeft.setVelocity(100, vex::velocityUnits::pct);
ArmRight.setVelocity(100, vex::velocityUnits::pct);
if(Controller1.ButtonL2.pressing()){
ArmLeft.rotateTo(RotationAmount, vex::rotationUnits::deg, false);
ArmRight.rotateTo(RotationAmount, vex::rotationUnits::deg, false);
}else{
ArmLeft.rotateTo(0, vex::rotationUnits::deg, false);
ArmRight.rotateTo(0, vex::rotationUnits::deg, false);
}
}
Hmmm. First, wrap your code in ```cpp
and ```
to have nice formatting. Second, how are you using these functions? If you are using them in driver control, then if you call Armlevel1 first and then Armlevel2, you will never get Armlevel1 to run. Let’s try and simulate the process. Set rotationamount to 300, if the button is pressed, then start the motors to go to the rotation. If not pressed, start to go to the 0. Then, set rotationamount to 500, if the button is pressed then start the motors to go to the rotation. If not pressed, then start the motors to go to the zero. The problem arises in that the code runs that if the first button is being pressed, then it doesn’t go to 0, but if the second button isn’t being pressed, than it goes to 0. I would do one function with the whole thing
void ArmLevel()
{
if(Controller1.ButtonL1.pressing() || Controller1.ButtonL2.pressing())
{
if(Controller1.ButtonL1.pressing())
{
ArmLeft.rotateTo(300, vex::rotationUnits::deg, false);
ArmRight.rotateTo(300, vex::rotationUnits::deg, false);
}
if(Controller1.ButtonL2.pressing())
{
ArmLeft.rotateTo(500, vex::rotationUnits::deg, false);
ArmRight.rotateTo(500, vex::rotationUnits::deg, false);
}
}
else
{
ArmLeft.rotateTo(0, vex::rotationUnits::deg, false);
ArmRight.rotateTo(0, vex::rotationUnits::deg, false);
}
}
You will need to further edit so that the command runs while you are not pressing the button, but this should be a good start.
2 Likes