Revision 710
Tweaked vision and various colonet fixes
trunk/code/projects/colonet/robot/robot_slave/Makefile | ||
---|---|---|
14 | 14 |
USE_WIRELESS = 1 |
15 | 15 |
|
16 | 16 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
17 |
#AVRDUDE_PORT = /dev/ttyUSB1
|
|
18 |
AVRDUDE_PORT = /dev/ttyUSB0 |
|
17 |
AVRDUDE_PORT = /dev/ttyUSB1 |
|
18 |
#AVRDUDE_PORT = /dev/ttyUSB0
|
|
19 | 19 |
#AVRDUDE_PORT = /dev/ttyUSB2 |
20 | 20 |
|
21 | 21 |
# |
trunk/code/projects/colonet/server/colonet_wireless.cpp | ||
---|---|---|
226 | 226 |
|
227 | 227 |
//TODO: fill in the doxygen comments |
228 | 228 |
/** |
229 |
* @brief
|
|
229 |
* @brief |
|
230 | 230 |
* |
231 | 231 |
* @return Void |
232 | 232 |
*/ |
... | ... | |
236 | 236 |
|
237 | 237 |
//TODO: fill in the doxygen comments |
238 | 238 |
/** |
239 |
* @brief
|
|
239 |
* @brief |
|
240 | 240 |
* |
241 | 241 |
* @param frame |
242 | 242 |
* @param received |
... | ... | |
252 | 252 |
/** |
253 | 253 |
* @brief When a packet is received via wireless, the data is passed to this function |
254 | 254 |
* |
255 |
* @param type
|
|
255 |
* @param type |
|
256 | 256 |
* @param source The robot the packet came from |
257 | 257 |
* @param data The data the robot sent |
258 | 258 |
* @param len The length of the data |
... | ... | |
280 | 280 |
//ask the position monitor for where that robot is. |
281 | 281 |
int ret = pm->getRobotPosition(source_robot, &robot_x, &robot_y); |
282 | 282 |
if (ret != 0 && num_robots != 1) { |
283 |
fprintf(stderr, "Robot %d requested position, but its position is not known.\n", source_robot); |
|
283 |
//DEBUG |
|
284 |
//fprintf(stderr, "Robot %d requested position, but its position is not known.\n", source_robot); |
|
284 | 285 |
|
285 | 286 |
if (colonet_wl_send(-1, source_robot, COLONET_COMMAND, SERVER_REPORT_ROBOT_LOST, NULL) != 0) { |
286 | 287 |
fprintf(stderr, "colonet_wl_send failed!\n"); |
... | ... | |
319 | 320 |
|
320 | 321 |
//TODO: fill in the doxygen comments |
321 | 322 |
/** |
322 |
* @brief
|
|
323 |
* @brief |
|
323 | 324 |
* |
324 | 325 |
* @return Void |
325 | 326 |
*/ |
... | ... | |
357 | 358 |
return NULL; |
358 | 359 |
} |
359 | 360 |
|
360 |
/**
|
|
361 |
/** |
|
361 | 362 |
* @brief |
362 | 363 |
* |
363 | 364 |
* @param pkt Packet to be logged |
trunk/code/projects/colonet/server/vision/vision.c | ||
---|---|---|
14 | 14 |
#include <stdio.h> |
15 | 15 |
#include <stdlib.h> |
16 | 16 |
|
17 |
#define MINH 100 //min threshold level
|
|
18 |
#define MAXH 150 //max threshold level
|
|
17 |
#define MINH 50 //min threshold level
|
|
18 |
#define MAXH 75 //max threshold level
|
|
19 | 19 |
|
20 |
#define MIN_BOX_WIDTH 10 |
|
21 |
#define MAX_BOX_WIDTH 20 |
|
22 |
#define MIN_BOX_HEIGHT 10 |
|
23 |
#define MAX_BOX_HEIGHT 20 |
|
24 |
|
|
25 |
#define BEST_CENTER_PADDING_X 9 |
|
26 |
#define BEST_CENTER_PADDING_Y 9 |
|
27 |
|
|
28 |
#define ELLIPSE_COUNT_TO_BE_OBJECT 7 |
|
29 |
|
|
20 | 30 |
#define DEBUG 0 //Debug to find threshold level |
21 | 31 |
|
22 | 32 |
struct CenterP { |
... | ... | |
100 | 110 |
size.height = cvRound(box->size.height*0.5); |
101 | 111 |
box->angle = -box->angle; |
102 | 112 |
|
103 |
if (size.width>10&&size.height>10&&size.width<20&&size.height<20){ |
|
113 |
if (size.width > MIN_BOX_WIDTH && size.height > MIN_BOX_HEIGHT |
|
114 |
&& size.width < MAX_BOX_WIDTH && size.height < MAX_BOX_HEIGHT){ |
|
104 | 115 |
//printf("%d %d %d %d\n",center.x,center.y,size.width,size.height); |
105 | 116 |
|
106 | 117 |
int found=0, j; |
107 | 118 |
for (j = 0; j < index; j++) { |
108 |
if (abs(bestc[j].center.x-center.x)<9&&abs(bestc[j].center.y-center.y)<9) { |
|
119 |
if (abs(bestc[j].center.x-center.x) < BEST_CENTER_PADDING_X |
|
120 |
&& abs(bestc[j].center.y-center.y) < BEST_CENTER_PADDING_Y) { |
|
109 | 121 |
bestc[j].count++; |
110 | 122 |
found=1; |
111 | 123 |
break; |
... | ... | |
133 | 145 |
int count = 0; |
134 | 146 |
int i; |
135 | 147 |
for (i = 0; i < index; i++) { |
136 |
if (bestc[i].count > 7){
|
|
148 |
if (bestc[i].count > ELLIPSE_COUNT_TO_BE_OBJECT){
|
|
137 | 149 |
count++; |
138 | 150 |
} |
139 | 151 |
} |
... | ... | |
146 | 158 |
|
147 | 159 |
int c = 0; |
148 | 160 |
for (i = 0; i < index; i++) { |
149 |
if (bestc[i].count > 7){
|
|
161 |
if (bestc[i].count > ELLIPSE_COUNT_TO_BE_OBJECT){
|
|
150 | 162 |
pos_array[c].x = bestc[i].center.x; |
151 | 163 |
pos_array[c].y = bestc[i].center.y; |
152 | 164 |
c++; |
trunk/code/projects/colonet/server/Makefile | ||
---|---|---|
3 | 3 |
COLONYROOT = ../../../.. |
4 | 4 |
|
5 | 5 |
CC = g++ |
6 |
CFLAGS = -Wall -Wshadow -Wextra -g |
|
6 |
CFLAGS = -Wall -Wshadow -Wextra -g
|
|
7 | 7 |
VISIONFLAGS = -ggdb `pkg-config opencv --cflags --libs` |
8 | 8 |
|
9 | 9 |
COLONETCPPFILES = Main.cpp ColonetServer.cpp ConnectionPool.cpp Command.cpp colonet_wireless.cpp PositionMonitor.cpp VirtualWall.cpp |
trunk/code/projects/colonet/server/PositionMonitor.cpp | ||
---|---|---|
16 | 16 |
using namespace std; |
17 | 17 |
|
18 | 18 |
#define MAX_POSITIONS 20 |
19 |
#define SAME_ROBOT_DISTANCE_THRESHOLD 150
|
|
19 |
#define SAME_ROBOT_DISTANCE_THRESHOLD 15 |
|
20 | 20 |
#define ROBOT_DELETE_BUFFER 10 |
21 | 21 |
#define CAM_UPDATE_PERIOD 100000 |
22 | 22 |
|
... | ... | |
28 | 28 |
//TODO: check for error returned from init |
29 | 29 |
vision_init("/var/www/colonet.jpg"); |
30 | 30 |
newIdToAssign = -1; |
31 |
|
|
31 |
|
|
32 | 32 |
pthread_mutex_init(&position_map_lock, NULL); |
33 | 33 |
} |
34 | 34 |
|
... | ... | |
61 | 61 |
int numPositions = vision_get_robot_positions(&positions); |
62 | 62 |
|
63 | 63 |
//debug output code |
64 |
/*
|
|
65 |
printf("numPositions is %d\n", numPositions); |
|
64 |
/* |
|
65 |
printf("\nnumPositions is %d\n", numPositions);
|
|
66 | 66 |
for (int i = 0; i < numPositions; i++) { |
67 | 67 |
printf("{%d,%d} ", positions[i].x, positions[i].y); |
68 | 68 |
} |
... | ... | |
81 | 81 |
for (int i = 0; i < numPositions; i++) { |
82 | 82 |
VisionPosition newPos = positions[i]; |
83 | 83 |
map<int, VisionPosition>::iterator iter; |
84 |
|
|
84 | 85 |
//go through all the positions we currently have in the position map |
85 | 86 |
for (iter = positionMap.begin(); iter != positionMap.end(); iter++) { |
86 | 87 |
VisionPosition oldPos = iter->second; |
87 | 88 |
|
88 | 89 |
//figure out if the new point is probably the same robot as one of the old positions |
89 | 90 |
if (isProbablySameRobot(newPos, oldPos)) { |
91 |
//DEBUG |
|
92 |
//printf("probably same robot: new = (%d, %d), old = (%d, %d)\n", newPos.x, newPos.y, oldPos.x, oldPos.y); |
|
93 |
|
|
90 | 94 |
//if the new positions is the same robot as an old one, insert this new position into the new map |
91 | 95 |
newPositionMap.insert(make_pair(iter->first, newPos)); |
92 | 96 |
|
... | ... | |
99 | 103 |
} |
100 | 104 |
|
101 | 105 |
if (iter == positionMap.end()) { |
102 |
//a position was found that probably isn't a known
|
|
106 |
//a position was found that probably isn't a known |
|
103 | 107 |
// robot so add it in case a new robot entered the field |
104 | 108 |
printf("Inserting new robot: %d (%d,%d)\n", newIdToAssign, newPos.x, newPos.y); |
105 |
|
|
109 |
|
|
106 | 110 |
//a position was found that probably isn't a known robot so add it in case a new robot entered the field |
107 | 111 |
newPositionMap.insert(make_pair(newIdToAssign, newPos)); |
108 | 112 |
deleteBufferMap.insert(make_pair(newIdToAssign, ROBOT_DELETE_BUFFER)); |
... | ... | |
110 | 114 |
} |
111 | 115 |
} |
112 | 116 |
|
113 |
|
|
117 |
|
|
114 | 118 |
map<int, VisionPosition>::iterator iter2; |
115 | 119 |
for (iter2 = positionMap.begin(); iter2 != positionMap.end(); iter2++) { |
116 | 120 |
int currId = iter2->first; |
... | ... | |
130 | 134 |
|
131 | 135 |
positionMap = newPositionMap; |
132 | 136 |
|
133 |
// printf("\npositionMap size is %d and deleteBufferMap size is %d\n", positionMap.size(), deleteBufferMap.size()); |
|
134 |
|
|
135 | 137 |
/* |
136 |
//TODO: remove this debug information |
|
138 |
//DEBUG PRINT STATEMENTS |
|
139 |
printf("positionMap size is %d and deleteBufferMap size is %d\n", positionMap.size(), deleteBufferMap.size()); |
|
137 | 140 |
map<int, VisionPosition>::iterator iter; |
138 | 141 |
for (iter = positionMap.begin(); iter != positionMap.end(); iter++) { |
139 |
printf("%d has position (%d, %d) with delete buffer %d\n", iter->first, iter->second.x, iter->second.y, deleteBufferMap[iter->first]); |
|
142 |
printf("%d has position (%d, %d) with delete buffer %d\n", iter->first, iter->second.x, iter->second.y, deleteBufferMap[iter->first]);
|
|
140 | 143 |
} |
141 | 144 |
*/ |
142 | 145 |
|
... | ... | |
193 | 196 |
pthread_mutex_lock(&position_map_lock); |
194 | 197 |
|
195 | 198 |
if (positionMap.find(robot_id) == positionMap.end()){ |
196 |
pthread_mutex_unlock(&position_map_lock);
|
|
199 |
pthread_mutex_unlock(&position_map_lock); |
|
197 | 200 |
return -1; |
198 | 201 |
} else { |
199 | 202 |
VisionPosition pos = positionMap[robot_id]; |
trunk/code/projects/colonet/client/Colonet.java | ||
---|---|---|
170 | 170 |
btnR = new JButton("\u2192"); |
171 | 171 |
btnR.setFont(f); |
172 | 172 |
btnActivate = new JButton("\u25A0"); |
173 |
btnActivate.setFont(new Font(null, Font.BOLD, 36));
|
|
173 |
btnActivate.setFont(new Font(null, Font.BOLD, 24));
|
|
174 | 174 |
|
175 | 175 |
panelRobotDirectionButtons.setLayout(new GridLayout(1,5)); |
176 | 176 |
panelRobotDirectionButtons.add(btnActivate); |
Also available in: Unified diff