So our team’s new to doing command based programming. We’re learning by translating our previous years code. However, we are stuck with trying to translate the following code:
if (m_controller.getYButton() || m_controller_right.getYButton()) {
arm.intakeBelt();
} else if (m_controller_right.getAButton()) {
arm.closeGripper();
} else {
arm.beltStop();
}
What is the best way to implement this kind of logic using commands?
I’m not sure if this misses the point of “translating to commands”, but if I were writing this, say, inside of a SequentialCommandGroup, I’d just wrap the entire block as-is in an InstantCommand:
new InstantCommand(() -> {
if (...) {
} else {
}
})
No need to replicate the logic with command compositions.
But you can remove the button negation for close gripper and probably end up with desired behavior.
Is there a reason that closing the gripper and running the belt are mutually exclusive? If they are unrelated hardware wise, you may want to separate the arm subsystem to belt and gripper so the command scheduler can be more granular.
All the buttons are Trigger objects. You can get them from the various command controllers in wpilib like command xbox controller.