gusimplewhiteboard
VisionRobots.hpp
Go to the documentation of this file.
1/*
2 * File: VisionRobots.h
3 * Author: eugene
4 *
5 * Created on 1 December 2013, 8:02 PM
6 */
7
8#ifndef VisionRobots_DEFINED
9#define VisionRobots_DEFINED
10
11#include <SimpleShapes.h>
12#include <string>
13#include <iostream>
14#include <algorithm>
15#include <gu_util.h>
16#include "wb_robot.h"
17
18#define TOPLIMIT 5
19#define BOTTOMLIMIT 5
20
21namespace guWhiteboard {
40private:
41 wb_robot topRobots[TOPLIMIT];
42 wb_robot bottomRobots[BOTTOMLIMIT];
43 size_t _frameNumber;
44 uint32_t topCntr;
45 uint32_t bottomCntr;
46public:
48 VisionRobots() : _frameNumber(0), topCntr(0), bottomCntr(0) {
49 }
50
56 VisionRobots(std::string s) {
57 from_string(s);
58 }
59
60 void from_string(std::string &s) {
61 _frameNumber = 0;
62 size_t n = static_cast<size_t>(-5);
63 std::string command = "ROBOT";
64 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
65 while(n!=std::string::npos) {
66 n = s.find(command, n+5);
67 if (n!=std::string::npos) {
68 std::string t = s.substr(n+command.length()+1);
69 wb_robot robotInfo;
70 VisionCamera cam;
71 if(s.substr(n-3, 3).find("TOP") != std::string::npos)
72 cam = Top;
73 else
74 cam = Bottom;
75
76 std::vector<std::string> com = components_of_string_separated(t, '(');
77 GUPoint<int16_t> _topLeft(com.at(2).c_str());
78 GUPoint<int16_t> _bottomRight(com.at(3).c_str());
79
80 robotInfo.set_topLeft_X(_topLeft.x);
81 robotInfo.set_topLeft_Y(_topLeft.y);
82
83 robotInfo.set_bottomRight_X(_bottomRight.x);
84 robotInfo.set_bottomRight_Y(_bottomRight.y);
85
86 setRobot(robotInfo, cam);
87 }
88 }
89 }
95 void setRobot(wb_robot robotInfo, VisionCamera camera) {
96 if(camera == Top && topCntr < TOPLIMIT) {
97 topRobots[topCntr] = robotInfo;
98 topRobots[topCntr++].set_visible(true);
99 }
100 else if( bottomCntr < BOTTOMLIMIT ) {
101 bottomRobots[bottomCntr] = robotInfo;
102 bottomRobots[bottomCntr++].set_visible(true);
103 }
104 }
105
112 const wb_robot &robots(VisionCamera camera, int idx) const
113 {
114 if(camera == Top)
115 {
116 idx = idx >= TOPLIMIT ? TOPLIMIT-1 : idx;
117 return topRobots[idx];
118 }
119 else
120 {
121 idx = idx >= BOTTOMLIMIT ? BOTTOMLIMIT-1 : idx;
122 return bottomRobots[idx];
123 }
124 }
125
132 wb_robot &robots(VisionCamera camera, int idx)
133 {
134 if(camera == Top)
135 {
136 idx = idx >= TOPLIMIT ? TOPLIMIT-1 : idx;
137 return topRobots[idx];
138 }
139 else
140 {
141 idx = idx >= BOTTOMLIMIT ? BOTTOMLIMIT-1 : idx;
142 return bottomRobots[idx];
143 }
144 }
145
149 void Reset() {
150 topCntr = bottomCntr = 0;
151 for( int i = 0; i < TOPLIMIT; i++ )
152 {
153 topRobots[i].set_visible(false);
154 }
155 for( int i = 0; i < BOTTOMLIMIT; i++ )
156 {
157 bottomRobots[i].set_visible(false);
158 }
159 }
160
165 void setFrameNumber(size_t fn) {
166 _frameNumber = fn;
167 }
168
173 size_t frameNumber() const {
174 return _frameNumber;
175 }
176
181 std::string description() {
182 std::stringstream result;
183
184 for (uint32_t i = 0; i < topCntr; i++) {
185 result << "TopRobot:("
186 << topRobots[i].topLeft_X() << "," << topRobots[i].topLeft_Y() << ")("
187 << topRobots[i].bottomRight_X() << "," << topRobots[i].bottomRight_Y() << ") ";
188 }
189 for (uint32_t i = 0; i < bottomCntr; i++) {
190 result << "BottomRobot:("
191 << bottomRobots[i].topLeft_X() << "," << bottomRobots[i].topLeft_Y() << ")("
192 << bottomRobots[i].bottomRight_X() << "," << bottomRobots[i].bottomRight_Y() << ") ";
193 }
194 return result.str();
195 }
196};
197}
198
199#endif /* VisionRobots_DEFINED */
200
#define TOPLIMIT
#define BOTTOMLIMIT
Class to post information about Robot posts detected from vision This class contains information the ...
VisionRobots()
Default Constructor.
void setRobot(wb_robot robotInfo, VisionCamera camera)
Add a the Robot to this VisionRobot message.
VisionRobots(std::string s)
String Constructor Converts a serialized string to a VisionRobot object.
void setFrameNumber(size_t fn)
Sets the frame number this information in this message was observed.
void Reset()
Reset the visible flag for all four different posts to false.
void from_string(std::string &s)
wb_robot & robots(VisionCamera camera, int idx)
Get the current Robots for this message.
std::string description()
Converts this message into a serialized string.
const wb_robot & robots(VisionCamera camera, int idx) const
Get the current Robots for this message.
size_t frameNumber() const
Get the frame number the information in this message was observed.
/file APM_Interface.h
Whiteboard structure for robot coordinates X and Y coordinates are posted as seen in the image X rang...
Definition: wb_robot.h:14
VisionCamera
Enum of available camera's that can be used by vision.
@ Bottom
Bottom Camera on the nao.
@ Top
Top Camera on the nao.