### Author Topic: Fuzzy logic for a robot to follow a line  (Read 993 times)

0 Members and 1 Guest are viewing this topic.

#### kaiser444

• Beginner
• Posts: 5
##### Fuzzy logic for a robot to follow a line
« on: March 16, 2013, 03:43:49 AM »
Hi, i need some help. I am constructing a line follower. I am having problem to program it using fuzzy logic.
The robot has QTR-8RC Reflectance Sensor Array as a sensor to detect the line which consists of 8 phototransistors .
It is using differential drive steering meaning that it will have independently powered  2 DC motors.
The speed of both motor vary using PWM to perform turns and straight line driving.
The idea to use fuzzy logic is keep the line on the centre of the robot that is at the fourth and fifth phototransistor. If it is to the left of the centre, the left motor will run faster and if to the right the right will run faster.
It is using l293D motor driver and a 16F877A microcontroller.

Please help me, i am doing it for my final year project BENG Mechatronics.

#### jwatte

• Supreme Robot
• Posts: 1,343
##### Re: Fuzzy logic for a robot to follow a line
« Reply #1 on: March 17, 2013, 02:56:24 PM »
That looks like a very clear description of how that kind of robot typically works.
What is it that you need help with?

#### kaiser444

• Beginner
• Posts: 5
##### Re: Fuzzy logic for a robot to follow a line
« Reply #2 on: March 17, 2013, 11:58:48 PM »
I want help on how the fuzzy logic can work in this concept.
The sensor measures the capacitor discharge time. The latter varies with the reflectance.
The greater the reflectance, the lower is the discharge time.
The width of line will be the distance of 2 sensors. I am using it on white line with a black surface.
The inputs are the discharge times of each sensor and the output is the difference between the speed of the motor.

#### jwatte

• Supreme Robot
• Posts: 1,343
##### Re: Fuzzy logic for a robot to follow a line
« Reply #3 on: March 18, 2013, 01:21:52 PM »
Right, I understand how the RC detector works. In the end, you will be measuring the decay time using a digital level comparison, and you'll get a "degree of whiteness" from each of the 8 sensors in parallel.
The goal of the "fuzzy logic" module is then to take the measurements from the 8 sensors, and turn that into PWM control values (duty cycles) for the two motors.
Note that this would typically be done with a PID controller rather than "fuzzy logic," although sometimes the line between the two can blur :-)
The basic algorithm you want is:
- each motor drives at a standard value by default
- the more "to the left" the centroid of the white line is, the faster you want to drive the right wheel, and the slower you want to drive the left wheel
- driving a wheel faster means increasing the PWM duty cycle; driving it slower means decreasing the duty cycle.

Now, take that behavior, and encode it as the kind of fuzzy logic your project requires you to use. Done!