Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / station / test_encoders.c @ 1204

History | View | Annotate | Download (1.65 KB)

1
#include "test_encoders.h"
2
#include "global.h"
3
#include "comm_robot.h"
4

    
5
#define num_measurements 4
6
#define velocity 200
7
#define on_delay 500
8
#define off_delay 800
9

    
10
static char *direction_string (uint8_t direction)
11
{
12
        if (direction==direction_forward)
13
                return "forward";
14
        else if (direction==BACKWARD)
15
                return "backward";
16
        else
17
                return "?";
18
}
19

    
20
static void test_encoders_direction (uint8_t direction1, uint8_t direction2)
21
{
22
        // reset_encoders ();
23
        for (uint8_t m=0; m<num_measurements; ++m)
24
        {
25
                robot_set_motors (direction1, velocity, direction2, velocity);
26
                delay_ms (on_delay);
27
                
28
                robot_set_motors_off ();
29
                delay_ms (off_delay);
30

    
31
                // TODO use the robot_set_motors_time function, but wait for completion
32
                // message from robot
33
                
34
                // TODO instead of waiting a fixed time, wait until the wheels
35
                // are not moving any more, using the station's encoders.
36
        
37
        //        send (turn motor on for time)
38
        //        wait (done)
39
        //        wait_stopped
40
        //        send (read encoders)
41
        //        receive (data)
42
        //        read encoders
43
        
44
        }
45

    
46
        // Send data
47
        for (uint8_t i=1; i<=2; ++i)
48
        {
49
                usb_puts ("data encoder ");
50
                usb_puti (i);
51
                usb_puts (" ");
52
                usb_puts (direction_string (i==1?direction1:direction2));
53
                usb_puts (" 100/100 200/200 300/300 400/400 500/500 600/600 700/700" NL);
54
        }
55
}
56

    
57
void test_encoder_all (void)
58
{
59
        usb_puts("# Testing encoders" NL);
60

    
61
        test_encoders_direction (direction_forward, BACKWARD);
62
        test_encoders_direction (BACKWARD, direction_forward);
63

    
64
        usb_puts("# Testing encoders finished" NL);
65
}
66

    
67
void test_encoder (uint8_t num)
68
{
69
        if (!(num==1 || num==2)) return;
70
        
71
        // TODO implement single encoder testing
72
        test_encoder_all ();
73
}