Robojoy challenge class

5-1-1 Make the line trace robot from "Hajimete-Robot"


Line Trace robot (PD control)

Previously introduced as "Introduction to Line Trace", if I want to improve the movement of the robot until now, I had to resolve that in terms of hardware (by changing the position of the center of gravity), but this time I'd like to resolve in software.
I tried to add "D control (derivative control)" to the program (Program3). D control is a control method that alters the output, depending on the amount of change of the input value. I think some people has not learned "differential", I would fix the word "speed" in this case.
To determine the speed has been calculated by the "current value of the light sensor" subtracts "the value of the light sensor of the previous loop." Parts are framed in blue, which is a subtraction.
I called the PD control in accordance with the P control and D control. We are also introduced PD control in the sixth of the "Introduction to Algorithms", please try to refer that.

I tried to figure the principle of work.
When the light sensor is a status of "White 50: Black 50", the position is 0. In this case, the power will be applied to the motor of the left and right are the same.
If the ratio of the "black" light sensor has increased rapidly, the motor of the left is plus and the motor of the right is negative power will be transmitted. The Arrow drawn in purple is its power.

I tried to run the program.
Match the light sensor to the position of the "50 white: black 50", I will run the program.
Proportional gain (P Gain variables) is1.3, differential gain (D Gain variable) is set to 25.
Phenomenon that has been around a curve is almost gone! By modifying the software, we are able to cover maneuverability of the robot

I thought it is a perfect program...... Now, I found a bug.
The robot was working fine in the evening, but it was made off the track in the daytime.

Cause of the failure is due to "uneven brightness", it is because the brightness of the surroundings is different in the starting point and in the middle of the course. If the value of the light sensor makes only 10 differences, it will not run properly.
When this could happen, I should do change the way of control called "line detection based on an absolute value."