Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / station / main.c @ 1218

History | View | Annotate | Download (3.45 KB)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3
#include <xbee.h>
4

    
5
#include "../common/comm_station_robot.h"
6

    
7
#include "global.h"
8
#include "hardware.h"
9
#include "tests.h"
10
#include "self_test.h"
11
#include "comm_server.h"
12
#include "comm_robot.h"
13

    
14
void interactive_main (void)
15
{
16
        while (1)
17
        {
18
                // Set the orbs to green/green
19
                orbs_set (0,255,0, 0,255,0);
20

    
21
                usb_puts (NL);
22
                usb_puts ("# Diagnostic station interactive mode" NL);
23
                usb_puts ("# Test (s)elf, (a)ll, (c)omm, (b)om, (r)angefinders, (m)otors, (e)ncoders" NL);
24

    
25
                char choice = usb_getc ();
26
                switch (choice) {
27
                        case 'c': case 'C': test_comm ();                                   break;
28
                        case 'a': case 'A': test_all ();                                    break; // test_all will test comm itself
29
                        case 'b': case 'B': if (require_comm ()) test_bom_all (true, true); break;
30
                        case 'r': case 'R': if (require_comm ()) test_rangefinder_all ();   break;
31
                        case 'm': case 'M': if (require_comm ()) test_motor_all ();         break;
32
                        case 'e': case 'E': if (require_comm ()) test_encoder_all ();       break;
33
                        case 's': case 'S': self_test ();                                   break;
34
                        default: break; // ignore it
35
                }
36
        }
37
}
38

    
39
int main_martin (void)
40
{
41
        dragonfly_init (0);
42
        orb_init ();
43

    
44
        // Initialize before using USB
45
        comm_server_init ();
46

    
47
        orb1_set (0, 0, 255);
48
        comm_robot_init ();
49
        orb2_set (0, 0, 255);
50
        
51
        int16_t left=69, right=105;
52
        
53
        while (1)
54
        {
55
                robot_set_motors (motor_direction_backward, 250, motor_direction_forward, 250);
56
                delay_ms (200);
57
        }
58
        
59
        // Encoder test
60
        while (0)
61
        {
62
                bool result=robot_read_encoders (&left, &right);
63
                usb_puti (result);
64
                usb_puts (" ");
65
                usb_puti (left);
66
                usb_puts (" ");
67
                usb_puti (right);
68
                usb_puts (NL);
69
                
70
                delay_ms (200);
71
        }
72
        
73
        while (1);
74
        return 0;
75
}
76

    
77
int main_john (void)
78
{
79
        dragonfly_init(0);
80
        orb_init();
81
        usb_init();
82
        analog_init(ADC_START);
83

    
84
        orbs_set(255, 0,255,255,0,255);
85

    
86
        rbom_debug();
87

    
88
        return 0;
89
}
90

    
91

    
92
int main_evan (void)
93
{
94
    dragonfly_init(0);
95

    
96
    usb_init ();
97

    
98
        usb_puts(NL NL NL);
99
        usb_puts("# Diagnostic station version " version_string " starting" NL);
100

    
101
    orb_init_pwm ();
102
        
103
        hardware_init ();
104
        comm_server_init ();
105
        comm_robot_init ();
106

    
107
        orb1_set (255, 0, 0); usb_puts("# Initializing wireless" NL);
108
        xbee_init ();
109
        wl_init();
110
        orb2_set (255, 0, 0); usb_puts("# Done" NL);
111

    
112

    
113
        // If button 1 is pressed after initialization of the wireless (which takes about 1s), run all tests.
114
        if (button1_read ())
115
                        test_all ();
116

    
117
        // If button 2 is pressed, go to interactive mode (green/green). If not, go to server mode (green/yellow).
118
        if (button2_read ())
119
                interactive_main ();
120
        else
121
        {
122
                // Set the orbs to green/yellow
123
                orbs_set (0,255,0, 255,127,0);
124

    
125
                server_main ();
126
        }
127

    
128
        while (1);
129
        return 0;
130
}
131

    
132
int main_default (void)
133
{
134
    dragonfly_init(0);
135

    
136
        // Initialize before using USB
137
        comm_server_init ();
138

    
139
        usb_puts(NL NL NL);
140
        usb_puts("# Diagnostic station version " version_string " starting" NL);
141

    
142
    orb_init_pwm ();
143
        hardware_init ();
144

    
145
        orb1_set (255, 0, 0); usb_puts("# Initializing wireless" NL);
146
        comm_robot_init ();
147
        orb2_set (255, 0, 0); usb_puts("# Done" NL);
148

    
149
        // If button 1 is pressed after initialization of the wireless (which takes about 1s), run all tests.
150
        if (button1_read ())
151
                        test_all ();
152

    
153
        // If button 2 is pressed, go to interactive mode (green/green). If not, go to server mode (green/yellow).
154
        if (button2_read ())
155
                interactive_main ();
156
        else
157
        {
158
                // Set the orbs to green/yellow
159
                orbs_set (0,255,0, 255,127,0);
160

    
161
                server_main ();
162
        }
163

    
164
        while (1);
165
        return 0;
166
}