Parachoques#
Introducción#
La categoría de detección de parachoques de VEX IQ (2.ª generación) ofrece métodos para interactuar con el interruptor de parachoques.
For the examples below, the configured Bumper Switch will be named Bumper1 and will be used in all subsequent examples throughout this API documentation when referring to bumper class methods.
A continuación se muestra una lista de todos los métodos disponibles:
Acciones: Interactúa con el interruptor del parachoques.
pressed– Calls a function when the Bumper Switch is pressed.released– Calls a function when the Bumper Switch is released.
Obtenedores: devuelven datos del interruptor de parachoques.
pressing– Returns whether the Bumper Switch is being pressed.installed– Whether the Bumper Switch is connected to the Brain.
Constructores: inicializan manualmente un interruptor de parachoques.
bumper– Create a Bumper Switch.
Comportamiento#
pressed#
pressed calls a function when the bumper switch is pressed.
Usage:
Bumper1.pressed(callback);
Parámetro |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando se presiona el interruptor de parachoques. |
// Drive forward when the Bumper Switch is pressed
void onBumperPressed() {
Drivetrain.driveFor(forward, 100, mm);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Call onBumperPressed when the Bumper is pressed
Bumper1.pressed(onBumperPressed);
}
released#
released calls a function when the bumper switch is released.
Usage:
Bumper1.released(callback);
Parámetro |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando se suelta el interruptor de parachoques. |
// Drive backward when the Bumper Switch is released
void onBumperReleased() {
Drivetrain.driveFor(reverse, 100, mm);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Call onBumperReleased when the Bumper is released
Bumper1.released(onBumperReleased);
}
Captadores#
pressing#
pressing returns a Boolean indicating whether the Bumper Switch is currently being pressed.
1- The Bumper Switch is being pressed.0- The Bumper Switch is not being pressed.
Usage:
Bumper1.pressing()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Drive forward until the Bumper is pressed
while (true) {
Drivetrain.drive(forward);
// If pressed, stop and back up
if (Bumper1.pressing()) {
Drivetrain.stop();
Drivetrain.driveFor(reverse, 100, mm);
break;
}
wait(20, msec);
}
}
installed#
installed returns a Boolean indicating whether the Bumper Switch is currently connected to the Brain.
1– The Bumper Switch is connected to the Brain.0– The Bumper Switch is not connected to the Brain.
Usage:
Bumper1.installed()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
Constructores#
bumper#
bumper creates an object of the bumper Class in the specified port.
Usage:
bumper Bumper1 = bumper(port);
Parámetro |
Descripción |
|---|---|
|
Which Smart Port that the Bumper Switch is connected to as |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Create a Bumper object in Port 3
bumper CustomBumper = bumper(PORT3);
}