สวิตช์กันชน#

การแนะนำ#

สวิตช์กันกระแทก เป็นสวิตช์เชิงกลที่ทำให้วงจรสมบูรณ์เมื่อถูกกด ทำให้หุ่นยนต์สามารถตรวจจับการกดและการปล่อยได้

สวิตช์กันชน VEX EXP เป็นอุปกรณ์ 3 สายที่มีฐานสีดำกว้างสำหรับติดกับหุ่นยนต์ และปุ่มสีแดงที่สามารถกดได้อยู่ด้านบน

หน้านี้ใช้ bumper_switch เป็นตัวอย่างชื่อสวิตช์กันชน โปรดแทนที่ด้วยชื่อที่คุณกำหนดเองตามต้องการ

ด้านล่างนี้คือรายการวิธีการที่มีให้เลือกใช้:

  • pressing – ส่งคืนว่าสวิตช์กันชนถูกกดหรือไม่

  • pressed – ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อใดก็ตามที่กดสวิตช์กันชน

  • released – ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อใดก็ตามที่ปล่อยสวิตช์กันชน

ตัวสร้าง – กำหนดค่าและตั้งค่าสวิตช์กันชนด้วยตนเอง

  • Bumper – สร้างสวิตช์กันชน

การกด#

pressing returns a Boolean indicating whether the Bumper Switch is currently being pressed. This can be used to check if the robot bumps into other objects.

  • True – สวิตช์กันชนกำลังถูกกดอยู่

  • False – ไม่ได้กดสวิตช์กันชน

Usage:
bumper_switch.pressing()

พารามิเตอร์

คำอธิบาย

เมธอดนี้ไม่มีพารามิเตอร์

# Display a message after bumper_switch is pressed
while not bumper_switch.pressing():
  pass

brain.screen.print("Bumper Switch pressed!")

กด#

pressed registers a function to be called whenever the Bumper Switch is pressed.

Usage:
bumper_switch.pressed(callback, arg)

พารามิเตอร์

คำอธิบาย

callback

A previously defined function that executes when the Bumper Switch is pressed.

arg

ไม่บังคับ ทูเปิล tuple ที่มีอาร์กิวเมนต์ที่จะส่งไปยังฟังก์ชันเรียกกลับ ดู ฟังก์ชันที่มีพารามิเตอร์ สำหรับข้อมูลเพิ่มเติม

def my_function():
  brain.screen.print("Pressed")

# Call my_function whenever bumper_switch is pressed
bumper_switch.pressed(my_function)

ปล่อยแล้ว#

released ลงทะเบียนฟังก์ชันที่จะถูกเรียกใช้เมื่อใดก็ตามที่ปล่อยสวิตช์กันกระแทก

Usage:
bumper_switch.released(callback, arg)

พารามิเตอร์

คำอธิบาย

callback

A previously defined function that executes when the Bumper Switch is released.

arg

ไม่บังคับ ทูเปิล tuple ที่มีอาร์กิวเมนต์ที่จะส่งไปยังฟังก์ชันเรียกกลับ ดู ฟังก์ชันที่มีพารามิเตอร์ สำหรับข้อมูลเพิ่มเติม

def my_function():
  brain.screen.print("Released")

# Call my_function whenever bumper_switch is released
bumper_switch.released(my_function)

ผู้สร้าง#

ตัวสร้าง (Constructor) ใช้สำหรับสร้างอ็อบเจ็กต์ Bumper จำนวน ชิ้นด้วยตนเอง ซึ่งจำเป็นสำหรับการกำหนดค่า Bumper Switch นอก VEXcode

Bumper#

Bumper สร้างสวิตช์กันชน

Usage:
Bumper(port)

พารามิเตอร์

คำอธิบาย

port

พอร์ต 3 สายที่เชื่อมต่อกับสวิตช์กันชน:

  • บน EXP Brain – brain.three_wire_port.x โดยที่ x คือหมายเลขของพอร์ต
  • บน 3-Wire Expander – expander.a โดยที่ expander คือชื่อของอินสแตนซ์ expander

# Create a Bumper Switch in Port A
bumper_switch = Bumper(brain.three_wire_port.a)