Project

General

Profile

Statistics
| Revision:

root / branches / encoders / code / projects / colonet / utilities / robot_slave / rangefinder.h @ 1390

History | View | Annotate | Download (1.62 KB)

1 13 emarinel
#ifndef _RANGEFINDER_H_
2
#define _RANGEFINDER_H_
3
4
#define RANGE_IN0 PIN_C0
5
6
#define IR1 6
7
#define IR2 5
8
#define IR3 4
9
#define IR4 3
10
#define IR5 2
11
12
13
/* Nasty IR approximation table
14
  I'm using this for the heck of it.  We can do whatever.
15

16
  Note the minimum value is .4V (20), and the maximum is 2.6V (133).
17
  Gives distance in mm.
18

19
  excel formula(valid for inputs 20-133):  ROUND(2353.6*(E2^(-1.1146))*10,0)
20

21
  This is only valid for the GP2D12, with objects directly ahead and more than
22
  10cm from the detector.  See the datasheet for more information.
23
*/
24
#define MIN_IR_ADC8 20
25
#define MAX_IR_ADC8 133
26
static int IR_dist_conversion[114] = {
27
800,791,751,714,681,651,623,597,574,552,531,512,494,478,462,447
28
,434,421,408,397,386,375,365,356,347,338,330,322,315,307,301,294
29
,288,282,276,270,265,260,255,250,245,241,237,232,228,224,221,217
30
,213,210,207,203,200,197,194,191,189,186,183,181,178,176,173,171
31
,169,166,164,162,160,158,156,154,152,151,149,147,145,144,142,140
32
,139,137,136,134,133,131,130,129,127,126,125,124,122,121,120,119
33
,118,117,115,114,113,112,111,110,109,108,107,106,105,105,104,103
34
,102,101
35
};
36
37
#define RANGE_CTRL PIN_C1
38
//old range_crtl
39
//#define RANGE_CTRL PIN_A7
40
41
#define THRESHOLD1 114
42
#define THRESHOLD2 110
43
#define THRESHOLD3 101
44
#define THRESHOLD4 85
45
#define OFFSET1 65
46
#define OFFSET2 63
47
#define OFFSET3 60
48
#define GAIN1 1525
49
#define GAIN2 1520
50
#define GAIN3 1525
51
#define CONTINUITY_FIX 39
52
#define MAX_DIST 61
53
54
#define MIN_DIST 8
55
56
57
void range_init(void);
58
int read_distance(int range_id);
59
int linearize_distance(int reading);
60
int log_distance(int distance);
61
62
#endif