root / branches / simulator / projects / simulator / Rangefinder_with_noise.c @ 1007
History | View | Annotate | Download (966 Bytes)
1 | 1003 | nparis | /**
|
---|---|---|---|
2 | * @file rangefinder_with_noise.c
|
||
3 | * @author Colony Project
|
||
4 | *
|
||
5 | * @brief Returns rangefinder units with noise given distance in cm.
|
||
6 | *
|
||
7 | * Adds a random, normal amount of noise to a rangefinder
|
||
8 | * value given in cm. Returns approximate IR units .
|
||
9 | **/
|
||
10 | 991 | nparis | |
11 | |||
12 | 1003 | nparis | double get_rangefinder(double dist_in_cm) |
13 | { |
||
14 | double cm, IR, noise;
|
||
15 | // gauss_init(1, 0); // Params are chaos scalar and seed
|
||
16 | 991 | nparis | |
17 | 1003 | nparis | // noise = gauss_noise(void); // Gives ther noise
|
18 | 991 | nparis | |
19 | 1003 | nparis | cm = dist_in_cm; // Enter value between 7 and 18 for accurate results
|
20 | 991 | nparis | |
21 | 1003 | nparis | IR = 15.4005 * cm; // 15.4005 is an experimental value |
22 | 991 | nparis | |
23 | 1003 | nparis | |
24 | /* Rangefinder is good for values between 7 and 18.
|
||
25 | * 3 < cm < 7 AND 18 < cm < 22 are significantly more erroneous.
|
||
26 | * cm < 3 and cm > 22, rangefinder reports -1
|
||
27 | */
|
||
28 | if ( cm < 3 || cm > 22 ) |
||
29 | { |
||
30 | return -1; |
||
31 | } |
||
32 | else if( cm < 7 || cm > 18 ) |
||
33 | { |
||
34 | gauss_init(2, 0); |
||
35 | noise = gauss_noise(); |
||
36 | return IR + noise;
|
||
37 | } |
||
38 | else
|
||
39 | { |
||
40 | gauss_init(1, 0); |
||
41 | noise = gauss_noise(); |
||
42 | return IR + noise;
|
||
43 | } |
||
44 | |||
45 | } |