root / trunk / code / projects / test / test_encoders.c @ 1418
History | View | Annotate | Download (1.49 KB)
1 |
/**
|
---|---|
2 |
* @file encoders unit test
|
3 |
*/
|
4 |
#include "serial.h" |
5 |
#include "time.h" |
6 |
#include "dio.h" |
7 |
#include "encoders.h" |
8 |
|
9 |
/**
|
10 |
* @brief Test encoders by outputting values to usb
|
11 |
*
|
12 |
* @test Tester should start a program to read data from the robot via usb
|
13 |
* (e.g. gtkterm). Turn on the robot on then turn each wheel manually.
|
14 |
* Make sure the output on the screen makes sense.
|
15 |
* Pressing button 1 resets total distance and time count
|
16 |
* @pre Depends on serial and dio to work correctly
|
17 |
*/
|
18 |
|
19 |
int testencoders(void) |
20 |
{ |
21 |
usb_init(); |
22 |
encoders_init(); |
23 |
int encoder_left,encoder_right;
|
24 |
int x_left, x_right;
|
25 |
int v_left, v_right;
|
26 |
int tc;
|
27 |
while(1) { |
28 |
/* button1 is pressed */
|
29 |
if (button1_read()) {
|
30 |
/* reset dx and tc */
|
31 |
encoder_rst_dx(LEFT); |
32 |
encoder_rst_dx(RIGHT); |
33 |
encoder_rst_tc(); |
34 |
} |
35 |
|
36 |
encoder_left = encoder_read(LEFT); |
37 |
encoder_right = encoder_read(RIGHT); |
38 |
usb_puts("Encoder values (left, right): ");
|
39 |
usb_puti(encoder_left); |
40 |
usb_puts(", ");
|
41 |
usb_puti(encoder_right); |
42 |
usb_puts("\n");
|
43 |
|
44 |
x_left = encoder_get_x(LEFT); |
45 |
x_right = encoder_get_x(RIGHT); |
46 |
usb_puts("Total Distance (left, right): ");
|
47 |
usb_puti(x_left); |
48 |
usb_puts(", ");
|
49 |
usb_puti(x_right); |
50 |
usb_puts("\n");
|
51 |
|
52 |
v_left = encoder_get_v(LEFT); |
53 |
v_right = encoder_get_v(RIGHT); |
54 |
usb_puts("Velocity (left, right): ");
|
55 |
usb_puti(v_left); |
56 |
usb_puts(", ");
|
57 |
usb_puti(v_right); |
58 |
usb_puts("\n");
|
59 |
|
60 |
tc = encoder_get_tc(); |
61 |
usb_puts("Time count: ");
|
62 |
usb_puti(tc); |
63 |
usb_puts("\n\r");
|
64 |
|
65 |
delay_ms(500);
|
66 |
} |
67 |
return 0; |
68 |
} |
69 |
|