Project

General

Profile

Revision 411

Laid out what I think will be the structure of SLAM for colony. This is an interesting project, and I think my strategy is a good one. It's laid out in the file server_main.c so read it if you're interested. I threw together the bare bones, but I realized that I might need to change my data_request code so that the order of packet arrival doesn't matter.

View differences:

branches/slam/code/projects/colonet/DataRequests/robot/data_response.c
16 16
  Prepares the robot to receive and respond to data requests.
17 17
*/
18 18
void data_response_init(void){
19
  usb_init();
20
  usb_puts("USB initialized!\n\r");
19
  //usb_init();
20
  //usb_puts("USB initialized!\n\r");
21 21
  range_init();
22 22
  pgh.groupCode=DATA_REQUEST_GROUP; 
23 23
  pgh.timeout_handler = NULL;
......
25 25
  pgh.handle_receive = handle_receive;
26 26
  pgh.unregister = NULL;
27 27
  wl_register_packet_group(&pgh);
28
  usb_puts("Packet Group Registered!\n\r");
28
  //usb_puts("Packet Group Registered!\n\r");
29 29
}
30 30

  
31 31

  
......
35 35
void handle_receive(char type, int source, unsigned char* packet, int length){
36 36
  
37 37
  char buf[MAX_PACKET_LENGTH]; 
38
  int size, i;
39
  usb_puts("Got a packet!\n\r");
38
  int size;
39
  int i=0;
40
  short int robot_id, ir_value; 
41
  char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
42
  
40 43
  switch(type){
41 44
  case BOM_TYPE:
42 45
    
43
    short int i=0, robot_id; 
44 46
    wl_token_iterator_begin();
45 47
    while(wl_token_iterator_has_next() && i<=96){
46 48
      robot_id = wl_token_iterator_next();
47
      (*buf)[i++] = (char)((robot_id>>8) & 255);
48
      (*buf)[i++] = (char)(robot_id & 255);
49
      //TODO Ensure that wl_token_get.... returns the expected char. 
50
      (*buf)[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
49
      buf[i++] = (char)((robot_id>>8) & 255);
50
      buf[i++] = (char)(robot_id & 255);
51
      buf[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
51 52
    }
52 53
    
53 54
    //i is one greater than the index of the last byte... the size.
54 55
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,BOM_TYPE,buf,i,source,0);
56
    break;
55 57
  
56 58
  case IR_TYPE:
57 59

  
58
    usb_puts("Generating an IR packet.\n");
59
    char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
60
    int i;
61
    short ir_value; 
60
    //usb_puts("Generating an IR packet.\n");
62 61
    for(i=0;i<5;i++){
63 62
      ir_value = (short)range_read_distance(ranges[i]);
64 63
      buf[2*i] = (char)((ir_value>>8)&255);   
65 64
      buf[2*i+1] = (ir_value&255);   
66
      usb_puts("Distance :\t");
67
      usb_puti(ir_value);
68
      usb_puts("\n");
65
      //usb_puts("Distance :\t");
66
      //usb_puti(ir_value);
67
      //usb_puts("\n");
69 68
    }
70 69
    size = 10;
71 70

  
72
    usb_puts("Packet Contents: ");
73
    for(i = 0; i<size;i++){
74
        usb_puti(buf[i]);
71
    //usb_puts("Packet Contents: ");
72
    /*for(i = 0; i<size;i++){
73
        //usb_puti(buf[i]);
75 74
        usb_putc(' ');
76
    }
75
    }*/
77 76
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,IR_TYPE,buf,size,source,0);
78 77
  
78
    break; 
79 79
  
80
  
81 80
  case ENCODER_TYPE:
82 81
    break; 
83 82
    //Not yet supported.
......
105 104
* 
106 105
*/
107 106
int generate_IR_packet(char** buf){
108
  usb_puts("Generating an IR packet.\n");
107
  //usb_puts("Generating an IR packet.\n");
109 108
  char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
110 109
  int i;
111 110
  short ir_value; 
......
113 112
    ir_value = (short)range_read_distance(ranges[i]);
114 113
    (*buf)[2*i] = (char)((ir_value>>8)&255);   
115 114
    (*buf)[2*i+1] = (ir_value&255);   
116
    usb_puts("Distance :\t");
117
    usb_puti(ir_value);
118
    usb_puts("\n");
115
    //usb_puts("Distance :\t");
116
    //usb_puti(ir_value);
117
    //usb_puts("\n");
119 118
  }
120 119
  return 10;
121 120
}
branches/slam/code/projects/colonet/DataRequests/server/data_requests.c
82 82
      break;
83 83
    
84 84
    case ENCODER_TYPE:
85
      /*I have no idea, unsupported.
85
      I have no idea, unsupported.
86 86
      break;
87 87
  }
88 88
  free(data->packet);
branches/slam/code/projects/slam/robot/data_response.c
16 16
  Prepares the robot to receive and respond to data requests.
17 17
*/
18 18
void data_response_init(void){
19
  usb_init();
20
  usb_puts("USB initialized!\n\r");
19
  //usb_init();
20
  //usb_puts("USB initialized!\n\r");
21 21
  range_init();
22 22
  pgh.groupCode=DATA_REQUEST_GROUP; 
23 23
  pgh.timeout_handler = NULL;
......
25 25
  pgh.handle_receive = handle_receive;
26 26
  pgh.unregister = NULL;
27 27
  wl_register_packet_group(&pgh);
28
  usb_puts("Packet Group Registered!\n\r");
28
  //usb_puts("Packet Group Registered!\n\r");
29 29
}
30 30

  
31 31

  
......
35 35
void handle_receive(char type, int source, unsigned char* packet, int length){
36 36
  
37 37
  char buf[MAX_PACKET_LENGTH]; 
38
  int size, i;
39
  usb_puts("Got a packet!\n\r");
38
  int size;
39
  int i=0;
40
  short int robot_id, ir_value; 
41
  char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
42
  
40 43
  switch(type){
41 44
  case BOM_TYPE:
42 45
    
43
    short int i=0, robot_id; 
44 46
    wl_token_iterator_begin();
45 47
    while(wl_token_iterator_has_next() && i<=96){
46 48
      robot_id = wl_token_iterator_next();
47
      (*buf)[i++] = (char)((robot_id>>8) & 255);
48
      (*buf)[i++] = (char)(robot_id & 255);
49
      //TODO Ensure that wl_token_get.... returns the expected char. 
50
      (*buf)[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
49
      buf[i++] = (char)((robot_id>>8) & 255);
50
      buf[i++] = (char)(robot_id & 255);
51
      buf[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
51 52
    }
52 53
    
53 54
    //i is one greater than the index of the last byte... the size.
54 55
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,BOM_TYPE,buf,i,source,0);
56
    break;
55 57
  
56 58
  case IR_TYPE:
57 59

  
58
    usb_puts("Generating an IR packet.\n");
59
    char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
60
    int i;
61
    short ir_value; 
60
    //usb_puts("Generating an IR packet.\n");
62 61
    for(i=0;i<5;i++){
63 62
      ir_value = (short)range_read_distance(ranges[i]);
64 63
      buf[2*i] = (char)((ir_value>>8)&255);   
65 64
      buf[2*i+1] = (ir_value&255);   
66
      usb_puts("Distance :\t");
67
      usb_puti(ir_value);
68
      usb_puts("\n");
65
      //usb_puts("Distance :\t");
66
      //usb_puti(ir_value);
67
      //usb_puts("\n");
69 68
    }
70 69
    size = 10;
71 70

  
72
    usb_puts("Packet Contents: ");
73
    for(i = 0; i<size;i++){
74
        usb_puti(buf[i]);
71
    //usb_puts("Packet Contents: ");
72
    /*for(i = 0; i<size;i++){
73
        //usb_puti(buf[i]);
75 74
        usb_putc(' ');
76
    }
75
    }*/
77 76
    wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,IR_TYPE,buf,size,source,0);
78 77
  
78
    break; 
79 79
  
80
  
81 80
  case ENCODER_TYPE:
82 81
    break; 
83 82
    //Not yet supported.
......
105 104
* 
106 105
*/
107 106
int generate_IR_packet(char** buf){
108
  usb_puts("Generating an IR packet.\n");
107
  //usb_puts("Generating an IR packet.\n");
109 108
  char ranges[] = {IR1,IR2,IR3,IR4,IR5}; 
110 109
  int i;
111 110
  short ir_value; 
......
113 112
    ir_value = (short)range_read_distance(ranges[i]);
114 113
    (*buf)[2*i] = (char)((ir_value>>8)&255);   
115 114
    (*buf)[2*i+1] = (ir_value&255);   
116
    usb_puts("Distance :\t");
117
    usb_puti(ir_value);
118
    usb_puts("\n");
115
    //usb_puts("Distance :\t");
116
    //usb_puti(ir_value);
117
    //usb_puts("\n");
119 118
  }
120 119
  return 10;
121 120
}
branches/slam/code/projects/slam/robot/smart_run_around_fsm.c
11 11
void run_around_init(void)
12 12
{
13 13
  range_init();
14
  analog_init();
14
  analog_init(ADC_START);
15 15
  motors_init();
16 16
  orb_init();
17 17
  orb_enable();
branches/slam/code/projects/slam/robot/robot_main.c
1
#include "dragonfly_lib.h"
2
#include "data_response.h"
3
#include "smart_run_around_fsm.h"
4

  
5
int main(void){
6
  wl_init(); 
7
  data_response_init();
8
  wl_token_ring_register();
9
  wl_token_ring_join();
10
  run_around_init();
11
  while(1){
12
    run_around_FSM();
13
  }
14
  wl_terminate();
15
}
branches/slam/code/projects/slam/computer/data_requests.c
82 82
      break;
83 83
    
84 84
    case ENCODER_TYPE:
85
      /*I have no idea, unsupported.
85
      I have no idea, unsupported.
86 86
      break;
87 87
  }
88 88
  free(data->packet);
branches/slam/code/projects/slam/computer/server_main.c
1
#include "data_requests.h"
2
#include "queue.h"
3

  
4

  
5
typedef struct dataNode{
6
  long timeStamp;
7
  char type;
8
  union{
9
      BomNode* u_b;
10
      short* u_s;
11
      unsigned char* u_c;
12
  } data;
13
} Data;
14

  
15
/*
16
This is the game plan if anyone is interested.
17
Each robot will go for an unspecified amount of time,
18
accruing encoder, BOM, and IR data.  The IR and encoders
19
will be used to generate heat maps for each robot, starting
20
at the center, decreasing in certainty (i.e. the amount of
21
'color' put on during a time unit will be spread over a greater
22
area) over time according to the physical limitations of 
23
the measuring devices.
24

  
25
When the uncertainty gets too high, a new map will be allocated for
26
the robot.
27

  
28
The BOM data will be used to orient individual maps to one another.
29
Along with physical limitations on the size of the environment, and
30
hopefully some brainstorming to do with triangularization and what not,
31
the heat maps will become increasingly well oriented.
32

  
33
Finally, after a currently unspecified amount of time, the maps which have
34
been properly oriented (this could probably just be all of them due to the nature
35
of the heat maps,) will be summed up into one meta map! Metamap will undergo some
36
signal processing, probably in the form of a second order gradient, to get a map
37
of magnitudes, which we will try to further reduce to lines.  These lines are the
38
walls of the environment.
39

  
40
In time, it is possible that this "unspecfied amount of time" could become a continuous
41
computation, but I haven't put much thought into how this will scale.  It will almost 
42
definitely depend upon the chosen resolution of the heat map.
43

  
44
I do want people working with me, this should be a lot of fun,
45
I'm coming to accept the fact that I'm not a very good programmer,
46
but I think this is a solid method of doing SLAM.
47
*/
48

  
49
/** 
50
* @brief An array of maps.
51
*/
52
int*** map_array;
53

  
54
/** 
55
* @brief An array of short's indicating which robot each map belongs to.
56
*/
57
int* map_ids[];
58

  
59
Queue* dataQueue;
60

  
61
/*These functions simply add the data to the queue.*/
62
void bom_handler(BomNode** head);
63
void ir_handler(short** data);
64
void encoder_handler(unsigned char** data);
65

  
66
void slam_analyze();
67
void bom_analyze(BomNode* head);
68
void ir_analyze(short* data);
69
void encoder_analyze(unsigned char* data);
70

  
71
int main(void){
72
  data_requests_init(bom_handler,IR_handler,encoder_handler);
73
  dataQueue = queue_create();
74
  slam_analyze(); 
75
}
76

  
77
void slam_analyze(){
78
  Data* current_data;
79
  while(1){
80
    if(!queue_is_empty(dataQueue)){
81
      current_data = (Data*)queue_remove(dataQueue);
82
      switch(current_data->type){
83
      
84
      case(BOM_TYPE):
85
        bom_analyze(current_data->data.u_b);
86
        break;
87
      
88
      case(IR_TYPE):
89
        ir_analyze(current_data->data.u_s);
90
        break;
91

  
92
      case(ENCODER_TYPE):
93
        encoder_analyze(current_data->data.u_c);
94
        break;
95
      }
96
    }
97
  }
98
}
99

  
100
void bom_analyze(BomNode* head){
101

  
102
}
103

  
104
void ir_analyze(short* data){
105

  
106
}
107

  
108
void encoder_analyze(unsigned char* data){
109

  
110
}
111

  
112
/*The packet handling functions for data requests.*/
113

  
114
void bom_handler(BomNode** head){
115
  Data* newData = malloc(sizeof(Data));
116
  newData->data = (*head);
117
  //newData->robot_id = ?????
118
  //newData->time = 
119
  queue_add(dataQueue,(void*)(newData));
120
}
121

  
122
void ir_handler(short** data){
123
  //etc.
124
}
125

  
126
void encoder_handler(unsigned char** data){
127

  
128
}

Also available in: Unified diff