Joysticks
學習目標
1.設定及使用Joystick類別。(wpi.edu.wpilibj.Joystick)
2.操控組遙控時的搖桿功能定義。
使用類別
GenreicHID (三個子類別如下:)
Joystic (wpi.edu.wpilibj.Joystick)
XboxController
PS4Controler
Document: https://docs.wpilib.org/en/stable/docs/software/basic-programming/joystick.html
Joystic class
Toggles 切換
按下搖桿按鍵,啟動某一功能,利用變數來控制。
public class MyRobot extands IterativeRobot{
public void robotInit(){
Joystick joystick = new Joystick(0);
}
boolean toggleOn = false;
boolean togglePressed = false;
public void teleopPeriodic(){
updateToggle();
if(toggleOn){
//
}else{
//
}
}
public void updateToggle(){
if (joystick.getRawButton(1)) {
if(!togglePressed){
toggleOn = !toggleOn;
togglePressed = true;
} else{
togglePressed = false;
}
}
}