root / trunk / code / projects / test / test_encoders.c @ 1465
History | View | Annotate | Download (1.41 KB)
1 |
/**
|
---|---|
2 |
* @file encoders unit test
|
3 |
*/
|
4 |
#include <dragonfly_lib.h> |
5 |
|
6 |
/**
|
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 |
|
16 |
int testencoders(void) |
17 |
{ |
18 |
int encoder_left,encoder_right;
|
19 |
int x_left, x_right;
|
20 |
int v_left, v_right;
|
21 |
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 |
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 |
usb_puts("\n");
|
38 |
|
39 |
x_left = encoder_get_x(LEFT); |
40 |
x_right = encoder_get_x(RIGHT); |
41 |
usb_puts("Total Distance (left, right): ");
|
42 |
usb_puti(x_left); |
43 |
usb_puts(", ");
|
44 |
usb_puti(x_right); |
45 |
usb_puts("\n");
|
46 |
|
47 |
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 |
tc = encoder_get_tc(); |
56 |
usb_puts("Time count: ");
|
57 |
usb_puti(tc); |
58 |
usb_puts("\n\r");
|
59 |
|
60 |
delay_ms(500);
|
61 |
} |
62 |
return 0; |
63 |
} |
64 |
|