Ligne 39 : |
Ligne 39 : |
| void loop() | | void loop() |
| { | | { |
− | // accélération : | + | // 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 | | // direction |
Ligne 48 : |
Ligne 49 : |
| if (throttle > 0 && steering > 0) | | if (throttle > 0 && steering > 0) |
| { | | { |
− | // Les deux signaux 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 61 : |
Ligne 63 : |
| 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 71 : |
Ligne 74 : |
| 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 78 : |
Ligne 81 : |
| } | | } |
| | | |
| + | // Appliquer les vitesses sur les moteurs |
| ZumoMotors::setSpeeds(left_speed, right_speed); | | ZumoMotors::setSpeeds(left_speed, right_speed); |
| } | | } |