Limit Switch

陳子毓

limit switch

Limit Switch 是什麼?

limit switch

  • 極限開關
  • 可以避免機器人撞到自己造成損傷
  • 不能停在半空中

如何接線?

limit switch 怎麼接?

  • Digital Input/Output
    • Signal -> 1
    • Ground -> 0

Ground(接地)

Signal(訊號)

limit switch 怎麼接?

  • Normally open
    • limit switch沒有被壓下
      • Signal -> 1
    • limit switch 被壓下
      • Ground -> 0
  • Normally closed
    • 反過來

程式

想法:

  • 上、下各有一個limit switch
  • 任何一個limit switch被壓下
    • 馬達的速度設為0
  • 兩個limit switch都沒有被壓下
    • 馬達的速度設為預設的速度

程式

//從Roborio的角位讀取limit switch
DigitalInput toplimitSwitch = new DigitalInput(0); 
DigitalInput bottomlimitSwitch = new DigitalInput(1);

PWMVictorSPX motor = new PWMVictorSPX(0);
Joystick joystick = new Joystick(0);

@Override
public void teleopPeriodic() {
    setMotorSpeed(joystick.getRawAxis(2));
}

public void setMotorSpeed(double speed) {
    if (speed > 0) {
        if (toplimitSwitch.get()) {
            // 上面的limit switch被壓到
            motor.set(0); //馬達的速度設為0
        } else {
            // 沒有碰到limit switch
            motor.set(speed); //馬達的速度設為預設的速度
        }
    } else {
        if (bottomlimitSwitch.get()) {
            // 下面的limit switch被壓到
            motor.set(0);
        } else {
            motor.set(speed);
        }
    }
}

資料來源

謝謝大家

Made with Slides.com