Dasdadqwdrw
Dasdadqwdrw
Sensors
1 Introduction
Using two infrared (IR) sensors for line following allows for better accuracy
and stability compared to a single sensor. The key concepts covered in this
document include:
• Sensor placement
• PD (Proportional-Derivative) control logic
• LEGO EV3-G block programming implementation
2 PD Control Logic
The PD control logic is based on:
• Error Calculation: The difference between the left and right sensor
values.
• Proportional Term (P): Adjusts based on the current error.
• Derivative Term (D): Considers the rate of change of error to prevent
oscillations.
3 Variables Definition
Define the following variables in the LEGO EV3-G software:
• Setpoint: Ideal difference between sensors (typically 0)
• Kp: Proportional gain (e.g., 1.5)
• Kd: Derivative gain (e.g., 1.0)
• Error: Difference between sensor values
• Previous Error: Store error from the previous cycle
• Correction: Steering adjustment based on the PD calculation
1
4 Algorithm Steps
The following sequence should be implemented in an infinite loop:
1. Read values from the left and right IR sensors.
2. Calculate the error:
Error = Left Sensor − Right Sensor (1)
6 Tuning Considerations
• Increase Kp to make the robot more responsive.
• Increase Kd to reduce oscillations.
• Fine-tune values to achieve stable line following.