Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / mapping / matlab / testRobot / test.c @ 963

History | View | Annotate | Download (1.39 KB)

1
/** This test should just have the robot stay in place,
2
 * register the token ring, participate in the token ring,
3
 * and reply to packets when asked by the computer.*/
4

    
5
#include <dragonfly_lib.h>
6
#include <wireless.h>
7
#include <encoders.h>
8
#include "odometry.h"
9

    
10
#define MAP_REQUEST_GROUP 23
11

    
12
#define DATA_POINT 2 
13
#define DATA_REQUEST 3
14

    
15
int state;
16
int velocity;
17
char buf[100];
18

    
19
void respond(char type, int source, unsigned char* packet, int length);
20

    
21
PacketGroupHandler requestHandler = {MAP_REQUEST_GROUP, 
22
        NULL, NULL, respond, NULL};
23

    
24
int main(void)
25
{
26
    /* initialize components and join the token ring */
27
    dragonfly_init(ORB | RANGE | BOM | COMM);
28
    odometry_init();
29
    
30
        wl_init();
31
    wl_set_channel(0xE);
32
    wl_register_packet_group(&requestHandler);
33
    
34
    wl_token_ring_register();
35
    wl_token_ring_join();
36

    
37
    while(1)
38
    {
39
                wl_do();
40
    }
41

    
42
    wl_terminate();
43
    return 0;
44
}
45

    
46
void respond(char type, int source, unsigned char* packet, int length) {
47
           if(type==DATA_REQUEST){ 
48
                sprintf(buf, "received packet: %d\n", type);
49
            usb_puts(buf);
50
        
51
                int store[9];
52
                store[0] = 0;
53
            store[1] = 0;
54
            *((double*)(store + 2)) = 5.0;
55
            store[4] = 125;        // IR1 range
56
                store[5] = 125;        // IR2 range
57
                store[6] = 125;        // IR3 range
58
                store[7] = 125;        // IR4 range
59
                store[8] = 125;        // IR5 range
60

    
61
                wl_send_robot_to_robot_global_packet(MAP_REQUEST_GROUP, 
62
                        DATA_POINT, &store, 0, source, 0);
63
        }
64
}
65

    
66