root / trunk / code / behaviors / formation_control / Circle / Code / encoder_test / encoder_test.c @ 1507
History | View | Annotate | Download (1.07 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <encoders.h> |
3 |
|
4 |
int main(void) |
5 |
{ |
6 |
|
7 |
dragonfly_init(ALL_ON); |
8 |
|
9 |
usb_init(); |
10 |
encoders_init(); |
11 |
int encoder_left,encoder_right;
|
12 |
int x_left, x_right;
|
13 |
int v_left, v_right;
|
14 |
int tc;
|
15 |
|
16 |
while(1) { |
17 |
/* button1 is pressed */
|
18 |
if (button1_read()) {
|
19 |
/* reset dx and tc */
|
20 |
encoder_rst_dx(LEFT); |
21 |
encoder_rst_dx(RIGHT); |
22 |
encoder_rst_tc(); |
23 |
} |
24 |
|
25 |
encoder_left = encoder_read(LEFT); |
26 |
encoder_right = encoder_read(RIGHT); |
27 |
usb_puts("Encoder values (left, right): ");
|
28 |
usb_puti(encoder_left); |
29 |
usb_puts(", ");
|
30 |
usb_puti(encoder_right); |
31 |
usb_puts("\r\n");
|
32 |
|
33 |
x_left = encoder_get_x(LEFT); |
34 |
x_right = encoder_get_x(RIGHT); |
35 |
usb_puts("Total Distance (left, right): ");
|
36 |
usb_puti(x_left); |
37 |
usb_puts(", ");
|
38 |
usb_puti(x_right); |
39 |
usb_puts("\r\n");
|
40 |
|
41 |
v_left = encoder_get_v(LEFT); |
42 |
v_right = encoder_get_v(RIGHT); |
43 |
usb_puts("Velocity (left, right): ");
|
44 |
usb_puti(v_left); |
45 |
usb_puts(", ");
|
46 |
usb_puti(v_right); |
47 |
usb_puts("\r\n");
|
48 |
|
49 |
tc = encoder_get_tc(); |
50 |
usb_puts("Time count: ");
|
51 |
usb_puti(tc); |
52 |
usb_puts("\r\n\r");
|
53 |
|
54 |
delay_ms(500);
|
55 |
} |
56 |
|
57 |
return 0; |
58 |
} |