Revision 655
added some more documentation
trunk/code/projects/colonet/server/Main.cpp | ||
---|---|---|
1 |
/** |
|
2 |
* @file Main.cpp |
|
3 |
* |
|
4 |
* @author Jason Knichel |
|
5 |
* |
|
6 |
*/ |
|
1 | 7 |
#include <stdio.h> |
2 | 8 |
#include <signal.h> |
3 | 9 |
#include <ColonetServer.h> |
... | ... | |
5 | 11 |
|
6 | 12 |
ColonetServer colonet_server; |
7 | 13 |
|
14 |
//TODO: what does the parameter a do? |
|
15 |
/** |
|
16 |
* @brief This function performs any cleanup needed to be done when the program dies. |
|
17 |
* |
|
18 |
* @return Void |
|
19 |
*/ |
|
8 | 20 |
void cleanup(int a) { |
9 | 21 |
a = a; |
10 | 22 |
|
... | ... | |
28 | 40 |
return -1; |
29 | 41 |
} |
30 | 42 |
|
43 |
//register a signal handler to be called when we get a SIGINT signal (killing the server by cntrl+c would generate this) |
|
31 | 44 |
signal(SIGINT, cleanup); |
32 | 45 |
|
33 | 46 |
if (colonet_server.start_listening() < 0) { |
trunk/code/projects/colonet/server/Makefile | ||
---|---|---|
35 | 35 |
make; ./ColonetServer |
36 | 36 |
|
37 | 37 |
vision/vision.o: vision/vision.c vision/vision.h |
38 |
cd vision |
|
39 |
make |
|
38 |
@echo "---------------------------" |
|
39 |
@echo "---compiling vision code---" |
|
40 |
cd vision; make |
|
41 |
@echo "---finish compiling vision code---" |
|
42 |
@echo "----------------------------------" |
|
40 | 43 |
|
41 | 44 |
$(COLONYROOT)/code/projects/libwireless/lib/libwireless_colonet.a: $(COLONYROOT)/code/projects/libwireless/lib/*.c $(COLONYROOT)/code/projects/libwireless/lib/*.h |
45 |
@echo "---------------------------" |
|
46 |
@echo "---compiling wireless library code---" |
|
42 | 47 |
cd $(COLONYROOT)/code/projects/libwireless/lib; make colonet |
48 |
@echo "---finish compiling wireless library code---" |
|
49 |
@echo "----------------------------------" |
|
43 | 50 |
|
44 | 51 |
ColonetServer: $(COLONYROOT)/code/projects/libwireless/lib/libwireless_colonet.a $(COLONETCPPFILES) $(COLONETFILES) $(LOGGINGFILES) $(COLONETHEADERFILES) |
45 | 52 |
@echo "-----------------------" |
46 |
@echo "---begin compilation---"
|
|
53 |
@echo "---begin compiling server---"
|
|
47 | 54 |
@echo "" |
48 |
@echo "---create object files---"
|
|
55 |
@echo "-----creating object files-----"
|
|
49 | 56 |
$(CC) $(CFLAGS) -c $(COLONETFILES) $(INCLUDE_DIRS_FOR_GCC) |
50 | 57 |
$(CC) $(CFLAGS) -c $(COLONETCPPFILES) $(INCLUDE_DIRS_FOR_GCC) |
51 | 58 |
$(CC) $(CFLAGS) -c $(LOGGINGFILES) $(INCLUDE_DIRS_FOR_GCC) |
52 |
@echo "---finish creating object files---"
|
|
59 |
@echo "-----finish creating object files-----"
|
|
53 | 60 |
@echo "" |
54 |
@echo "---link files---"
|
|
61 |
@echo "-----linking files-----"
|
|
55 | 62 |
$(CC) $(CFLAGS) $(VISIONFLAGS) $(COLONETOBJECTS) $(COLONETCPPOBJECTS) $(LOGGINGOBJECTS) $(VISIONOBJECTS) $(LIBRARY_DIRS_FOR_GCC) -lpthread -lwireless_colonet $(INCLUDE_DIRS_FOR_GCC) -o $@ |
56 |
@echo "---finish linking files---"
|
|
63 |
@echo "-----finish linking files-----"
|
|
57 | 64 |
@echo "" |
58 | 65 |
@echo "---finish compilation---" |
59 | 66 |
@echo "-----------------------" |
trunk/code/projects/colonet/server/PositionMonitor.cpp | ||
---|---|---|
20 | 20 |
#define ROBOT_DELETE_BUFFER 10 |
21 | 21 |
#define CAM_UPDATE_PERIOD 100000 |
22 | 22 |
|
23 |
/** |
|
24 |
* @brief Constructor for the PositionMonitor class |
|
25 |
*/ |
|
23 | 26 |
PositionMonitor::PositionMonitor() { |
24 | 27 |
//TODO: don't hardcode this file name |
25 | 28 |
//TODO: check for error returned from init |
... | ... | |
29 | 32 |
pthread_mutex_init(&position_map_lock, NULL); |
30 | 33 |
} |
31 | 34 |
|
35 |
/** |
|
36 |
* @brief Destructor for the PositionMonitor class |
|
37 |
*/ |
|
32 | 38 |
PositionMonitor::~PositionMonitor() { |
33 | 39 |
} |
34 | 40 |
|
41 |
/** |
|
42 |
* @brief This function updates the positions of things in the image |
|
43 |
* |
|
44 |
* @return Void |
|
45 |
*/ |
|
35 | 46 |
void PositionMonitor::run() { |
36 | 47 |
while (1) { |
37 | 48 |
if (updatePositions() == -1) { |
... | ... | |
42 | 53 |
} |
43 | 54 |
} |
44 | 55 |
|
56 |
/** |
|
57 |
* @brief This function asks the vision code for the position of things it identifies |
|
58 |
*/ |
|
45 | 59 |
int PositionMonitor::updatePositions() { |
46 | 60 |
VisionPosition* positions = NULL; |
47 | 61 |
int numPositions = vision_get_robot_positions(&positions); |
48 | 62 |
|
63 |
//debug output code |
|
49 | 64 |
/* |
50 | 65 |
printf("numPositions is %d\n", numPositions); |
51 | 66 |
for (int i = 0; i < numPositions; i++) { |
... | ... | |
62 | 77 |
|
63 | 78 |
pthread_mutex_lock(&position_map_lock); |
64 | 79 |
|
65 |
//TODO: also remove robots that might have disappeared
|
|
80 |
//go through each of the positions the vision system identified
|
|
66 | 81 |
for (int i = 0; i < numPositions; i++) { |
67 | 82 |
VisionPosition newPos = positions[i]; |
68 | 83 |
map<int, VisionPosition>::iterator iter; |
84 |
//go through all the positions we currently have in the position map |
|
69 | 85 |
for (iter = positionMap.begin(); iter != positionMap.end(); iter++) { |
70 | 86 |
VisionPosition oldPos = iter->second; |
71 | 87 |
|
88 |
//figure out if the new point is probably the same robot as one of the old positions |
|
72 | 89 |
if (isProbablySameRobot(newPos, oldPos)) { |
73 |
//TODO: is this the right use of an iterator?
|
|
90 |
//if the new positions is the same robot as an old one, insert this new position into the new map
|
|
74 | 91 |
newPositionMap.insert(make_pair(iter->first, newPos)); |
92 |
|
|
93 |
//erase this robot from the map that is used to smooth over several frames in case of problems identifying robots |
|
75 | 94 |
deleteBufferMap.erase(iter->first); |
95 |
//insert this robot back into the map in order to refresh its delete buffer |
|
76 | 96 |
deleteBufferMap.insert(make_pair(iter->first, ROBOT_DELETE_BUFFER)); |
77 | 97 |
break; |
78 | 98 |
} |
... | ... | |
90 | 110 |
} |
91 | 111 |
} |
92 | 112 |
|
113 |
|
|
93 | 114 |
map<int, VisionPosition>::iterator iter2; |
94 | 115 |
for (iter2 = positionMap.begin(); iter2 != positionMap.end(); iter2++) { |
95 | 116 |
int currId = iter2->first; |
Also available in: Unified diff