Explicación para el seguidor de línea

Robot URFI





Explicación para el seguidor de línea (Pista)

Line-following 

The line sensor is composed of an infrared light-emitting LED diode and a photodiode that detects infrared light. These diodes function as both emitters and receivers of signals, allowing the URFI robot to determine whether it is positioned on or off a line

Code and explanation:

  1. Library Inclusion:

    • The code begins by including a library called DRV8833. This library allows us to control a motor driver (which manages the motors) using simple instructions.
  2. Driver Initialization:

    • Next, we create an instance of the DRV8833 driver and name it driver. Think of this as setting up a virtual motor driver within our program.
  3. Pin Declarations:

    • We declare some global integer variables to represent pin numbers:
      • sensorLeft and sensorRight: These are the pins connected to the left and right line follower sensors.
      • motorA1motorA2motorB1, and motorB2: These are the pins connected to the motor driver for controlling the motors.
      • We also define the motor speeds (motorSpeedA and motorSpeedB).
  4. Setup Function:

    • The setup() function runs once when the program starts.
    • Inside this function:
      • We set the sensorLeft and sensorRight pins as inputs (to read sensor values).
      • We attach the motor pins to the driver instance, which configures them as outputs.
      • We initialize serial communication with the computer at a baud rate of 9600.
  5. Loop Function:

    • The loop() function runs repeatedly.
    • Inside this function:
      • We read the values from the left and right sensors (leftValue and rightValue).
      • Based on the sensor readings, we execute different actions:
        • If both sensors detect the line (HIGH-HIGH state), the robot moves forward (moveForward() function).
        • If neither sensor detects the line (LOW-LOW state), the robot moves backward (moveBackward() function).
        • If only the right sensor detects the line (LOW-HIGH state), the robot turns left (turnLeft() function).
        • If only the left sensor detects the line (HIGH-LOW state), the robot turns right (turnRight() function).
      • We also print the sensor values to the serial monitor.




Comentarios

Entradas populares de este blog

Traffic light algortihm