Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / test / test_encoders.c @ 1389

History | View | Annotate | Download (1.3 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 dx_left, dx_right;
25
        int tc;
26
        while(1) {
27
                /* button1 is pressed */
28
                if (button1_read()) {
29
                        /* reset dx and tc */
30
                        encoder_rst_dx(LEFT);
31
                        encoder_rst_dx(RIGHT);
32
                        encoder_rst_tc();
33
                }
34

    
35
                encoder_left = encoder_read(LEFT);
36
                encoder_right = encoder_read(RIGHT);
37
                usb_puts("Encoder values (left, right): ");
38
                usb_puti(encoder_left); 
39
                usb_puts(", ");
40
                usb_puti(encoder_right); 
41
                usb_puts("\n");
42

    
43
                dx_left = encoder_get_dx(LEFT);
44
                dx_right = encoder_get_dx(RIGHT);
45
                usb_puts("Total Distance (left, right): ");
46
                usb_puti(dx_left);
47
                usb_puts(", ");
48
                usb_puti(dx_right);
49
                usb_puts("\n");
50

    
51
                tc = encoder_get_tc();
52
                usb_puts("Time count: ");
53
                usb_puti(tc);
54
                usb_puts("\n\r");
55

    
56
                delay_ms(500);
57
        }
58
        return 0;
59
}
60