Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120146169
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
Wed, Jul 2, 06:26
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Jul 4, 06:26 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27129555
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