Modifications

Sauter à la navigation Sauter à la recherche
9 030 octets ajoutés ,  30 avril 2018 à 19:33
Ligne 32 : Ligne 32 :     
=== emittersOn() ===
 
=== emittersOn() ===
 +
<syntaxhighlight lang="C">void emittersOn()</syntaxhighlight>
   −
{{traduction}}
+
Turn the IR LEDs on. This is mainly for use by the read method, and calling these functions before or after the reading the sensors will have no effect on the readings, but you may wish to use these for testing purposes. This method will only do something if the emitter pin specified in the constructor is not <font color="red">QTR_NO_EMITTER_PIN</font>.
    +
=== emittersOff() ===
 +
<syntaxhighlight lang="C">void emittersOff()</syntaxhighlight>
 +
 +
Turn the IR LEDs off. This is mainly for use by the read method, and calling these functions before or after the reading the sensors will have no effect on the readings, but you may wish to use these for testing purposes.
 +
 +
=== calibrate() ===
 +
<syntaxhighlight lang="C">void calibrate(unsigned char readMode = QTR_EMITTERS_ON)</syntaxhighlight>
 +
 +
Reads the sensors for calibration. The sensor values are not returned; instead, the maximum and minimum values found over time are stored internally and used for the '''readCalibrated()''' method. You can access the calibration (i.e raw max and min sensor readings) through the public member pointers '''calibratedMinimumOn''', '''calibratedMaximumOn''', '''calibratedMinimumOff''', and '''calibratedMaximumOff'''. Note that these pointers will point to arrays of length numSensors, as specified in the constructor, and they will only be allocated after '''calibrate()''' has been called. If you only calibrate with the emitters on, the calibration arrays that hold the off values will not be allocated.
 +
 +
=== readCalibrated() ===
 +
<syntaxhighlight lang="C">void readCalibrated(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON)</syntaxhighlight>
 +
 +
Returns sensor readings calibrated to a value between 0 and 1000, where 0 corresponds to a reading that is less than or equal to the minimum value read by '''calibrate()''' and 1000 corresponds to a reading that is greater than or equal to the maximum value. Calibration values are stored separately for each sensor, so that differences in the sensors are accounted for automatically.
 +
 +
=== readLine() ===
 +
<syntaxhighlight lang="C">unsigned int readLine(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON, unsigned char whiteLine = 0)</syntaxhighlight>
 +
 +
Operates the same as read calibrated, but with a feature designed for line following: this function returns an estimated position of the line. The estimate is made using a weighted average of the sensor indices multiplied by 1000, so that a return value of 0 indicates that the line is directly below sensor 0 (or was last seen by sensor 0 before being lost), a return value of 1000 indicates that the line is directly below sensor 1, 2000 indicates that it’s below sensor 2, etc. Intermediate values indicate that the line is between two sensors. The formula is:
 +
 +
<nowiki> 0*value0 + 1000*value1 + 2000*value2 + ...
 +
--------------------------------------------
 +
    value0  +  value1  +  value2 + ...</nowiki>
 +
 +
As long as your sensors aren’t spaced too far apart relative to the line, this returned value is designed to be monotonic, which makes it great for use in closed-loop PID control. Additionally, this method remembers where it last saw the line, so if you ever lose the line to the left or the right, it’s line position will continue to indicate the direction you need to go to reacquire the line. For example, if sensor 4 is your rightmost sensor and you end up completely off the line to the left, this function will continue to return 4000.
 +
 +
By default, this function assumes a dark line (high values) surrounded by white (low values). If your line is light on black, set the optional second argument whiteLine to true. In this case, each sensor value will be replaced by the maximum possible value minus its actual value before the averaging.
 +
 +
=== calibratedMinimumOn ===
 +
<syntaxhighlight lang="C">unsigned int* calibratedMinimumOn</syntaxhighlight>
 +
 +
The calibrated minimum values measured for each sensor, with emitters on. The pointers are unallocated and set to 0 until '''calibrate()''' is called, and then allocated to exactly the size required. Depending on the readMode argument to calibrate(), only the On or Off values may be allocated, as required. This and the following variables are made public so that you can use them for your own calculations and do things like saving the values to EEPROM, performing sanity checking, etc
 +
 +
=== calibratedMaximumOn ===
 +
<syntaxhighlight lang="C">unsigned int* calibratedMaximumOn</syntaxhighlight>
 +
 +
The calibrated maximum values measured for each sensor, with emitters on.
 +
 +
=== calibratedMinimumOff ===
 +
<syntaxhighlight lang="C">unsigned int* calibratedMinimumOff</syntaxhighlight>
 +
 +
The calibrated minimum values measured for each sensor, with emitters off.
 +
 +
