1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
#include "frame.h"
#include "parameterset.h"
#include "utilimagergba.h"
#include "utiltimeprobe.h"
#include "vraibolabmodule.h"
// Register this command in the module factory, don't change this!
bool Frame::m_registered =3D =
VRAIBOLabModule::getFactory()->registerPrimaryCommand(&create);
// Constructor of this command.
// The first parameter is the used CommandDescriptor, which will =
identify this Command.
// The second parameter is the used CommandGUIDescriptor, which will =
specify the menue and the=20
// displayed text. (for more information see WISP-Docu: =
CommandDescriptor, CommandGUIDescriptor)
Frame::Frame():Command(new Main::CommandDescriptor("show the =
parcour-OpenGLscene","vrAiboFrame"),
new =
Main::CommandGUIDescriptor(Main::CommandGUIDescriptor::ON_MENU,"VRAIBO =
Frame", "Show Scene Parcour"))
{
// Illustrator is used to show the OPENGL scene
mp_Illustrator =3D NULL;
=09
// CloseObserver is used to shut down the Lab frame
mp_CloseObserver =3D NULL;
//UpdateObserver is used to observe the VRAIBO, to receive synchronized =
repaints
mp_UpdateObserver =3D NULL;
}
// Destructor of the class
Frame::~Frame()
{
}
// This method will be executed if the Command was called from the WISP =
console or WISP GUI.
void Frame::execute()
{
// if you want to use input parameters, you can do it like the =
following lines=20
// e.g to get the height and width for the used picture
// (for more information see WISP-Docu: Command, AbstractParameter)=20
/*Main::Parameter<int> input1;
Main::Parameter<int> input2;
if(!mp_Selected->getParameterList()->empty())
{
//solver solves casting problems
if(!m_Solver.solve(&input1,mp_Selected->getParameterList()->front()))
{
=
Main::Overseer::getInstance()->getOutputConsole()->appendText("Parameter =
failure");
return;
}
if(!m_Solver.solve(&input2,mp_Selected->getParameterList()->at(1)))
{
=
Main::Overseer::getInstance()->getOutputConsole()->appendText("Parameter =
failure");
return;
}
int height =3D *input1.getValue();
int width =3D *input2.getValue();
}*/
// The VRAibo class is the central interface to the virtual AIBO =
(neccessary to let the VRAIBO walk for example)
// (for more information see WISP-Docu: VRAibo)
VRAIBO::VRAibo* vraibo =3D VRAIBO::VRAibo::getInstance();
if(vraibo->isRunning())
{
// Example to use the console for outputs with a linebreak "\n".
// alternative, you can use =
Main::Overseer::getInstance()->getOutputConsole()->appendText("");
_Console()->appendText("already running \n");
return;
}
// Illustrator is used to show the OPENGL scene for example the =
Parcourillustrator or Parcelillustrator
//mp_Illustrator =3D new ParcelIllustrator();
mp_Illustrator =3D new ParcourIllustrator(); //->alternative =
illustrator
// activate the viewing of the opengl scenes ( four different camera =
positions )
// params are the used illustrator, height, width, eye distance to =
center of head
// (half distance between both eyes), start PositonX, startPositionY
// (for more information see WISP-Docu: VRAibo)
//vraibo->showViews(mp_Illustrator,256,256,0.5,-30,-55);
vraibo->showViews(mp_Illustrator,256,256,0.0,-30,-55);
mp_CloseObserver =3D new Frame::MyCloseObserver(this);
mp_UpdateObserver =3D new Frame::MyUpdateObserver(this,256,256);
//add observers to VRAIBO
vraibo->addCloseObserver(mp_CloseObserver);
vraibo->addUpdateObserver(mp_UpdateObserver);
_Console()->appendText("ready\n");
// Inform module about it's use (ensure correct unloading of the =
module) =20
VRAIBOLabModule::setUsed(true);
}
// Creation method for this Command
Main::Command* Frame::create()
{
return new Frame();
}
// Constructor of MyCloseObserver
Frame::MyCloseObserver::MyCloseObserver(Frame* scenes)
:mp_Frame(scenes)
{
}
// this method is used to shut down the Lab frame
void Frame::MyCloseObserver::update()
{
=09
=
VRAIBO::VRAibo::getInstance()->removeUpdateObserver(mp_Frame->mp_UpdateOb=
server);
VRAIBO::VRAibo::getInstance()->removeCloseObserver(this);
VRAIBOLabModule::setUsed(false);
if(VRAIBOLabModule::getFactory()->getModule() !=3DNULL )
{
delete mp_Frame->mp_Illustrator;
delete mp_Frame->mp_UpdateObserver;
}
delete this;
}
// Constructor of MyUpdateObserver
Frame::MyUpdateObserver::MyUpdateObserver(Frame* scenes,int =
imageWidth,int imageHeight)
:mp_Frame(scenes)
{
// Get a workspacewindow from the Overseer to put elements on it, like =
pictures, buttons, labels etc..
// (for more information see Ab-Docu: AbWindow, WISP-Docu: Overseer)
mp_LeftWindow =3D =
Main::Overseer::getInstance()->getWorkspaceWindow("left image");
// Create an imageComponent, which can show a picture
// (for more information see Ab-Docu: AbImageComponent)
mp_LeftImage =3D new AbImageComponent();
// Set the layout for the window (usefull to arrange components)
// (for more information see Ab-Docu: AbBorderLayout)
mp_LeftWindow->setLayoutManager(new AbBorderLayout());
// Add the imageComponent to the window
mp_LeftWindow->add(mp_LeftImage);
// Set the dimensio of the window
AbDimension dim(0,0,imageWidth,imageHeight);
mp_LeftWindow->setDimension(dim);
// disable resizing of the window
mp_LeftWindow->setResizeable(false);
// Show the window
mp_LeftWindow->show();
mp_RightWindow =3D =
Main::Overseer::getInstance()->getWorkspaceWindow("right image");
mp_RightImage =3D new AbImageComponent();
mp_RightWindow->setLayoutManager(new AbBorderLayout());
mp_RightWindow->add(mp_RightImage);
mp_RightWindow->setResizeable(false);
mp_RightWindow->setDimension(dim);
mp_RightWindow->show();
// The VRAibo class is the central interface to the virtual AIBO =
(neccessary to let the VRAIBO walk for example)
// (for more information see WISP-Docu: VRAibo)
mp_VRAibo =3D VRAIBO::VRAibo::getInstance();
}
// destructor of MyUpdateObserver
Frame::MyUpdateObserver::~MyUpdateObserver()
{
//close all own windows
AbMemoryManaged::destroy(mp_LeftWindow);
AbMemoryManaged::destroy(mp_RightWindow);
}
// This method will return true, if a point of interest has been found.
// image Left/Right is the picture of the actual position of VRAIBO. You =
can use this to analyse
// your situation with different image algorithms or something else.
// linePos is the Pixel, which will be used to calculate the next angle =
of rotation
// (e.g. the center of the line, which you want to follow).
bool Frame::MyUpdateObserver::evaluate(BV::ImageRGB& =
imageLeft,BV::ImageRGB& imageRight, double& linePos)
{=09
int x, start, end, h, w;
BV::RGBPixel red(198, 0, 0);
BV::RGBPixel test;
bool begin =3D true;
// double terror;
//heigt, the line is in the lower quarter of the left image
h =3D (int) (imageLeft.getHeight()*0.75);
//width
w =3D imageLeft.getWidth();
for(x =3D 0; x < w; x++)
{
//TB: only for debug issues, the function call could be direct in the =
if below
test =3D imageLeft.getPixel(x,h);
//terror =3D imageLeft.getPixel(x,h).getScalarValue();
//_Console()->appendText(AbString::format("DEBUG Scalar: %f\n", =
terror));
//_Console()->appendText(AbString::format("DEBUG RGB: %f %f %f \n", =
imageLeft.getPixel(x,h).getRed(), imageLeft.getPixel(x,h).getGreen(), =
imageLeft.getPixel(x,h).getBlue() ));
//TB: get the right side of the red line
if(test =3D=3D red && begin =3D=3D true)
{
start =3D x;
begin =3D false;
}
//TB: get the left side if the red line
else if(imageLeft.getPixel(x,h) !=3D red && begin =3D=3D false)
{
//TB: calc the middle of the red line and return this point
end =3D x-1;
linePos =3D (start + end)*0.5;
return true;
}
=09
}
return false;
=09
}
// This method will be invoked if the VRAIBO has synchronized all views =
again
void Frame::MyUpdateObserver::update()
{
// Get a rgb-images of VRAIBO's camera=20
unsigned char* tempLeft =3D mp_VRAibo->getLeftImage();
unsigned char* tempRight =3D mp_VRAibo->getRightImage();
=09
if(tempLeft =3D=3D NULL || tempRight =3D=3D NULL)
{
return;
}
// Set image for the imageComponents, which shows the Images
if(mp_LeftWindow !=3D NULL)
{
mp_LeftImage->setNewImage(tempLeft, mp_VRAibo->getPictureWidth(), =
mp_VRAibo->getPictureHeight(), Ab::RGB24);
}
if(mp_RightWindow !=3D NULL)
{
mp_RightImage->setNewImage(tempRight, mp_VRAibo->getPictureWidth(), =
mp_VRAibo->getPictureHeight(), Ab::RGB24);
}
=09
// Create a ImageRGBs for image processing and set buffer pointer for =
bvImages
BV::ImageRGB imageLeft;
=
imageLeft.setBufferPointer(mp_VRAibo->getPictureWidth(),mp_VRAibo->getPic=
tureHeight(),tempLeft);
=09
BV::ImageRGB imageRight;
=
imageRight.setBufferPointer(mp_VRAibo->getPictureWidth(),mp_VRAibo->getPi=
ctureHeight(),tempRight);
// Set the evaluation return value "linePos" to a default value
double linePos =3D 0;
// Set the angle of rotation for AIBO to a default value
double walkAngle =3D 0;
if (evaluate(imageLeft,imageRight,linePos))//pos found
{
// Point of interest has been found
// This is a example for a console output in which a variable
// and a string will be written to the console
// AbString::format() is used like printf()
// (for more information see Ab-Docu: AbString)
_Console()->appendText(AbString::format("aktuelle Linienposition: =
%f\n", linePos));
=09
//TB: calc the angle for the rotation of the robo (see worksheet)
walkAngle =3D =
(mp_VRAibo->getFovy()/mp_VRAibo->getPictureWidth())*-(linePos-imageLeft.g=
etWidth()*0.5);
=09
_Console()->appendText(AbString::format("aktueller Walkangle: %d\n", =
walkAngle));
//let the VRAIBO turn "walkAngle" degrees=20
mp_VRAibo->turn(walkAngle);
//let the VRAIBO walk 0.5=20
mp_VRAibo->walk(0.5);
=09
}
else
{
//TB: if no line was found walk forward...
mp_VRAibo->walk(0.5);
// Point of interest has not been found
// Search for point of interest
_Console()->appendText("No Lineposition found \n");
}
=09
}
|