Project

General

Profile

Revision 1854

Added by Dan Jacobs over 13 years ago

lineFollow now supports merge. line drive is UNTESTED and has NO COMMENTS, but will provide higher level driving control

View differences:

trunk/code/projects/linefollowing/lineFollow.h
3 3
 #ifndef _LINEFOLLOW_H_
4 4
 #define _LINEFOLLOW_H_
5 5

  
6
#define WHITE			0
7
#define GREY			1
8
#define BLACK	 		2
6
#define LWHITE			0
7
#define LGREY			1
8
#define LBLACK	 		2
9 9
#define CENTER			3
10 10
#define NOLINE			-42
11 11
#define LINELOST		-1
12 12

  
13
#define NOBARCODE 		-2
14
#define INTERSECTION 		-25
15
#define FULL_LINE 		-26
16

  
17

  
18

  
13 19
/* 	lineFollow_init
14 20
	Must call before lineFollow
15 21
	Turns analog loop off
16 22
*/ 
17
void lineFollow_init();
23
void lineFollow_init(void);
18 24

  
19 25
/*	lineFollow
20 26
	Must call lineFollow first
......
22 28
*/
23 29
int lineFollow(int speed);
24 30

  
25
/*	turnLeft and turnRight
31
/*	turnLeft turnRight mergeLeft mergeRight
26 32
	Must be called inside a loop
27 33
	returns 0 when complete
28 34
*/
29
int turnLeft();
30
int turnRight();
35
int turnLeft(void);
36
int turnRight(void);
37
int mergeLeft(void);
38
int mergeRight(void);
31 39

  
32 40
/*	updateLine
33 41
	Reads in the analog values
......
43 51
*/
44 52
int lineLocate(int* colors);
45 53

  
46
//Not implemented yet, returns ???
47
void updateBarCode();
54
/*	updatebarCode
55
	Reads in and processes
56
	bar code data
57
*/
58
void updateBarCode(void);
48 59

  
49
/*	min
50
	returns the minimum of two values
60
/*	getBarCode
61
	returns a bar code, if
62
	available, otherwise NOBARCODE
51 63
*/
64
int getBarCode(void);
65

  
66
/*	min max
67
	returns the minimum/maximum of two values
68
*/
52 69
int min(int x, int y);
70
int max(int x, int y);
53 71

  
54 72
/*	motorLeft
55 73
	Commands the left motor
trunk/code/projects/linefollowing/main.c
12 12
	int barCode;
13 13
	while(1)
14 14
	{
15
		//for(int q=0; q<500; q++)
15
		
16

  
17
		for(int q=0; q<500; q++)
16 18
			barCode = lineFollow(200);
19
		while(mergeLeft());
20
		for(int q=0; q<1000; q++)lineFollow(200);
21
		
22
		continue;
17 23
		if(barCode==-25)while(turnRight());
18 24
		continue;
19 25
		if(barCode != -2 && barCode != LINELOST)
trunk/code/projects/linefollowing/lineFollow.c
1 1
#include "lineFollow.h"
2 2

  
3
#define NOBARCODE -2
4 3
#define CODESIZE 5 
5
#define INTERSECTION -25
6
#define FULL_LINE -26
7 4

  
8 5
int countHi = 0;
9 6
int countLo = 0;
......
75 72
}
76 73

  
77 74

  
78
int turnLeft()
75
int mergeLeft()
79 76
{
80
	motor_l_set(BACKWARD, 200);
81
	motor_r_set(FORWARD, 200);
77
	motor_l_set(FORWARD, 200);
78
	if(turnDistance!=21)motor_r_set(FORWARD, 230);
79
	else motor_r_set(FORWARD, 210);
82 80
	int colors[5];
83 81
	updateLine(colors);
84 82
	int position = lineLocate(colors);
85
	if(position>2 || position<-2)turnDistance++;
83
	if(position>3 || position<-3)turnDistance++;
86 84

  
87
	if(turnDistance>1)
85
	if(turnDistance>20)
88 86
	{
87
	turnDistance=21;
88
	
89 89
		if(position<3 && position>-3)
90 90
		{
91 91
			turnDistance = 0;
......
95 95
	return 1;
96 96
}
97 97

  
98

  
99
int mergeRight()
100
{
101
        motor_r_set(FORWARD, 200);
102
        if(turnDistance!=21)motor_l_set(FORWARD, 230);
103
        else motor_l_set(FORWARD, 210);
104
        int colors[5];
105
        updateLine(colors);
106
        int position = lineLocate(colors);
107
        if(position>3 || position<-3)turnDistance++;
108

  
109
        if(turnDistance>20)
110
        {
111
        turnDistance=21;
112

  
113
                if(position<3 && position>-3)
114
                {
115
                        turnDistance = 0;
116
                        return 0;
117
                } 
118
        }
119
        return 1;
120
}
121

  
122

  
123

  
124
int turnLeft()
125
{
126
        motor_l_set(BACKWARD, 200);
127
        motor_r_set(FORWARD, 200);
128
        int colors[5];
129
        updateLine(colors);
130
        int position = lineLocate(colors);
131
        if(position>2 || position<-2)turnDistance++;
132
        if(turnDistance>1)
133
        {
134
                if(position<3 && position>-3)
135
                {
136
                        turnDistance = 0;
137
                         return 0;
138
                }
139
        }
140
        return 1;
141
}
142

  
143

  
144

  
98 145
int turnRight()
99 146
{
100 147
        motor_r_set(BACKWARD, 200);
......
134 181
{	
135 182
	int ports[5] = {13, 12, 3, 2, 9};
136 183
	for(int i = 0; i<5; i++)
137
		values[i] = analog_get10(ports[i])<150 ? WHITE : BLACK;
184
		values[i] = analog_get10(ports[i])<150 ? LWHITE : LBLACK;
138 185
}
139 186

  
140 187

  
......
160 207

  
161 208
void updateBarCode()
162 209
{
210

  
211
	//NOTE: currently only uses one of the barcode sensors.
212

  
163 213
	//maps the sensors to the analog input ports
164 214
	int ports[2] = {8,1};
165 215
	int current[2];
166
//	current[0] = analog_get10(8);
167
	current[1] = analog_get10(1);
168
//	usb_puti(analog_get10(8));
169
//	usb_putc('\t');
170
//	usb_puti(analog_get10(1));
171
//	usb_putc('\n');
216
//	current[0] = analog_get10(ports[0]);
217
	current[1] = analog_get10(ports[1]);
172 218

  
173 219
	if(current[1]>500)
174 220
	{

Also available in: Unified diff