Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / slam / robot_main.c @ 53

History | View | Annotate | Download (2.35 KB)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3
#include <wl_token_ring.h>
4
#include <smart_run_around_fsm.h>
5

    
6
#define BOM_POST_DELAY 50
7
#define SLAM_PACKET_GROUP 11
8
#define CONTROL_PACKET_TYPE 'C'
9
#define REQUEST_PACKET_TYPE 'R'
10
#define ROBOT_RESPONSE 'I'
11

    
12
//REQUEST_PACKET_ORGANIZATION
13
#define REQUEST_PACKET_SIZE 50
14
#define IR_1_LOC 0
15
#define IR_2_LOC 1
16
#define IR_3_LOC 2
17
#define IR_4_LOC 3
18
#define IR_5_LOC 4
19
#define BOM_START_LOC 5
20

    
21
void bom_pre(void);
22
void bom_post(void);
23

    
24
//Packet Handler Functions
25
void timeout_handle(void);
26
void response_handle(int frame, int received);
27
void receive_handle(char type, int source, unsigned char* packet, int length);
28
void unregister(void);
29

    
30
char* make_request_packet(char* packet);
31

    
32
int IR[5];
33

    
34
int main(void)
35
{
36

    
37
  dragonfly_init(ALL_ON);
38
  
39
  wl_init();
40
 
41
  wl_token_ring_register();
42
  wl_token_ring_join();
43
  wl_token_ring_set_bom_functions(bom_pre, bom_post, get_max_bom);
44

    
45
  PacketGroupHandler packet_group_handler;
46
  packet_group_handler.groupCode=SLAM_PACKET_GROUP;
47
  packet_group_handler.timeout_handler=timeout_handle;
48
  packet_group_handler.handle_response=response_handle;
49
  packet_group_handler.handle_receive=receive_handle;
50
  packet_group_handler.unregister=unregister;
51

    
52
  wl_register_packet_group(&packet_group_handler);
53
  
54
  int i;
55
  while(1){
56
    wl_do();
57
    run_around_FSM(); 
58
    for(i=0;i<5;i++){
59
      IR[i]=range_read_distance(i);
60
    }
61
  }
62

    
63
  wl_unregister_packet_group(&packet_group_handler); 
64
}
65

    
66
void bom_pre(void){
67
    bom_on();
68
}
69

    
70
void bom_post(void){
71
    delay_ms(BOM_POST_DELAY);
72
    bom_off();
73
}
74

    
75
void timeout_handle(void){
76
    wl_token_ring_join();
77
}
78

    
79
void response_handle(int frame, int received){
80
  
81
}
82

    
83
void receive_handle(char type, int source, unsigned char* packet, int length){
84
  int i; 
85
  if(type==REQUEST_PACKET_TYPE){
86
    char packet[REQUEST_PACKET_SIZE]; 
87
    //Send a message back to our computer overlord.
88
    int len= make_request_packet(packet);
89
   
90
    wl_send_robot_to_robot_packet(SLAM_PACKET_GROUP, ROBOT_RESPONSE, packet, len, source , 0);
91
  }
92
  else if(type == CONTROL_PACKET_TYPE){
93
    for(i=0;i<length;i++){
94

    
95
    }
96
  }
97
}
98

    
99
int make_request_packet(char* packet){
100
  int size = wl_token_get_num_robots();
101
  int i,j;
102
  for(i=0;i<5;i++){
103
      packet[i] = IR[i];
104
  } 
105
  for(i=0;i<size;i++){
106
      for(j=0;j<size;j++){
107
       // wl_token_get_sensor_reading(int source, int dest);
108
      
109
      }
110
  }
111
  return size;
112
}
113