=== calibratedMaximumOff ===
 +
<syntaxhighlight lang="C">unsigned int* calibratedMaximumOff</syntaxhighlight>
 +
 +
The calibrated maximum values measured for each sensor, with emitters off.
 +
 +
=== ~QTRSensors() - descructeur ===
 +
<syntaxhighlight lang="C">Destructor: ~QTRSensors()</syntaxhighlight>
 +
 +
The destructor for the QTRSensors class frees up memory allocated for the calibration arrays.
 +
 +
=== QTRSensorsRC() - constructeur ===
 +
<syntaxhighlight lang="C">Constructor: QTRSensorsRC()</syntaxhighlight>
 +
 +
This version of the constructor performs no initialization. If it is used, the user must call init() before using the methods in this class.
 +
 +
<syntaxhighlight lang="C">Constructor: QTRSensorsRC(unsigned char* digitalPins, unsigned char numSensors, unsigned int timeout = 2000, unsigned char emitterPin = QTR_NO_EMITTER_PIN);</syntaxhighlight>
 +
 +
This constructor just calls {{fname|init()}}, below.
 +
 +
<syntaxhighlight lang="C">void QTRSensorsRC::init(unsigned char* digitalPins, unsigned char numSensors, unsigned int timeout = 2000, unsigned char emitterPin = QTR_NO_EMITTER_PIN)</syntaxhighlight>
 +
 +
Initializes a QTR-RC (digital) sensor array.
 +
 +
* The array ''digitalPins'' should contain the Arduino digital pin numbers for each sensor.
 +
* ''numSensors'' specifies the length of the ''digitalPins'' array (the number of QTR-RC sensors you are using). numSensors must be no greater than 16.
 +
* ''timeout'' specifies the length of time in microseconds beyond which you consider the sensor reading completely black. That is to say, if the pulse length for a pin exceeds timeout, pulse timing will stop and the reading for that pin will be considered full black. It is recommended that you set timeout to be between 1000 and 3000 µs, depending on factors like the height of your sensors and ambient lighting. This allows you to shorten the duration of a sensor-reading cycle while maintaining useful measurements of reflectance.
 +
* ''emitterPin'' is the Arduino digital pin that controls whether the IR LEDs are on or off. This pin is optional and only exists on the 8A and 8RC QTR sensor arrays. If a valid pin is specified, the emitters will only be turned on during a reading. If the value <font color="red">QTR_NO_EMITTER_PIN</font> (255) is used, you can leave the emitter pin disconnected and the IR emitters will always be on.
 +
 +
=== QTRSensorsAnalog() - constructeur ===
 +
<syntaxhighlight lang="C">Constructor: QTRSensorsAnalog()</syntaxhighlight>
 +
 +
This version of the constructor performs no initialization. If this constructor is used, the user must call init() before using the methods in this class.
 +
 +
<syntaxhighlight lang="C">Constructor: QTRSensorsAnalog(unsigned char* analogPins, unsigned char numSensors, unsigned char numSamplesPerSensor = 4, unsigned char emitterPin = QTR_NO_EMITTER_PIN)</syntaxhighlight>
 +
 +
This constructor just calls {{fname|init()}}, below.
 +
 +
<syntaxhighlight lang="C">void init(unsigned char* analogPins, unsigned char numSensors, unsigned char numSamplesPerSensor = 4, unsigned char emitterPin = QTR_NO_EMITTER_PIN)</syntaxhighlight>
 +
 +
Initializes a QTR-A (analog) sensor array.
 +
 +
* The array ''pins'' should contain the Arduino analog input pin number for each sensor. For example, if pins is {0, 1, 7}, sensor 1 is on analog input 0, sensor 2 is on analog input 1, and sensor 3 is on analog input 7.
 +
* ''numSensors'' specifies the length of the analogPins array (the number of QTR-A sensors you are using). numSensors must be no greater than 16.
 +
* ''numSamplesPerSensor'' indicates the number of 10-bit analog samples to average per channel (per sensor) for each reading. The total number of analog-to-digital conversions performed will be equal to numSensors times numSamplesPerSensor. Increasing this parameter increases noise suppression at the cost of sample rate. This parameter must not exceed 64. Recommended value: 4.
 +
* ''emitterPin'' is the Arduino digital pin that controls whether the IR LEDs are on or off. This pin is optional and only exists on the 8A and 8RC QTR sensor arrays. If a valid pin is specified, the emitters will only be turned on during a reading. If the value QTR_NO_EMITTER_PIN (255) is used, you can leave the emitter pin disconnected and the IR emitters will always be on.
    
{{Pololu-Senseur-QTR-TRAILER}}
 
{{Pololu-Senseur-QTR-TRAILER}}
29 917

modifications

Menu de navigation