Ligne 74 : |
Ligne 74 : |
| */ | | */ |
| | | |
− | // #define LOG_SERIAL // write log output to serial port | + | // #define LOG_SERIAL // écrire la sortie du log vers le port série |
| | | |
| #define LED 13 | | #define LED 13 |
− | Pushbutton button(ZUMO_BUTTON); // pushbutton on pin 12 | + | Pushbutton button(ZUMO_BUTTON); // bouton poussoir sur la broche 12 |
| | | |
− | // Accelerometer Settings | + | // Paramètre de l'accéléromètre |
− | #define RA_SIZE 3 // number of readings to include in running average of accelerometer readings | + | #define RA_SIZE 3 // Nombre de lectures à inclure dans la moyenne de accélération durant la phase de déplacement (running average of accelerometer readings) |
− | #define XY_ACCELERATION_THRESHOLD 2400 // for detection of contact (~16000 = magnitude of acceleration due to gravity) | + | #define XY_ACCELERATION_THRESHOLD 2400 // pour la détection de contact (~16000 = mangitude de l'accélération du à la gravité) |
| | | |
− | // Reflectance Sensor Settings | + | // Configuration du réseau senseur infrarouge (Reflectance Sensor) |
| #define NUM_SENSORS 6 | | #define NUM_SENSORS 6 |
| unsigned int sensor_values[NUM_SENSORS]; | | unsigned int sensor_values[NUM_SENSORS]; |
− | // this might need to be tuned for different lighting conditions, surfaces, etc. | + | // Ce paramètre pourrait avoir besoin d'être mis au point en fonction des conditions de luminosité, surface, etc. |
| #define QTR_THRESHOLD 1500 // microseconds | | #define QTR_THRESHOLD 1500 // microseconds |
| ZumoReflectanceSensorArray sensors(QTR_NO_EMITTER_PIN); | | ZumoReflectanceSensorArray sensors(QTR_NO_EMITTER_PIN); |
| | | |
− | // Motor Settings | + | // Configuration moteur |
| ZumoMotors motors; | | ZumoMotors motors; |
| | | |
− | // these might need to be tuned for different motor types | + | // Ces valeurs pourrait avoir besoin d'être mis-au-pnt en fonction des différents types de moteur |
− | #define REVERSE_SPEED 200 // 0 is stopped, 400 is full speed | + | #define REVERSE_SPEED 200 // 0 = à l'arrêt, 400 = pleine vitesse |
| #define TURN_SPEED 200 | | #define TURN_SPEED 200 |
| #define SEARCH_SPEED 200 | | #define SEARCH_SPEED 200 |
− | #define SUSTAINED_SPEED 400 // switches to SUSTAINED_SPEED from FULL_SPEED after FULL_SPEED_DURATION_LIMIT ms | + | #define SUSTAINED_SPEED 400 // Vitesse soutenue SUSTAINED_SPEED après la vitesse FULL_SPEED appliquée durant FULL_SPEED_DURATION_LIMIT ms |
| #define FULL_SPEED 400 | | #define FULL_SPEED 400 |
| #define STOP_DURATION 100 // ms | | #define STOP_DURATION 100 // ms |
Ligne 107 : |
Ligne 107 : |
| | | |
| enum ForwardSpeed { SearchSpeed, SustainedSpeed, FullSpeed }; | | enum ForwardSpeed { SearchSpeed, SustainedSpeed, FullSpeed }; |
− | ForwardSpeed _forwardSpeed; // current forward speed setting | + | ForwardSpeed _forwardSpeed; // Configuration de la vitesse actuelle |
| unsigned long full_speed_start_time; | | unsigned long full_speed_start_time; |
| #define FULL_SPEED_DURATION_LIMIT 250 // ms | | #define FULL_SPEED_DURATION_LIMIT 250 // ms |
| | | |
− | // Sound Effects | + | // Effet sonore |
| ZumoBuzzer buzzer; | | ZumoBuzzer buzzer; |
− | const char sound_effect[] PROGMEM = "O4 T100 V15 L4 MS g12>c12>e12>G6>E12 ML>G2"; // "charge" melody | + | const char sound_effect[] PROGMEM = "O4 T100 V15 L4 MS g12>c12>e12>G6>E12 ML>G2"; // Mélodie de "charge" |
− | // use V0 to suppress sound effect; v15 for max volume | + | // Utiliser V0 pour supprimer le son; v15 pour volume max |
| | | |
− | // Timing | + | // Minutage |
| unsigned long loop_start_time; | | unsigned long loop_start_time; |
| unsigned long last_turn_time; | | unsigned long last_turn_time; |
| unsigned long contact_made_time; | | unsigned long contact_made_time; |
− | #define MIN_DELAY_AFTER_TURN 400 // ms = min delay before detecting contact event | + | #define MIN_DELAY_AFTER_TURN 400 // ms = délais minimum avant la détection d'un événement collision |
− | #define MIN_DELAY_BETWEEN_CONTACTS 1000 // ms = min delay between detecting new contact event | + | #define MIN_DELAY_BETWEEN_CONTACTS 1000 // ms = délais minimum entre avant la détection d'un nouvel événement collision |
| | | |
− | // RunningAverage class | + | // classe RunningAverage |
− | // based on RunningAverage library for Arduino | + | // Basé sur la bibliothèque RunningAverage pour Arduino |
| // source: http://playground.arduino.cc/Main/RunningAverage | | // source: http://playground.arduino.cc/Main/RunningAverage |
| template <typename T> | | template <typename T> |
Ligne 146 : |
Ligne 146 : |
| }; | | }; |
| | | |
− | // Accelerometer Class -- extends the LSM303 Library to support reading and averaging the x-y acceleration | + | // Classe Accelerometer -- étend la bibliothèque LSM303 pour supporter la lecture et moyenne des vecteurs |
− | // vectors from the onboard LSM303DLHC accelerometer/magnetometer | + | // d'accélérations x-y provenant de l'accéléromètre/magnétomètre LSM303DLHC. |
| class Accelerometer : public LSM303 | | class Accelerometer : public LSM303 |
| { | | { |
Ligne 177 : |
Ligne 177 : |
| | | |
| Accelerometer lsm303; | | Accelerometer lsm303; |
− | boolean in_contact; // set when accelerometer detects contact with opposing robot | + | boolean in_contact; // activé lorsque l'accéléromètre détecte un contact avec le robot opposé |
| | | |
− | // forward declaration | + | // pré-déclaration de setForwardSpeed - vitesse en marche avant |
| void setForwardSpeed(ForwardSpeed speed); | | void setForwardSpeed(ForwardSpeed speed); |
| | | |
| void setup() | | void setup() |
| { | | { |
− | // Initiate the Wire library and join the I2C bus as a master | + | // Initialise la bibliothèque Wire et joindre le bus I2C comme maître |
| Wire.begin(); | | Wire.begin(); |
| | | |
− | // Initiate LSM303 | + | // Initialiser le LSM303 |
| lsm303.init(); | | lsm303.init(); |
| lsm303.enable(); | | lsm303.enable(); |
Ligne 198 : |
Ligne 198 : |
| randomSeed((unsigned int) millis()); | | randomSeed((unsigned int) millis()); |
| | | |
− | // uncomment if necessary to correct motor directions | + | // Dé-commentez les ligne pour corriger le sens de rotation des moteurs (si nécessaire) |
| //motors.flipLeftMotor(true); | | //motors.flipLeftMotor(true); |
| //motors.flipRightMotor(true); | | //motors.flipRightMotor(true); |
Ligne 218 : |
Ligne 218 : |
| digitalWrite(LED, LOW); | | digitalWrite(LED, LOW); |
| | | |
− | // play audible countdown | + | // jouer le décompte audio |
| for (int i = 0; i < 3; i++) | | for (int i = 0; i < 3; i++) |
| { | | { |
Ligne 228 : |
Ligne 228 : |
| delay(1000); | | delay(1000); |
| | | |
− | // reset loop variables | + | // Réinitialiser les variables de loop() |
− | in_contact = false; // 1 if contact made; 0 if no contact or contact lost | + | in_contact = false; // 1 si collision; 0 si pas de collision (ou perte de contact) |
| contact_made_time = 0; | | contact_made_time = 0; |
− | last_turn_time = millis(); // prevents false contact detection on initial acceleration | + | last_turn_time = millis(); // Evite les fausses détections de collision durant l'accélération initiale |
| _forwardSpeed = SearchSpeed; | | _forwardSpeed = SearchSpeed; |
| full_speed_start_time = 0; | | full_speed_start_time = 0; |
Ligne 240 : |
Ligne 240 : |
| if (button.isPressed()) | | if (button.isPressed()) |
| { | | { |
− | // if button is pressed, stop and wait for another press to go again | + | // Si le bouton est pressé, arrêter et attente une autre pression sur le bouton |
| motors.setSpeeds(0, 0); | | motors.setSpeeds(0, 0); |
| button.waitForRelease(); | | button.waitForRelease(); |
Ligne 257 : |
Ligne 257 : |
| if (sensor_values[0] < QTR_THRESHOLD) | | if (sensor_values[0] < QTR_THRESHOLD) |
| { | | { |
− | // if leftmost sensor detects line, reverse and turn to the right | + | // Si le senseur le plus à gauche détecte une ligne, marche arrière et tourner à droite |
| turn(RIGHT, true); | | turn(RIGHT, true); |
| } | | } |
| else if (sensor_values[5] < QTR_THRESHOLD) | | else if (sensor_values[5] < QTR_THRESHOLD) |
| { | | { |
− | // if rightmost sensor detects line, reverse and turn to the left | + | // Si le senseur le plus a droite détecte une ligne, marche arrière et tourner à gauche |
| turn(LEFT, true); | | turn(LEFT, true); |
| } | | } |
− | else // otherwise, go straight | + | else // Sinon, aller tout droit |
| { | | { |
| + | // vérifier si contact; signaler contact |
| if (check_for_contact()) on_contact_made(); | | if (check_for_contact()) on_contact_made(); |
| int speed = getForwardSpeed(); | | int speed = getForwardSpeed(); |
Ligne 273 : |
Ligne 274 : |
| } | | } |
| | | |
− | // execute turn | + | // Exécuter une rotation |
− | // direction: RIGHT or LEFT | + | // direction: RIGHT (droite) ou LEFT (gauche) |
− | // randomize: to improve searching | + | // Angle aléatoire pour améliorer la recherche |
| void turn(char direction, bool randomize) | | void turn(char direction, bool randomize) |
| { | | { |
Ligne 283 : |
Ligne 284 : |
| #endif | | #endif |
| | | |
− | // assume contact lost | + | // assume qu'il n'y a pas de contact (pas de collision). |
| on_contact_lost(); | | on_contact_lost(); |
| | | |
Ligne 323 : |
Ligne 324 : |
| } | | } |
| | | |
− | // check for contact, but ignore readings immediately after turning or losing contact | + | // Vérifie s'il y a une collision/contact, mais ignore les lectures immédiatement après une rotation ou une perte de contact |
| bool check_for_contact() | | bool check_for_contact() |
| { | | { |
Ligne 332 : |
Ligne 333 : |
| } | | } |
| | | |
− | // sound horn and accelerate on contact -- fight or flight | + | // Klaxon et accélération au contact/collision -- frapper ou s'échapper (fight or flight) |
| void on_contact_made() | | void on_contact_made() |
| { | | { |
Ligne 345 : |
Ligne 346 : |
| } | | } |
| | | |
− | // reset forward speed | + | // Réinitialiser la vitesse (de la marche avant) |
| void on_contact_lost() | | void on_contact_lost() |
| { | | { |
Ligne 356 : |
Ligne 357 : |
| } | | } |
| | | |
− | // class Accelerometer -- member function definitions | + | // classe Accelerometer -- définition des fonctions membres |
| | | |
− | // enable accelerometer only | + | // Activer uniquement l'accéléromètre |
− | // to enable both accelerometer and magnetometer, call enableDefault() instead | + | // Appeler enableDefault() pour activer l'accéléromètre et le magnétomètre. |
| void Accelerometer::enable(void) | | void Accelerometer::enable(void) |
| { | | { |
− | // Enable Accelerometer | + | // Activer l'accéléromètre |
| // 0x27 = 0b00100111 | | // 0x27 = 0b00100111 |
− | // Normal power mode, all axes enabled | + | // Mode d'alimentation normal, activer tous les axes |
| writeAccReg(LSM303::CTRL_REG1_A, 0x27); | | writeAccReg(LSM303::CTRL_REG1_A, 0x27); |
| | | |
| if (getDeviceType() == LSM303::device_DLHC) | | if (getDeviceType() == LSM303::device_DLHC) |
− | writeAccReg(LSM303::CTRL_REG4_A, 0x08); // DLHC: enable high resolution mode | + | writeAccReg(LSM303::CTRL_REG4_A, 0x08); // DLHC: activer le mode haute résolution |
| } | | } |
| | | |
Ligne 441 : |
Ligne 442 : |
| | | |
| | | |
− | // RunningAverage class | + | // Classe RunningAverage |
− | // based on RunningAverage library for Arduino | + | // basé sur la bibliothèque RunningAverage d'Arduino |
| // source: http://playground.arduino.cc/Main/RunningAverage | | // source: http://playground.arduino.cc/Main/RunningAverage |
− | // author: Rob.Tillart@gmail.com | + | // autheur: Rob.Tillart@gmail.com |
− | // Released to the public domain | + | // public domain |
| | | |
| template <typename T> | | template <typename T> |
Ligne 464 : |
Ligne 465 : |
| } | | } |
| | | |
− | // resets all counters | + | // Réinitialiser tous les compteurs |
| template <typename T> | | template <typename T> |
| void RunningAverage<T>::clear() | | void RunningAverage<T>::clear() |
Ligne 471 : |
Ligne 472 : |
| _idx = 0; | | _idx = 0; |
| _sum = zero; | | _sum = zero; |
− | for (int i = 0; i< _size; i++) _ar[i] = zero; // needed to keep addValue simple | + | for (int i = 0; i< _size; i++) _ar[i] = zero; // Nécessaire pour maintenir addValue simple |
| } | | } |
| | | |
− | // adds a new value to the data-set | + | // Ajouter une nouvelle valeur au data-set (ensemble des données) |
| template <typename T> | | template <typename T> |
| void RunningAverage<T>::addValue(T f) | | void RunningAverage<T>::addValue(T f) |
Ligne 482 : |
Ligne 483 : |
| _sum += _ar[_idx]; | | _sum += _ar[_idx]; |
| _idx++; | | _idx++; |
− | if (_idx == _size) _idx = 0; // faster than % | + | if (_idx == _size) _idx = 0; // plus rapide que % |
| if (_cnt < _size) _cnt++; | | if (_cnt < _size) _cnt++; |
| } | | } |
| | | |
− | // returns the average of the data-set added so far | + | // Retourne la moyenne des valeurs du data-set |
| template <typename T> | | template <typename T> |
| T RunningAverage<T>::getAverage() const | | T RunningAverage<T>::getAverage() const |
Ligne 494 : |
Ligne 495 : |
| } | | } |
| | | |
− | // fill the average with a value | + | // Rempli la moyenne avec une valeur |
− | // the param number determines how often value is added (weight) | + | // Le paramètre number détermine ne nombre de fois que la valeur est ajouté (poids) |
− | // number should preferably be between 1 and size | + | // number devrait être entre 1 et size (la taille) |
| template <typename T> | | template <typename T> |
| void RunningAverage<T>::fillValue(T value, int number) | | void RunningAverage<T>::fillValue(T value, int number) |
Ligne 506 : |
Ligne 507 : |
| } | | } |
| } | | } |
| + | </syntaxhighlight> |
| | | |
− | </syntaxhighlight>
| |
| {{Pololu-Zumo-Shield-Arduino-TRAILER}} | | {{Pololu-Zumo-Shield-Arduino-TRAILER}} |