detector de objetos#
Inicializando la clase objectdetector#
Un sensor de objetos se crea utilizando el siguiente constructor:
The objectdetector constructor creates an objectdetector object in the specified Three Wire Port with the reverse flag set to the specified value.
Parámetro |
Descripción |
|---|---|
|
The 3-Wire Port that the Object Sensor is connected to, whether it’s a port on the |
|
Set this to reverse the detection logic. The default is |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the objectdetector Class constructor.
// Create the Brain.
brain Brain;
// Construct an ObjectSensor "objdet" with the
// objectdetector class.
objectdetector objdet = objectdetector(Brain.ThreeWirePort.A, true);
This objdet object will be used in all subsequent examples throughout this API documentation when referring to objectdetector class methods.
Métodos de clase#
reflectivity()#
The reflectivity(units) method returns the reflectivity measured by the Object Sensor. The reflectivity is an estimation based on the raw value of the sensor.
Una reflectividad del 0 % es un valor bruto de 3000 o superior. Una reflectividad del 100 % es un valor bruto de 0.
Parámetros |
Descripción |
|---|---|
|
The only valid unit for reflectivity is |
Devuelve: Un número entero que representa la reflectividad medida por el sensor de objetos en el rango de 0% a 100%.
// Get Object Sensor reflectivity in range of 0% - 100%.
int value = ObjectDetectorA.reflectivity();
// Print the reflectivity to the Brain's screen.
Brain.Screen.print(value);
setDetectionThreshold()#
The setDetectionThreshold(value, units) method sets the detection threshold for the Object Sensor to a specific value.
Parámetros |
Descripción |
|---|---|
|
Umbral de reflectividad para la detección de objetos. Rango de 0 a 100. |
|
The only valid unit for reflectivity is |
Devoluciones: Ninguna.
// Set the reflectivity threhold to 50%.
objdet.setDetectionThreshold(50);
isObjectDetected()#
The isObjectDetected() method returns if an object is detected.
Returns: true if an object is detected. false if one is not.
changed()#
The changed(callback) method registers a callback function for when the value of an Object Sensor changes.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando cambie el valor de un sensor de objetos. |
Devoluciones: Ninguna.
// Define the detectorChanged function with a void return
// type, showing it doesn't return a value.
void detectorChanged() {
// The Brain will print that the value of the Object Sensor
// changed on the Brain's screen.
Brain.Screen.print("Object Sensor value changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run detectorChanged when the value of the Object Sensor changes.
objdet.changed(detectorChanged);
}
objectDetected()#
The objectDetected(callback) method registers a callback function for when an object is detected.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se detecte un objeto. |
Devoluciones: Ninguna.
// Define the detected function with a void return type,
// showing it doesn't return a value.
void detected() {
// The Brain will print that the Object Sensor detected
// an object to the Brain's screen.
Brain.Screen.print("object detected");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run detected when the Object Sensor detects an object.
objdet.objectDetected(detected);
}
objectLost()#
The objectLost(callback) method registers a callback function for when an object is lost.
Este es un método sin espera y permite que el siguiente método se ejecute sin demora.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se pierda un objeto. |
Devoluciones: Ninguna.
// Define the lost function with a void return type,
// showing it doesn't return a value.
void lost() {
// The Brain will print that the Object Sensor
// lost an object to the Brain's screen.
Brain.Screen.print("object lost");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run lost when the Object Sensor loses an object.
objdet.objectLost(lost);
}