root / trunk / code / projects / colonet / ColonetServer / PositionMonitor.cpp @ 451
History | View | Annotate | Download (1.73 KB)
1 | 436 | jknichel | /**
|
---|---|---|---|
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 | 443 | emarinel | #include <PositionMonitor.h> |
12 | 436 | jknichel | #include <stdlib.h> |
13 | #include <vision.h> |
||
14 | |||
15 | 449 | jknichel | #include <stdio.h> |
16 | |||
17 | #include <map> |
||
18 | using namespace std; |
||
19 | |||
20 | |||
21 | |||
22 | 436 | jknichel | 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 | 449 | jknichel | //TODO: fill this in when this becomes asynchronous
|
33 | 436 | jknichel | return 0; |
34 | } |
||
35 | |||
36 | int PositionMonitor::stopMonitoring() {
|
||
37 | 449 | jknichel | //TODO: fill this in when this becomes asynchronous
|
38 | 436 | jknichel | return 0; |
39 | } |
||
40 | |||
41 | 447 | emarinel | int PositionMonitor::updatePositions() {
|
42 | 449 | jknichel | VisionPosition * positions = NULL;
|
43 | 436 | jknichel | |
44 | //TODO: check for error returned
|
||
45 | 449 | jknichel | int numPositions = vision_get_robot_positions(&positions);
|
46 | 436 | jknichel | |
47 | 449 | jknichel | //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 | 436 | jknichel | return 0; |
65 | } |
||
66 | 443 | emarinel | |
67 | 447 | emarinel | map<int, VisionPosition> PositionMonitor::getAllRobotPositions() {
|
68 | return positionMap;
|
||
69 | } |
||
70 | |||
71 | 443 | emarinel | int PositionMonitor::getRobotPosition(int robot_id, int* xbuf, int* ybuf) { |
72 | 449 | jknichel | //TODO: figure out what a map returns if the element doesn't exist
|
73 | 451 | jknichel | if (positionMap.find(robot_id) == positionMap.end()){
|
74 | 449 | jknichel | return -1; |
75 | } |
||
76 | |||
77 | VisionPosition pos = positionMap[robot_id]; |
||
78 | 443 | emarinel | |
79 | 449 | jknichel | *xbuf = pos.x; |
80 | *ybuf = pos.y; |
||
81 | 443 | emarinel | |
82 | return 0; |
||
83 | } |