Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / libwireless / lib / sensor_matrix.h @ 717

History | View | Annotate | Download (3.86 KB)

1
/**
2
 * Copyright (c) 2007 Colony Project
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

    
26
/**
27
 * @file sensor_matrix.h
28
 * @brief Definitions for sensor matrices
29
 *
30
 * Contains functions and declarations for using sensor matrices.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

    
35
#ifndef SENSOR_MATRIX_H
36
#define SENSOR_MATRIX_H
37

    
38

    
39
/**
40
 * @defgroup sensormatrix Sensor Matrix
41
 * @brief the robot sensor matrix
42
 *
43
 * These functions and structures are used for localization
44
 * to determine the relative directions of robots.
45
 *
46
 * @{
47
 **/
48

    
49
/**
50
 * @struct SensorMatrix
51
 *
52
 * A sensor matrix.
53
 **/
54
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
55
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
56
// Thus, pointers should be first, followed by int, followed by char.
57
typedef struct
58
{
59
        /**
60
         * The size of the sensor matrix.
61
        **/
62
        int size;
63
        /**
64
         * The matrix. Each row represents the readings of one
65
         * robot.
66
         **/
67
        int** matrix;
68
        /**
69
         * The element representing a robot is true if that robot
70
         * is in the token ring and false otherwise.
71
         **/
72
  //TODO: if these values are just to be used to represent boolean values, why are they int?
73
  // They could be made char and the code should still be fine, and if you want to save more
74
  // memory, they could be made into bit vectors but that would increase the complexity of
75
  // the code to set and read from them.
76
        int* joined;
77
        /**
78
         * The number of robots in the token ring.
79
         **/
80
  //TODO: int is probably > 2 bytes.  Unless we are going to have more than 255 robots,
81
  // this could be made a char.  It would only save 1 byte, but on embedded systems, every
82
  // byte counts
83
        int numJoined;
84
} SensorMatrix;
85

    
86
/**@brief Create a sensor matrix **/
87
SensorMatrix* sensor_matrix_create(void);
88
/**@brief Destroy a sensor matrix **/
89
void sensor_matrix_destroy(SensorMatrix* m);
90
/**@brief Add a robot to a sensor matrix **/
91
void sensor_matrix_add_robot(SensorMatrix* m, int id);
92
/**@brief Remove a robot from a sensor matrix **/
93
void sensor_matrix_remove_robot(SensorMatrix* m, int id);
94
/**@brief Set a reading in a sensor matrix **/
95
void sensor_matrix_set_reading(SensorMatrix* m, int observer, int robot, int reading);
96
/**@brief Get a reading in a sensor matrix **/
97
int sensor_matrix_get_reading(SensorMatrix* m, int observer, int robot);
98
/**@brief Set whether the robot is in the token ring **/
99
void sensor_matrix_set_in_ring(SensorMatrix* m, int robot, int in);
100
/**@brief Get whether the robot is in the sensor ring **/
101
int sensor_matrix_get_in_ring(SensorMatrix* m, int robot);
102
/**@brief Get the size of the sensor matrix **/
103
int sensor_matrix_get_size(SensorMatrix* m);
104
/**@brief Get the number of robots which have joined the token ring **/
105
int sensor_matrix_get_joined(SensorMatrix* m);
106

    
107
/** @} **/ //end defgroup
108

    
109

    
110
#endif