Revision 508
position updating in separate thread. incomplete SIGINT handler
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 |
|
20 | 20 |
# |
21 | 21 |
# |
trunk/code/projects/colonet/robot/colonet_dragonfly/colonet_dragonfly.c | ||
---|---|---|
172 | 172 |
break; |
173 | 173 |
} |
174 | 174 |
} else if (type == COLONET_COMMAND) { |
175 |
usb_puts("type is colonet command...\n");
|
|
175 |
usb_puts("colonet command...\n"); |
|
176 | 176 |
|
177 | 177 |
/* TODO uncomment this stuff */ |
178 | 178 |
/* if (pkt.msg_code >= USER_DEFINED_MSG_ID_START && */ |
... | ... | |
193 | 193 |
case SERVER_REPORT_POSITION_TO_ROBOT: |
194 | 194 |
robot_x = int_args[0]; |
195 | 195 |
robot_y = int_args[1]; |
196 |
|
|
197 |
sprintf(buf, "my position is: %d %d\n", robot_x, robot_y); |
|
198 |
usb_puts(buf); |
|
196 | 199 |
break; |
197 | 200 |
|
198 | 201 |
case MOVE_TO_ABSOLUTE_POSITION: |
trunk/code/projects/colonet/server/Main.cpp | ||
---|---|---|
1 | 1 |
#include <stdio.h> |
2 |
#include <signal.h> |
|
2 | 3 |
#include <ColonetServer.h> |
3 | 4 |
|
4 | 5 |
ColonetServer colonet_server; |
5 | 6 |
|
7 |
void cleanup(int a) { |
|
8 |
printf("TODO deinit wireless here\n"); |
|
9 |
exit(0); |
|
10 |
} |
|
11 |
|
|
6 | 12 |
/** |
7 | 13 |
* @brief The main function of the server |
8 | 14 |
* |
... | ... | |
17 | 23 |
return -1; |
18 | 24 |
} |
19 | 25 |
|
26 |
signal(SIGINT, cleanup); |
|
27 |
|
|
20 | 28 |
if (colonet_server.start_listening() < 0) { |
21 | 29 |
fprintf(stderr, "ColonetServer.start_listening failed.\n"); |
22 | 30 |
return -1; |
23 | 31 |
} |
24 | 32 |
|
33 |
colonet_server.run_position_monitor(); |
|
34 |
|
|
25 | 35 |
colonet_server.run_server(); |
26 | 36 |
|
27 | 37 |
return 0; |
trunk/code/projects/colonet/server/includes/ColonetServer.h | ||
---|---|---|
22 | 22 |
int run_server(void); |
23 | 23 |
int process_received_wireless_message(int dest, char* data, int len); |
24 | 24 |
PositionMonitor* getPositionMonitor(void); |
25 |
int run_position_monitor(void); |
|
25 | 26 |
|
26 | 27 |
private: |
27 | 28 |
ConnectionPool* connection_pool; |
trunk/code/projects/colonet/server/includes/PositionMonitor.h | ||
---|---|---|
23 | 23 |
PositionMonitor(void); |
24 | 24 |
~PositionMonitor(void); |
25 | 25 |
|
26 |
int startMonitoring(void);
|
|
26 |
void run(void);
|
|
27 | 27 |
int stopMonitoring(void); |
28 | 28 |
int updatePositions(void); |
29 | 29 |
|
... | ... | |
35 | 35 |
map<int, VisionPosition> positionMap; |
36 | 36 |
bool isProbablySameRobot(VisionPosition p1, VisionPosition p2); |
37 | 37 |
int newIdToAssign; |
38 |
pthread_mutex_t position_map_lock; |
|
38 | 39 |
}; |
39 | 40 |
|
40 | 41 |
#endif |
trunk/code/projects/colonet/server/ColonetServer.cpp | ||
---|---|---|
91 | 91 |
return 0; |
92 | 92 |
} |
93 | 93 |
|
94 |
void* run_thread(void* arg) { |
|
95 |
PositionMonitor* p = (PositionMonitor*) arg; |
|
96 |
p->run(); |
|
97 |
return NULL; |
|
98 |
} |
|
99 |
|
|
100 |
int ColonetServer::run_position_monitor() { |
|
101 |
pthread_t posmon_thread; |
|
102 |
pthread_create(&posmon_thread, NULL, run_thread, &position_monitor); |
|
103 |
|
|
104 |
return 0; |
|
105 |
} |
|
106 |
|
|
94 | 107 |
/** |
95 | 108 |
* @brief Starts the server running (starts an infinite loop) |
96 | 109 |
*/ |
trunk/code/projects/colonet/server/PositionMonitor.cpp | ||
---|---|---|
22 | 22 |
//TODO: check for error returned from init |
23 | 23 |
vision_init("/var/www/colonet.jpg"); |
24 | 24 |
newIdToAssign = -1; |
25 |
|
|
26 |
pthread_mutex_init(&position_map_lock, NULL); |
|
25 | 27 |
} |
26 | 28 |
|
27 | 29 |
PositionMonitor::~PositionMonitor() { |
28 | 30 |
} |
29 | 31 |
|
30 |
int PositionMonitor::startMonitoring() { |
|
31 |
//TODO: fill this in when this becomes asynchronous |
|
32 |
return 0; |
|
32 |
void PositionMonitor::run() { |
|
33 |
while (1) { |
|
34 |
updatePositions(); |
|
35 |
usleep(500000); |
|
36 |
} |
|
33 | 37 |
} |
34 | 38 |
|
35 | 39 |
int PositionMonitor::stopMonitoring() { |
... | ... | |
107 | 111 |
} |
108 | 112 |
|
109 | 113 |
map<int, VisionPosition> PositionMonitor::getAllRobotPositions() { |
110 |
//TODO do this in another thread! |
|
111 |
updatePositions(); |
|
112 |
|
|
113 | 114 |
return positionMap; |
114 | 115 |
} |
115 | 116 |
|
Also available in: Unified diff