root / trunk / code / projects / colonet / ColonetServer / PositionMonitor.cpp @ 451
History | View | Annotate | Download (1.73 KB)
1 |
/**
|
---|---|
2 |
* @file PositionMonitor.cpp
|
3 |
*
|
4 |
* @author Jason Knichel
|
5 |
*
|
6 |
* @date 2/4/08
|
7 |
*/
|
8 |
|
9 |
//TODO: make this file asynchronous
|
10 |
|
11 |
#include <PositionMonitor.h> |
12 |
#include <stdlib.h> |
13 |
#include <vision.h> |
14 |
|
15 |
#include <stdio.h> |
16 |
|
17 |
#include <map> |
18 |
using namespace std; |
19 |
|
20 |
|
21 |
|
22 |
PositionMonitor::PositionMonitor() { |
23 |
//TODO: don't hardcode this file name
|
24 |
//TODO: check for error returned from init
|
25 |
vision_init("/var/www/colonet.jpg");
|
26 |
} |
27 |
|
28 |
PositionMonitor::~PositionMonitor() { |
29 |
} |
30 |
|
31 |
int PositionMonitor::startMonitoring() {
|
32 |
//TODO: fill this in when this becomes asynchronous
|
33 |
return 0; |
34 |
} |
35 |
|
36 |
int PositionMonitor::stopMonitoring() {
|
37 |
//TODO: fill this in when this becomes asynchronous
|
38 |
return 0; |
39 |
} |
40 |
|
41 |
int PositionMonitor::updatePositions() {
|
42 |
VisionPosition * positions = NULL;
|
43 |
|
44 |
//TODO: check for error returned
|
45 |
int numPositions = vision_get_robot_positions(&positions);
|
46 |
|
47 |
//TODO: compare current set of positions to previous set of
|
48 |
// positions to match up who is who
|
49 |
positionMap.clear(); |
50 |
|
51 |
int i;
|
52 |
for (i = 0; i < numPositions; i++) { |
53 |
positionMap[i] = positions[i]; |
54 |
} |
55 |
|
56 |
//TODO: remove this debug information
|
57 |
map<int, VisionPosition>::iterator iter;
|
58 |
for (iter = positionMap.begin(); iter != positionMap.end(); iter++) {
|
59 |
printf("%d has position (%d, %d)\n", iter->first, iter->second.x, iter->second.y);
|
60 |
} |
61 |
|
62 |
if (positions)
|
63 |
free(positions); |
64 |
return 0; |
65 |
} |
66 |
|
67 |
map<int, VisionPosition> PositionMonitor::getAllRobotPositions() {
|
68 |
return positionMap;
|
69 |
} |
70 |
|
71 |
int PositionMonitor::getRobotPosition(int robot_id, int* xbuf, int* ybuf) { |
72 |
//TODO: figure out what a map returns if the element doesn't exist
|
73 |
if (positionMap.find(robot_id) == positionMap.end()){
|
74 |
return -1; |
75 |
} |
76 |
|
77 |
VisionPosition pos = positionMap[robot_id]; |
78 |
|
79 |
*xbuf = pos.x; |
80 |
*ybuf = pos.y; |
81 |
|
82 |
return 0; |
83 |
} |