So, I was wondering if there was a way to use the potentiometer to limit the drivers control of an arm to a certain range. My thought was
if (Controller1.ButtonL2.pressing()){ Tower.spin(forward); } else if (Controller1.ButtonL1.pressing()){ Tower.spin(reverse); } else if ((TowerSensor.angle(degrees) =< 15) or (TowerSensor.angle(degrees) >= 90)){ Tower.stop(); } else{ Tower.stop(); }
I’m worried about it preventing driver from having control after the potentiometer reaches the range limits. I haven’t tested that hypothesis yet, but is that even a concern I should have?
You could do a combination inside of the if
statements.
//Robot-Config Reference
potV2 ArmPot = potV2(Brain.ThreeWirePort.A);
motor ArmGroupMotorA = motor(PORT7, ratio18_1, false);
motor ArmGroupMotorB = motor(PORT8, ratio18_1, false);
motor_group ArmGroup = motor_group(ArmGroupMotorA, ArmGroupMotorB);
//Code - using && (and) operator
while(1) {
if(Controller1.ButtonL2.pressing() && ArmPot.angle() < 90) {
ArmGroup.spin(forward);
}
else if(Controller1.ButtonL1.pressing() && ArmPot.angle() > 15) {
ArmGroup.spin(reverse);
}
else {
ArmGroup.stop();
}
}
3 Likes
Thank you! That will let it move in the opposite direction, which is what I was worried about.