Sonar#
Inicializando la clase Sonar#
Un telémetro se crea utilizando el siguiente constructor:
Sonar(port)
Este constructor utiliza un parámetro:
Parámetro |
Descripción |
|---|---|
|
The 3-Wire Port “pair” that the Range Finder is connected to, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Sonar Class constructor.
# Create the Brain.
brain = Brain()
# Construct a Sonar "sonar" with the
# Sonar class.
sonar = Sonar(brain.three_wire_port.a)
This sonar object will be used in all subsequent examples throughout this API documentation when referring to Sonar class methods.
Métodos de clase#
distance()#
The distance(units) method returns the current distance the Range Finder is detecting on object at. The Range Finder will return a large positive number if no object is detected in range.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: La distancia medida por el telémetro.
# Print the current distance detected by the Range Finder
# to the Brain's screen.
brain.screen.print(sonar.distance(MM))
found_object()#
The found_object() method checks if an object is detected by the Range Finder in the range 0 - 1000 millimeters. The Range Finder will return True if an object is detected closer than 1000mm.
Returns: True if an object is detected by the Range Finder. False if one is not.
# Check if an object is 1000mm or closer to the Range Finder.
if sonar.found_object():
# Print to the Brain's screen that an object was found
brain.screen.print("object found")