Différences entre versions de « Pololu-Senseur-QTR-Utiliser »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 17 : Ligne 17 :
  
 
== Les fonctions ==
 
== Les fonctions ==
=== read ===
+
=== read() ===
 
<syntaxhighlight lang="C">void read(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON)</syntaxhighlight>
 
<syntaxhighlight lang="C">void read(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON)</syntaxhighlight>
  
xxx
+
Reads the raw sensor values into an array. There '''MUST''' be space for as many values as there were sensors specified in the constructor. The values returned are a measure of the reflectance in units that depend on the type of sensor being used, with higher values corresponding to lower reflectance (a black surface or a void). QTR-xA sensors will return a raw value between 0 and 1023. QTR-xRC sensors will return a raw value between 0 and the timeout argument (in units of microseconds) provided in the constructor (which defaults to 2000).
 +
 
 +
The functions that read values from the sensors all take an argument readMode, which specifies the kind of read that will be performed. Several options are defined: <font color="red">QTR_EMITTERS_OFF</font> specifies that the reading should be made without turning on the infrared (IR) emitters, in which case the reading represents ambient light levels near the sensor; <font color="red">QTR_EMITTERS_ON</font> specifies that the emitters should be turned on for the reading, which results in a measure of reflectance; and <font color="red">QTR_EMITTERS_ON_AND_OFF</font> specifies that a reading should be made in both the on and off states. The values returned when the <font color="red">QTR_EMITTERS_ON_AND_OFF</font> option is used are given by '''on + max – off''', where on is the reading with the emitters on, off is the reading with the emitters off, and '''max''' is the maximum sensor reading. This option can reduce the amount of interference from uneven ambient lighting. Note that emitter control will only work if you specify a valid emitter pin in the constructor.
 +
 
 +
{{underline|Exemple d'utilisation:}}
 +
 
 +
<syntaxhighlight lang="C">
 +
unsigned int sensor_values[8];
 +
sensors.read(sensor_values);
 +
</syntaxhighlight>
 +
 
 +
=== emittersOn() ===
 +
 
 +
{{traduction}}
 +
 
  
 
{{Pololu-Senseur-QTR-TRAILER}}
 
{{Pololu-Senseur-QTR-TRAILER}}

Version du 28 avril 2018 à 21:59

QTRSensor Command Reference

For QTR-xA sensors, you will want to instantiate a QTRSensorsAnalog object, and for QTR-xRC sensors you will want to instantiate a QTRSensorsRC object. Aside from the constructors, these two objects provide the same methods for reading sensor values (both classes are derived from the same abstract base class). The library provides access to the raw sensors values as well as to high level functions including calibration and line-tracking.

This section of the library defines an object for each of the two QTR sensor types, with the QTRSensorsAnalog class intended for use with QTR-xA sensors and the QTRSensorsRC class intended for use with QTR-xRC sensors. This library takes care of the differences between the QTR-xA and QTR-xRC sensors internally, providing you with a common interface to both sensors. The only external difference is in the constructors. This is achieved by having both of these classes derive from the abstract base class QTRSensors. This base class cannot be instantiated.

The QTRSensorsAnalog and QTRSensorsRC classes must be instantiated before they are used. This allows multiple QTR sensor arrays to be controlled independently as separate QTRSensors objects.

For calibration, memory is allocated using the malloc() command. This conserves RAM: if all eight sensors are calibrated with the emitters both on an off, a total of 64 bytes would be dedicated to storing calibration values. However, for an application where only three sensors are used, and the emitters are always on during reads, only 6 bytes are required.

Internally, this library uses all standard Arduino functions such as micros() for timing and analogRead() or digitalRead() for getting the sensor values, so it should work on all Arduinos without conflicting with other libraries.

Les fonctions

read()

void read(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON)

Reads the raw sensor values into an array. There MUST be space for as many values as there were sensors specified in the constructor. The values returned are a measure of the reflectance in units that depend on the type of sensor being used, with higher values corresponding to lower reflectance (a black surface or a void). QTR-xA sensors will return a raw value between 0 and 1023. QTR-xRC sensors will return a raw value between 0 and the timeout argument (in units of microseconds) provided in the constructor (which defaults to 2000).

The functions that read values from the sensors all take an argument readMode, which specifies the kind of read that will be performed. Several options are defined: QTR_EMITTERS_OFF specifies that the reading should be made without turning on the infrared (IR) emitters, in which case the reading represents ambient light levels near the sensor; QTR_EMITTERS_ON specifies that the emitters should be turned on for the reading, which results in a measure of reflectance; and QTR_EMITTERS_ON_AND_OFF specifies that a reading should be made in both the on and off states. The values returned when the QTR_EMITTERS_ON_AND_OFF option is used are given by on + max – off, where on is the reading with the emitters on, off is the reading with the emitters off, and max is the maximum sensor reading. This option can reduce the amount of interference from uneven ambient lighting. Note that emitter control will only work if you specify a valid emitter pin in the constructor.

Exemple d'utilisation:

unsigned int sensor_values[8];
sensors.read(sensor_values);

emittersOn()



Basé sur "Arduino Library for the Pololu QTR Reflectance Sensors" de Pololu (www.pololu.com/docs/0J19/1) - Traduit en Français par shop.mchobby.be CC-BY-SA pour la traduction
Toute copie doit contenir ce crédit, lien vers cette page et la section "crédit de traduction". Traduit avec l'autorisation expresse de Pololu (www.pololu.com)

Based on "Arduino Library for the Pololu QTR Reflectance Sensors" from Pololu (www.pololu.com/docs/0J19/1) - Translated to French by shop.mchobby.be CC-BY-SA for the translation
Copies must includes this credit, link to this page and the section "crédit de traduction" (translation credit). Translated with the Pololu's authorization (www.pololu.com)