Αποστασιόμετρο#

Εισαγωγή#

The sonar class is used with the Ultrasonic Range Finder, which measures the distance to the nearest object using sound waves. It works by sending out an ultrasonic pulse and measuring how long it takes for the sound to bounce back.

Το αποστασιόμετρο VEX V5.

Κατασκευαστής κλάσης#

sonar(
  triport::port &port);

Καταστροφέας κλάσης#

Destroys the sonar object and releases associated resources.

virtual ~sonar();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

port

triport::port &

The first 3-Wire Port of a required two-port group used by the Range Finder. The Range Finder occupies two adjacent ports (A–B, C–D, E–F, or G–H) on either the Brain or a 3-Wire Expander. Specify the first port in the pair (A, C, E, or G), written as Brain.ThreeWirePort.X or ExpanderName.X where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.C).

Παραδείγματα#

// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);

Συναρτήσεις Μελών#

The sonar class includes the following member functions:

  • foundObject — Returns whether the Range Finder detects an object.

  • distance — Returns the distance between the Range Finder and the nearest detected object.

Before calling any sonar member functions, a sonar instance must be created, as shown below:

/* This constructor is required when using VS Code.
Range Finder configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);

foundObject#

Επιστρέφει εάν το Range Finder ανιχνεύει ένα αντικείμενο εντός του οπτικού του πεδίου.

Available Functions
bool foundObject();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Returns a bool representing whether the Range Finder detects an object:

  • true — The Range Finder is detecting an object.

  • false — The Range Finder is not detecting an object.

Examples
// Check if an object is detected.
if (RangeFinderA.foundObject()){
    // Print to screen on the brain that an object was found.
    Brain.Screen.print("object found");
}

distance#

Επιστρέφει την μετρούμενη απόσταση από το πλησιέστερο αντικείμενο που ανιχνεύεται από τον αισθητήρα.

Available Functions
double distance(
  distanceUnits units );

Parameters

Παράμετρος

Τύπος

Περιγραφή

units

distanceUnits

The unit that represents the distance: inches or mm — millimeters.

Return Values

Returns a double representing the distance in the specified units.

Examples
// Get the Range Finder distance in millimeters.
double value = RangeFinderA.distance(mm);

// Print the current distance detected by the Range Finder to the
// Brain's screen.
Brain.Screen.print(value);