Revision 1418
Added encoder_get_x and encoder_get_v.
use get_v at your own risk
If encoder_read returns -1, this usually means battery is low.
If encoder_read returns a value greater than ENCODER_MAX, this usually means there are physical problems with the encoder.
test_encoders.c | ||
---|---|---|
21 | 21 |
usb_init(); |
22 | 22 |
encoders_init(); |
23 | 23 |
int encoder_left,encoder_right; |
24 |
int dx_left, dx_right; |
|
24 |
int x_left, x_right; |
|
25 |
int v_left, v_right; |
|
25 | 26 |
int tc; |
26 | 27 |
while(1) { |
27 | 28 |
/* button1 is pressed */ |
... | ... | |
40 | 41 |
usb_puti(encoder_right); |
41 | 42 |
usb_puts("\n"); |
42 | 43 |
|
43 |
dx_left = encoder_get_dx(LEFT);
|
|
44 |
dx_right = encoder_get_dx(RIGHT);
|
|
44 |
x_left = encoder_get_x(LEFT);
|
|
45 |
x_right = encoder_get_x(RIGHT);
|
|
45 | 46 |
usb_puts("Total Distance (left, right): "); |
46 |
usb_puti(dx_left);
|
|
47 |
usb_puti(x_left); |
|
47 | 48 |
usb_puts(", "); |
48 |
usb_puti(dx_right);
|
|
49 |
usb_puti(x_right); |
|
49 | 50 |
usb_puts("\n"); |
50 | 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 |
|
|
51 | 60 |
tc = encoder_get_tc(); |
52 | 61 |
usb_puts("Time count: "); |
53 | 62 |
usb_puti(tc); |
Also available in: Unified diff