保險桿開關#
介紹#
bumper 類與保險桿開關搭配使用,保險桿開關是一種機械開關,按下時會接通電路,使機器人能夠偵測到按下和釋放動作。

類別建構函數#
bumper(
triport::port &port );
類別析構函數#
銷毀 bumper 對象並釋放相關資源。
virtual ~bumper();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
保險桿開關連接的 3 線端口,寫成 |
例子#
// Create a bumper instance in Port A
bumper BumperA = bumper(Brain.ThreeWirePort.A);
成員功能#
bumper 類包含以下成員函數:
在呼叫任何 bumper 成員函數之前,必須先建立一個 bumper 實例,如下所示:
/* This constructor is required when using VS Code.
Bumper Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a bumper instance in Port A
bumper BumperA = bumper(Brain.ThreeWirePort.A);
pressing#
返回碰撞開關目前是否被按下。這可用於檢查機器人是否碰撞到其他物體。
Available Functionsint32_t pressing();
此函數不接受任何參數。
Return Values返回 int32_t ,表示是否按下了保險桿開關。
1— 保險桿開關被按下。0— 保險桿開關未按下。
pressed#
註冊一個在按下保險桿開關時要呼叫的函數。
Available Functionsvoid pressed( void (* callback)(void) );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
指向一個函數的指針,該函數將在按下保險桿時調用。 |
此函數不傳回值。
Examples定義回呼函數(在
int main()之外)// Display a message when bumper is pressed void BumperPressed() { Brain.Screen.print("Bumper pressed"); }在
int main()中註冊回呼函數int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run BumperPressed when the value of the Bumper Switch is pressed. BumperA.pressed(BumperPressed); }
released#
註冊一個在釋放碰撞開關時要呼叫的函數。
Available Functionsvoid released( void (* callback)(void) );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
指向一個函數的指針,該函數將在保險桿釋放時調用。 |
此函數不傳回值。
Examples定義回呼函數(在
int main()之外)// Display a message when bumper is released void BumperReleased() { Brain.Screen.print("Bumper released"); }在
int main()中註冊回呼函數int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run BumperReleased when the value of the Bumper Switch is released. BumperA.released(BumperReleased); }