I am trying to set limits on the up and down movement of the arm on my robot, my first try it stopped but wouldn’t let me go back down, then I tried again through different if else statements but that didn’t work either. Here is a sample of the code I was working on.
@Override
public void execute() {
double current_pos = m_ArmSubsystem.getPos();
m_ArmSubsystem.p2(speed);
if (current_pos < -70.8|| speed>0){
m_ArmSubsystem.p2(speed);
} else if(current_pos > 5 || speed<0){
m_ArmSubsystem.p2(speed);
}
else{m_ArmSubsystem.p2(0);}
}
The || operator is for OR, so when you put
if (current_pos < -70.8|| speed>0){
m_ArmSubsystem.p2(speed);
}
It sets the speed if the current_pos is less than -70.8 OR speed is greater than 0.
I think what you want is the AND operator (&&) so instead do
if (current_pos < -70.8 && speed>0){
m_ArmSubsystem.p2(speed);
}
And then the same for the else if statement.
Also, if speed is greater than 0, the arm will move in the positive direction, so you probably want positive 70.8 instead of negative.
system
Closed
August 12, 2024, 2:41pm
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.