Ligne 13 : |
Ligne 13 : |
| == Code == | | == Code == |
| Voici une copie de l'exemple avec traduction des commentaires pour vous aider à mieux comprendre le fonctionnement du croquis/sketch | | Voici une copie de l'exemple avec traduction des commentaires pour vous aider à mieux comprendre le fonctionnement du croquis/sketch |
| + | |
| + | Nous recommandons de toujours charger l'exemple depuis les codes d'exemples de la bibliothèque Zumo. |
| | | |
| <syntaxhighlight lang="c"> | | <syntaxhighlight lang="c"> |
| #include <ZumoMotors.h> | | #include <ZumoMotors.h> |
| | | |
− | #define THROTTLE_PIN 4 // throttle channel from RC receiver | + | #define THROTTLE_PIN 4 // Canal accélération (throttle) du récepteur RC |
− | #define STEERING_PIN 5 // steering channel from RC receiver | + | #define STEERING_PIN 5 // Canal de direction (steering) du récepteur RC |
− | #define LED_PIN 13 // user LED pin | + | #define LED_PIN 13 // broche de la LED utilisateur |
| | | |
− | #define MAX_SPEED 400 // max motor speed | + | #define MAX_SPEED 400 // Vitesse max moteur |
− | #define PULSE_WIDTH_DEADBAND 25 // pulse width difference from 1500 us (microseconds) to ignore (to compensate for control centering offset) | + | #define PULSE_WIDTH_DEADBAND 25 // Différence de largeur d'impulsion depuis 1500 us (microseconds) à ignorer (pour compenser l'offset/décalage de la position centrale) |
− | #define PULSE_WIDTH_RANGE 350 // pulse width difference from 1500 us to be treated as full scale input (for example, a value of 350 means | + | #define PULSE_WIDTH_RANGE 350 // Différence de largeur d'impulsion depuis 1500 us qui doit être considéré comme l'amplitude totale de l'entrée (valeur max) |
− | // any pulse width <= 1150 us or >= 1850 us is considered full scale) | + | // Par exemple une valeur de 350 signifie l'utilisation d'une largeur d'impulsion (pulse width) <= 1150 us OU >= 1850 us |
| + | // est considérée comme ayant atteint l'amplitude maximale de l'entrée (de la manette de contrôle) |
| | | |
| | | |
Ligne 31 : |
Ligne 34 : |
| pinMode(LED_PIN, OUTPUT); | | pinMode(LED_PIN, OUTPUT); |
| | | |
− | // uncomment one or both of the following lines if your motors' directions need to be flipped | + | // Décommenter une ou deux ligne pour corriger la direction du moteur (si nécessaire) |
| //motors.flipLeftMotor(true); | | //motors.flipLeftMotor(true); |
| //motors.flipRightMotor(true); | | //motors.flipRightMotor(true); |
Ligne 38 : |
Ligne 41 : |
| void loop() | | void loop() |
| { | | { |
| + | // accélération : Attend que l'entrée passe à HIGH puis démarre le compteur de temps. |
| + | // le comtpeur de temps est stoppé dès que le signal passe à LOW |
| int throttle = pulseIn(THROTTLE_PIN, HIGH); | | int throttle = pulseIn(THROTTLE_PIN, HIGH); |
| + | // direction |
| int steering = pulseIn(STEERING_PIN, HIGH); | | int steering = pulseIn(STEERING_PIN, HIGH); |
| | | |
Ligne 45 : |
Ligne 51 : |
| if (throttle > 0 && steering > 0) | | if (throttle > 0 && steering > 0) |
| { | | { |
− | // both RC signals are good; turn on LED | + | // Les deux signaux RC sont correctes; allumer la LED |
| digitalWrite(LED_PIN, HIGH); | | digitalWrite(LED_PIN, HIGH); |
| | | |
− | // RC signals encode information in pulse width centered on 1500 us (microseconds); subtract 1500 to get a value centered on 0 | + | // Le signal RC encode l'information sur un signal ayant une largeur d'impulsion "centrale" de 1500 us (microseconds); |
| + | // Soustraire 1500 pour obtenir une valeur centrée sur 0 |
| throttle -= 1500; | | throttle -= 1500; |
| steering -= 1500; | | steering -= 1500; |
| | | |
− | // apply deadband | + | // Appliquer la zone morte (deadband) où toute variation du signal est ignoré |
| if (abs(throttle) <= PULSE_WIDTH_DEADBAND) | | if (abs(throttle) <= PULSE_WIDTH_DEADBAND) |
| throttle = 0; | | throttle = 0; |
Ligne 58 : |
Ligne 65 : |
| steering = 0; | | steering = 0; |
| | | |
− | // mix throttle and steering inputs to obtain left & right motor speeds | + | // Combiner les valeurs d'accélération (throttle) et de direction (steering) pour |
| + | // obtenir la vitesse du moteur gauche et du moteur droit |
| left_speed = ((long)throttle * MAX_SPEED / PULSE_WIDTH_RANGE) - ((long)steering * MAX_SPEED / PULSE_WIDTH_RANGE); | | left_speed = ((long)throttle * MAX_SPEED / PULSE_WIDTH_RANGE) - ((long)steering * MAX_SPEED / PULSE_WIDTH_RANGE); |
| right_speed = ((long)throttle * MAX_SPEED / PULSE_WIDTH_RANGE) + ((long)steering * MAX_SPEED / PULSE_WIDTH_RANGE); | | right_speed = ((long)throttle * MAX_SPEED / PULSE_WIDTH_RANGE) + ((long)steering * MAX_SPEED / PULSE_WIDTH_RANGE); |
| | | |
− | // cap speeds to max | + | // Limiter les vitesses (borner) à des vitesses max |
| left_speed = min(max(left_speed, -MAX_SPEED), MAX_SPEED); | | left_speed = min(max(left_speed, -MAX_SPEED), MAX_SPEED); |
| right_speed = min(max(right_speed, -MAX_SPEED), MAX_SPEED); | | right_speed = min(max(right_speed, -MAX_SPEED), MAX_SPEED); |
Ligne 68 : |
Ligne 76 : |
| else | | else |
| { | | { |
− | // at least one RC signal is not good; turn off LED and stop motors | + | // Au moins un des signaux RC n'est pas correct; Eteindre la la LED et stopper les moteurs |
| digitalWrite(LED_PIN, LOW); | | digitalWrite(LED_PIN, LOW); |
| | | |
Ligne 75 : |
Ligne 83 : |
| } | | } |
| | | |
| + | // Appliquer les vitesses sur les moteurs |
| ZumoMotors::setSpeeds(left_speed, right_speed); | | ZumoMotors::setSpeeds(left_speed, right_speed); |
| } | | } |