Project

General

Profile

Statistics
| Revision:

root / branches / autonomous_recharging / code / projects / libwireless / lib / sensor_matrix.c @ 883

History | View | Annotate | Download (3.45 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.c
28
 * @brief Sensor Matrix implementation
29
 *
30
 * Implementation of a sensor matrix for storing localization implementation.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

    
35
#include <stdlib.h>
36
#include <stdio.h>
37
#include <wl_defs.h>
38

    
39
#include "sensor_matrix.h"
40

    
41
// the global sensor matrix
42
SensorMatrix m;
43

    
44
/**
45
 * Initializes the sensor matrix.
46
 *
47
 * @return the newly created sensor matrix
48
 **/
49
void sensor_matrix_create()
50
{
51
        int i, j;
52

    
53
        m.numJoined = 0;
54

    
55
        for (i = 0; i < MAXIMUM_XBEE_ID; i++)
56
        {
57
                m.joined[i] = 0;
58
        }
59
}
60

    
61
/**
62
 * Sets the sensor reading for robot robot to reading.
63
 *
64
 * @param observer the id of the robot who made the reading
65
 * @param robot the id of the robot who the reading is for
66
 * @param reading the BOM reading from observer to robot
67
 */
68
void sensor_matrix_set_reading(int observer, int robot, int reading)
69
{
70

    
71
}
72

    
73
/**
74
 * Gets the sensor reading for a robot to another robot.
75
 *
76
 * @param observer the robot whose reading we check
77
 * @param robot the robot who we are checking the reading to
78
 *
79
 * @return the observer's BOM reading for robot
80
 **/
81
int sensor_matrix_get_reading(int observer, int robot)
82
{
83
        return -1;
84
}
85

    
86
/**
87
 * Sets whether or not the given robot is part of the token ring.
88
 *
89
 * @param robot the robot to set as a member / nonmember of the token ring
90
 * @param in 1 if the robot is in the token ring, 0 otherwise
91
 **/
92
void sensor_matrix_set_in_ring(int robot, int in)
93
{
94
        if (robot >= MAXIMUM_XBEE_ID)
95
        {
96
                usb_puts("ID too large.\n\r");
97
                WL_DEBUG_PRINT("ID too large.");
98
                return;
99
        }
100

    
101
        if (in == 1 && m.joined[robot] == 0)
102
                m.numJoined++;
103

    
104
        if (in == 0 && m.joined[robot])
105
                m.numJoined--;
106
        m.joined[robot] = in;
107
}
108

    
109
/**
110
 * Checks if the given robot is in the token ring.
111
 *
112
 * @param robot the ID of the robot to check
113
 *
114
 * @return 1 if the robot is in the token ring, 0 otherwise
115
 **/
116
int sensor_matrix_get_in_ring(int robot)
117
{
118
        if (robot >= MAXIMUM_XBEE_ID)
119
                return -1;
120

    
121
        return m.joined[robot];
122
}
123

    
124
/**
125
 * Returns the number of robots which have joined the
126
 * token ring.
127
 *
128
 * @return the number of robots in the token ring
129
 **/
130
int sensor_matrix_get_joined(void)
131
{
132
        return m.numJoined;
133
}
134

    
135
/**
136
 * Returns the maximum XBee id of a robot which can be stored
137
 * in the sensor matrix.
138
 *
139
 * @return the maximum number of robots which can be stored
140
 **/
141
int sensor_matrix_get_size(void)
142
{
143
        return MAXIMUM_XBEE_ID;
144
}
145