Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65755572
main.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jun 6, 00:21
Size
1 KB
Mime Type
text/x-c
Expires
Sat, Jun 8, 00:21 (2 d)
Engine
blob
Format
Raw Data
Handle
18122459
Attached To
R9807 cellulo-lua
main.cpp
View Options
#include <stdio.h>
#include "../cellulounity.h"
#include <unistd.h>
#include <pthread.h>
#include <QDebug>
void
onKidnappedChanged
()
{
qDebug
()
<<
"callback: kidnapped changed"
;
}
void
*
testCellulo
(
void
*
arg
)
{
// LED colors
int
r
,
g
,
b
;
r
=
g
=
b
=
0
;
// creating and destroying robots
while
(
true
)
{
// starting the library
initialize
();
// waiting for connection
while
(
true
)
{
if
(
robotsRemaining
()
<=
1
)
{
qDebug
()
<<
"robots remaining: "
<<
robotsRemaining
();
sleep
(
1
);
}
else
break
;
}
// creating robot
long
robot
=
newRobot
();
fprintf
(
stderr
,
"Got robot %x
\n
"
,
robot
);
// will react on kidnapping
setKidnappedCallback
(
robot
,
&
onKidnappedChanged
);
// printing data
qDebug
()
<<
getX
(
robot
)
<<
getY
(
robot
)
<<
getTheta
(
robot
)
<<
(
getKidnapped
(
robot
)
?
"true"
:
"false"
);
// updating LED color
setVisualEffect
(
robot
,
0
,
r
,
g
,
b
,
255
);
r
+=
50
;
r
%=
255
;
// waiting and reinitizlizing library
// will connect to the same robot on next iteration if there are no other users of the library
sleep
(
1
);
destroyRobot
(
robot
);
initialize
();
}
return
NULL
;
}
int
main
()
{
pthread_t
thread
;
pthread_create
(
&
thread
,
NULL
,
testCellulo
,
NULL
);
pthread_join
(
thread
,
NULL
);
return
0
;
}
Event Timeline
Log In to Comment