Revision 1213
Finished rangefinders test implementation
test_rangefinders.c | ||
---|---|---|
1 |
#include <stdlib.h> |
|
2 |
|
|
1 | 3 |
#include "test_rangefinders.h" |
2 | 4 |
#include "global.h" |
3 | 5 |
|
... | ... | |
5 | 7 |
|
6 | 8 |
#include "comm_robot.h" |
7 | 9 |
|
10 |
#define wall_min 0 |
|
11 |
#define wall_max 1000 |
|
12 |
#define wall_inc 100 |
|
8 | 13 |
|
14 |
static uint16_t rangefinder_position (uint8_t num) |
|
15 |
{ |
|
16 |
switch (num) |
|
17 |
{ |
|
18 |
case 0: return 100; break; |
|
19 |
case 1: return 200; break; |
|
20 |
case 2: return 300; break; |
|
21 |
case 3: return 400; break; |
|
22 |
case 4: return 500; break; |
|
23 |
} |
|
24 |
|
|
25 |
return 0; |
|
26 |
} |
|
27 |
|
|
28 |
static void test_rangefinder_direction (uint8_t num, uint16_t wall_start, uint16_t wall_step, uint8_t num_steps, char *wall_direction_string) |
|
29 |
{ |
|
30 |
// Allocate space for the data on the stack |
|
31 |
uint16_t *data_wall =malloc (num_steps*sizeof (uint16_t)); |
|
32 |
uint16_t *data_rangefinder=malloc (num_steps*sizeof (uint16_t)); |
|
33 |
|
|
34 |
// Rotate the robot to the correct position |
|
35 |
turntable_rotate_to_position (rangefinder_position (num)); |
|
36 |
|
|
37 |
uint16_t wall=wall_start; |
|
38 |
for (uint8_t i=0; i<num_steps; ++i) |
|
39 |
{ |
|
40 |
wall_set_position (wall); |
|
41 |
|
|
42 |
data_wall [i]=wall_get_position (); |
|
43 |
data_rangefinder[i]=robot_read_rangefinder (num); |
|
44 |
|
|
45 |
wall+=wall_step; |
|
46 |
} |
|
47 |
|
|
48 |
// Send data |
|
49 |
usb_puts ("data rangefinder "); |
|
50 |
usb_puti (num); |
|
51 |
usb_puts (" "); |
|
52 |
usb_puts (wall_direction_string); |
|
53 |
|
|
54 |
for (uint8_t i=0; i<num_steps; ++i) |
|
55 |
{ |
|
56 |
usb_putc (' '); |
|
57 |
usb_puti (data_wall[i]); |
|
58 |
usb_putc ('/'); |
|
59 |
usb_puti (data_rangefinder[i]); |
|
60 |
} |
|
61 |
|
|
62 |
free (data_rangefinder); |
|
63 |
free (data_wall); |
|
64 |
|
|
65 |
usb_puts (NL); |
|
66 |
} |
|
67 |
|
|
68 |
|
|
9 | 69 |
void test_rangefinder (uint8_t num) |
10 | 70 |
{ |
11 | 71 |
if (num>4) return; |
... | ... | |
14 | 74 |
usb_puti(num); |
15 | 75 |
usb_puts(NL); |
16 | 76 |
|
17 |
// rotate to position |
|
18 |
// |
|
19 |
for (uint8_t direction=1; direction<=2; ++direction) |
|
20 |
{ |
|
21 |
// for (wall positions up/down) |
|
22 |
// { |
|
23 |
// set wall position |
|
24 |
// send (read) |
|
25 |
// receive (data) |
|
26 |
// } |
|
27 |
|
|
28 |
// Send data |
|
29 |
usb_puts ("data rangefinder "); |
|
30 |
usb_puti (num); |
|
31 |
usb_puts (" "); |
|
32 |
usb_puts (wall_direction_string (direction)); |
|
33 |
usb_puts (" 1/1 2/2 3/3 4/4 5/5 6/6 7/7 8/8" NL); |
|
34 |
} |
|
77 |
test_rangefinder_direction (num, wall_min, wall_inc, 10, "out"); |
|
78 |
test_rangefinder_direction (num, wall_max, -wall_inc, 10, "in"); |
|
35 | 79 |
} |
36 | 80 |
|
37 | 81 |
|
Also available in: Unified diff