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