direcs
2012-09-30
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
head.cpp
Go to the documentation of this file.
1
/*************************************************************************
2
* Copyright (C) Markus Knapp *
3
* www.direcs.de *
4
* *
5
* This file is part of direcs. *
6
* *
7
* direcs is free software: you can redistribute it and/or modify it *
8
* under the terms of the GNU General Public License as published *
9
* by the Free Software Foundation, version 3 of the License. *
10
* *
11
* direcs is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
15
* *
16
* You should have received a copy of the GNU General Public License *
17
* along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18
* *
19
*************************************************************************/
20
21
#include "
head.h
"
22
23
Head::Head
(
Servo
*s)
24
{
25
//------------------------------------------------------------------
26
// copy the pointer from the original usb object
27
//------------------------------------------------------------------
28
servos
= s;
29
30
// Initialize something
31
}
32
33
34
Head::~Head
()
35
{
36
/*
37
park();
38
*/
39
}
40
41
42
void
Head::look
(QString direction)
43
{
44
if
(direction ==
"UP"
)
45
{
46
47
eye
(
LEFTEYE
, direction);
48
eye
(
RIGHTEYE
, direction);
49
return
;
50
}
51
52
if
(direction ==
"UPLEFT"
)
53
{
54
eye
(
LEFTEYE
, direction);
55
eye
(
RIGHTEYE
, direction);
56
return
;
57
}
58
59
if
(direction ==
"UPRIGHT"
)
60
{
61
eye
(
LEFTEYE
, direction);
62
eye
(
RIGHTEYE
, direction);
63
return
;
64
}
65
66
if
(direction ==
"DOWN"
)
67
{
68
eye
(
LEFTEYE
, direction);
69
eye
(
RIGHTEYE
, direction);
70
return
;
71
}
72
73
if
(direction ==
"DOWNLEFT"
)
74
{
75
eye
(
LEFTEYE
, direction);
76
eye
(
RIGHTEYE
, direction);
77
return
;
78
}
79
80
if
(direction ==
"DOWNRIGHT"
)
81
{
82
eye
(
LEFTEYE
, direction);
83
eye
(
RIGHTEYE
, direction);
84
return
;
85
}
86
87
if
(direction ==
"LEFT"
)
88
{
89
eye
(
LEFTEYE
, direction);
90
eye
(
RIGHTEYE
, direction);
91
return
;
92
}
93
94
if
(direction ==
"RIGHT"
)
95
{
96
eye
(
LEFTEYE
, direction);
97
eye
(
RIGHTEYE
, direction);
98
return
;
99
}
100
101
if
(direction ==
"FORWARD"
)
102
{
103
eye
(
LEFTEYE
, direction);
104
eye
(
RIGHTEYE
, direction);
105
return
;
106
}
107
108
if
(direction ==
"NORMAL"
)
109
{
110
eyebrow
(
LEFTBROW
, direction);
111
eyebrow
(
RIGHTBROW
, direction);
112
return
;
113
}
114
115
if
(direction ==
"CURIOUS"
)
116
{
117
eyebrow
(
LEFTBROW
,
"UP"
);
118
eyebrow
(
RIGHTBROW
,
"UP"
);
119
return
;
120
}
121
122
if
(direction ==
"ANGRY"
)
123
{
124
eyebrow
(
LEFTBROW
,
"DOWN"
);
125
eyebrow
(
RIGHTBROW
,
"DOWN"
);
126
return
;
127
}
128
}
129
130
131
void
Head::eye
(
unsigned
char
whichEye, QString direction)
132
{
133
// move servo to the start or end position (*not* to the min or max posisiotns!)
134
if
(direction ==
"UP"
)
135
{
136
if
(whichEye==
LEFTEYE
)
137
{
138
// up
139
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVEND
) );
140
// default
141
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVDEFAULT
) );
142
return
;
143
}
144
145
if
(whichEye==
RIGHTEYE
)
146
{
147
// up
148
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVSTART
) );
149
// default
150
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVDEFAULT
) );
151
return
;
152
}
153
return
;
154
}
155
156
if
(direction ==
"UPLEFT"
)
157
{
158
if
(whichEye==
LEFTEYE
)
159
{
160
// up
161
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVEND
) );
162
//left
163
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVSTART
) );
164
return
;
165
}
166
167
if
(whichEye==
RIGHTEYE
)
168
{
169
// up
170
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVSTART
) );
171
// left
172
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVSTART
) );
173
return
;
174
}
175
return
;
176
}
177
178
if
(direction ==
"UPRIGHT"
)
179
{
180
if
(whichEye==
LEFTEYE
)
181
{
182
// right
183
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVEND
) );
184
// up
185
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVEND
) );
186
return
;
187
}
188
189
if
(whichEye==
RIGHTEYE
)
190
{
191
// up
192
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVSTART
) );
193
// right
194
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVEND
) );
195
return
;
196
}
197
return
;
198
}
199
200
// move servo to the start or end position (*not* to the min or max posisiotns!)
201
if
(direction ==
"DOWN"
)
202
{
203
if
(whichEye==
LEFTEYE
)
204
{
205
// down
206
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVSTART
) );
207
// default
208
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVDEFAULT
) );
209
return
;
210
}
211
212
if
(whichEye==
RIGHTEYE
)
213
{
214
// down
215
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVEND
) );
216
// default
217
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVDEFAULT
) );
218
return
;
219
}
220
return
;
221
}
222
223
if
(direction ==
"DOWNLEFT"
)
224
{
225
if
(whichEye==
LEFTEYE
)
226
{
227
// down
228
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVSTART
) );
229
// left
230
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVSTART
) );
231
return
;
232
}
233
234
if
(whichEye==
RIGHTEYE
)
235
{
236
// down
237
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVEND
) );
238
// left
239
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVSTART
) );
240
return
;
241
}
242
return
;
243
}
244
245
if
(direction ==
"DOWNRIGHT"
)
246
{
247
if
(whichEye==
LEFTEYE
)
248
{
249
// down
250
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVSTART
) );
251
// right
252
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVEND
) );
253
return
;
254
}
255
256
if
(whichEye==
RIGHTEYE
)
257
{
258
// right
259
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVEND
) );
260
// down
261
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVEND
) );
262
return
;
263
}
264
return
;
265
}
266
267
// move servo to the start or end position (*not* to the min or max posisiotns!)
268
if
(direction ==
"LEFT"
)
269
{
270
if
(whichEye==
LEFTEYE
)
271
{
272
// left
273
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVSTART
) );
274
// default
275
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVDEFAULT
) );
276
return
;
277
}
278
279
if
(whichEye==
RIGHTEYE
)
280
{
281
// left
282
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVSTART
) );
283
// default
284
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVDEFAULT
) );
285
return
;
286
}
287
return
;
288
}
289
290
// move servo to its maximum end position
291
if
(direction ==
"LEFTMAX"
)
292
{
293
if
(whichEye==
LEFTEYE
)
294
{
295
//
296
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVMIN
) );
297
return
;
298
}
299
300
if
(whichEye==
RIGHTEYE
)
301
{
302
//
303
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVMIN
) );
304
return
;
305
}
306
return
;
307
}
308
309
// move servo to the start or end position (*not* to the min or max posisiotns!)
310
if
(direction ==
"RIGHT"
)
311
{
312
//qDebug("right");
313
if
(whichEye==
LEFTEYE
)
314
{
315
// right
316
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVEND
) );
317
// default
318
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVDEFAULT
) );
319
return
;
320
}
321
322
if
(whichEye==
RIGHTEYE
)
323
{
324
// right
325
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVEND
) );
326
// default
327
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVDEFAULT
) );
328
return
;
329
}
330
return
;
331
}
332
333
// move servo to its maximum end position
334
if
(direction ==
"RIGHTMAX"
)
335
{
336
if
(whichEye==
LEFTEYE
)
337
{
338
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVMAX
) );
339
return
;
340
}
341
342
if
(whichEye==
RIGHTEYE
)
343
{
344
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVMAX
) );
345
return
;
346
}
347
return
;
348
}
349
350
if
(direction ==
"FORWARD"
)
351
{
352
servos
->
moveServo
(
SERVO1
,
servos
->
getServoPosition
(
SERVO1
,
SVDEFAULT
) );
353
servos
->
moveServo
(
SERVO2
,
servos
->
getServoPosition
(
SERVO2
,
SVDEFAULT
) );
354
servos
->
moveServo
(
SERVO4
,
servos
->
getServoPosition
(
SERVO4
,
SVDEFAULT
) );
355
servos
->
moveServo
(
SERVO5
,
servos
->
getServoPosition
(
SERVO5
,
SVDEFAULT
) );
356
return
;
357
}
358
}
359
360
361
void
Head::eyebrow
(
unsigned
char
whichBrow, QString direction)
362
{
363
if
(direction ==
"NORMAL"
)
364
{
365
if
(whichBrow==
LEFTBROW
)
366
{
367
// default pos
368
servos
->
moveServo
(
SERVO3
,
servos
->
getServoPosition
(
SERVO3
,
SVDEFAULT
) );
369
return
;
370
}
371
372
if
(whichBrow==
RIGHTBROW
)
373
{
374
// default pos
375
servos
->
moveServo
(
SERVO6
,
servos
->
getServoPosition
(
SERVO6
,
SVDEFAULT
) );
376
return
;
377
}
378
return
;
379
}
380
381
if
(direction ==
"UP"
)
382
{
383
if
(whichBrow==
LEFTBROW
)
384
{
385
// inside up
386
servos
->
moveServo
(
SERVO3
,
servos
->
getServoPosition
(
SERVO3
,
SVEND
) );
387
return
;
388
}
389
390
if
(whichBrow==
RIGHTBROW
)
391
{
392
// inside up
393
servos
->
moveServo
(
SERVO6
,
servos
->
getServoPosition
(
SERVO6
,
SVSTART
) );
394
return
;
395
}
396
return
;
397
}
398
399
if
(direction ==
"DOWN"
)
400
{
401
if
(whichBrow==
LEFTBROW
)
402
{
403
// inside down
404
servos
->
moveServo
(
SERVO3
,
servos
->
getServoPosition
(
SERVO3
,
SVSTART
) );
405
return
;
406
}
407
408
if
(whichBrow==
RIGHTBROW
)
409
{
410
// inside down
411
servos
->
moveServo
(
SERVO6
,
servos
->
getServoPosition
(
SERVO6
,
SVEND
) );
412
return
;
413
}
414
return
;
415
}
416
}
direcs
src
head.cpp
Generated on Sat Feb 2 2013 21:41:01 for direcs by
1.8.1.1