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.
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.
- The code begins by including a library called
Driver Initialization:
- Next, we create an instance of the
DRV8833
driver and name itdriver
. Think of this as setting up a virtual motor driver within our program.
- Next, we create an instance of the
Pin Declarations:
- We declare some global integer variables to represent pin numbers:
sensorLeft
andsensorRight
: These are the pins connected to the left and right line follower sensors.motorA1
,motorA2
,motorB1
, andmotorB2
: These are the pins connected to the motor driver for controlling the motors.- We also define the motor speeds (
motorSpeedA
andmotorSpeedB
).
- We declare some global integer variables to represent pin numbers:
Setup Function:
- The
setup()
function runs once when the program starts. - Inside this function:
- We set the
sensorLeft
andsensorRight
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.
- We set the
- The
Loop Function:
- The
loop()
function runs repeatedly. - Inside this function:
- We read the values from the left and right sensors (
leftValue
andrightValue
). - 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).
- If both sensors detect the line (HIGH-HIGH state), the robot moves forward (
- We also print the sensor values to the serial monitor.
- We read the values from the left and right sensors (
- The
Comentarios
Publicar un comentario