Table of Contents

Constantin CARAPENCEA, Marian-Daniel CRĂCIUNESCU - Line Follower - Gigel3000

Autorii pot fi contactați la adresele: Login pentru adresa

Login pentru adresa

Introducere

Scurtă prezentare:

Descriere generală

Schma bloc a sistemului:

Cei 8 senozori dispuși în linie, perpendicular pe direcția de mers a mașinii întorc 1 logic atunci când se află deasupra de negru și 0 logic atunci când se află deasupra de alb. În bucla principală de procesare, microcontroller-ul citește aceste valori și pa baza lor stabilește poziția relativă a liniei față de centrul mașinii. Astfel stabilește direcția spre care mașina trebuie sa vireze. Acesta comandă motoarele prin intermediul punții H astfel:

Hardware Design

Lista de piese:

img_1637.jpg

0j615.600.jpg

tens70.jpg

Schema circuitului:

Software Design

Ca mediu de dezvoltare s-a folosit Notepad++ și WinAVR 2010. Bootloader-ul este cel folosit la laborator (Bootloader).

proiect.c
#include <avr\io.h>
#include <avr\interrupt.h>
#define F_CPU 16000000
#include <util/delay.h>
 
#define BV(i) (1 << i)
#define IS_SET(r, i) (r & BV(i))
 
inline unsigned char getLinePosition()
{
	unsigned char i, count, sum;
	sum = 0;
	count = 0;
 
	// verifica senzori
	for (i = 0; i < 8; i++)
	{
		if (IS_SET(PINA, i))
		{
			sum += i + 1;
			count++;
		}
	}
 
	// intoarce media valorilor sau 0 daca s-a pierdut linia
	return count == 0 ? 0 : sum / count;
}
 
inline void goForward()
{
	PORTD |= BV(4); // input 1 high
	PORTD |= BV(5); // input 3 high
	PORTD &= ~BV(6); // input 2 low
	PORTD &= ~BV(7); // input 4 low
 
	PORTD |= BV(2);
	PORTD |= BV(3);
}
 
inline void goLeft()
{
	PORTD |= BV(4); // input 1 high
	PORTD |= BV(5); // input 3 high
	PORTD &= ~BV(6); // input 2 low
	PORTD &= ~BV(7); // input 4 low
 
	PORTD &= ~BV(2);
	PORTD |= BV(3);
}
 
inline void goRight()
{
	PORTD |= BV(4); // input 1 high
	PORTD |= BV(5); // input 3 high
	PORTD &= ~BV(6); // input 2 low
	PORTD &= ~BV(7); // input 4 low
 
	PORTD &= ~BV(3);
	PORTD |= BV(2);
}
 
inline void rotateLeft()
{
	PORTD &= ~BV(4); // input 1 low
	PORTD |= BV(5); // input 3 high
	PORTD |= BV(6); // input 2 high
	PORTD &= ~BV(7); // input 4 low
 
	PORTD |= BV(2);
	PORTD |= BV(3);
}
 
inline void rotateRight()
{
	PORTD |= BV(4); // input 1 high
	PORTD &= ~BV(5); // input 3 low
	PORTD &= ~BV(6); // input 2 low
	PORTD |= BV(7); // input 4 high
 
	PORTD |= BV(2);
	PORTD |= BV(3);
}
 
 
int main()
{
	PORTA = 0xff; // citire senzori
	DDRA = 0x00;
 
	DDRD = ~0;
	PORTD=0;
 
	char lastDirection = 0;
	while (1)
	{
		unsigned char lp = getLinePosition();
		if (lp == 0) // s-a pierdut linia
		{
			if (lastDirection == 0)
			{
				rotateLeft();
			}
			else
			{
				rotateRight();
			}
		}
		else if (lp < 4) // linia e in stanga
		{
			goLeft();
			lastDirection = 0;
		}
		else if (lp > 5) // linia e in dreapta
		{
			goRight();
			lastDirection = 1;
		}
		else // linia e in centru
		{
			goForward();
		}
	}
 
	return 0;
}

Rezultate Obţinute

Testare bara senzori (debugging cu un led :-D):

dsc00207.jpg

Lipire placa proiect la puntea H:

dsc00211.jpg

Bancul de Lucru:

dsc00212.jpg

Debug senzori folosind leduri:

The Adobe Flash Plugin is needed to display this content.

Gigel varianta alpha

The Adobe Flash Plugin is needed to display this content.

Gigel 3000 in actiune:

The Adobe Flash Plugin is needed to display this content.

Concluzii

Proiectul a fost foarte interesant si… chiar a functionat!!!

Download

Cod Sursă: Arhiva