/**
 * @brief MapManager::setupRobotManagerThread esegue il setup del thread su cui gira la parte di controllo del robot
 */
void MapManager::setupRobotManagerThread()
{
    //Creo l'istanza del thread secondario
//    QThread* robotManagerThread = new QThread(this);
    robotManagerThread = new QThread(this);

    // Sposto l'oggetto che controlla il robot nell'altro thread
    robotManager.moveToThread(robotManagerThread);

    //Connetto il signal che dichiara l'inizio dell'esecuzione del thread con lo slot che si occupa dell'inizializzazione della classe
    QObject::connect(robotManagerThread, SIGNAL(started()), &robotManager, SLOT(init()));

    // Connetto i signal della classe del robot a quelli della GUI, in modo da poterli usare da QML
    QObject::connect(&robotManager, SIGNAL(pointFound(QVariant,QVariant)), this, SIGNAL(pointFound(QVariant,QVariant)));
    QObject::connect(&robotManager, SIGNAL(victimFound(QVariant)), this, SIGNAL(victimFound(QVariant)));
    QObject::connect(&robotManager, SIGNAL(robotTurn(QVariant)), this, SIGNAL(robotTurn(QVariant)));
    QObject::connect(&robotManager, SIGNAL(generateStep()), this, SIGNAL(generateStep()));

    // Dato che uso signal che passano paremtri Mat di opencv, devo esplori al meta system delle Qt
    qRegisterMetaType< cv::Mat >("cv::Mat");

    // Connetto i signal che inviano immagini da mostrare ai rispettivi slot
    QObject::connect(&robotManager, SIGNAL(newCameraImage(cv::Mat)), this, SLOT(printImage(cv::Mat)));
    QObject::connect(&robotManager, SIGNAL(victimImageFound(cv::Mat)), this, SLOT(printVictimImage(cv::Mat)));

    // Segnalo di terminare il thread alla chiusura della GUI (anche se non sembra far nulla)
    QObject::connect(this, SIGNAL(destroyed()), robotManagerThread, SLOT(quit()));

    // Avvio il thread
    robotManagerThread->start();
}
Esempio n. 2
0
int ex(nodeType *p) {
    if (!p) return 0;
    switch (p->type) {
        case typeCon:
            return p->con.value;
        case typeId:
            switch (p->id.s_type){
            case 2:
            //fprintf(flerror, "Inside typeID for function!!!!!!!!\n");
            globsym = symtab;
            count=globsym[p->id.i].noParams-1;
            while(count>=0){
                //fprintf(flout,"%s ",globsym[p->id.i].symboltable[globsym[p->id.i].paramlist[count]].name);
                popValue=pop();
                tempList[count]=popValue;
                globsym[p->id.i].symboltable[globsym[p->id.i].paramlist[count]].value = popValue;
                count--;
            }
            symtab = globsym[p->id.i].symboltable;
            ex(globsym[p->id.i].op[0]);
            count=0;
            while(count<globsym[p->id.i].noParams){
              popValue = tempList[count];
              push(popValue);
              count++;
            }
            symtab =symboltable;
            }
            default:  return symtab[p->id.i].value;
        case typeFunction:
            ex(p->opr.op[0]);
            ex(p->opr.op[1]);
            return 0;
        case typeOpr:
            switch (p->opr.oper) {
                int brojac;
                case WHILE:
                    while (ex(p->opr.op[0])) ex(p->opr.op[1]);
                    return 0;
                case POVTORUVAJ:
                    while (ex(p->opr.op[0])) ex(p->opr.op[1]);
                    return 0;
                case POVTORUVAJ_2:
                    brojac = ex(p->opr.op[0]);
                    while (brojac > 0) {
                        brojac--;
                        ex(p->opr.op[1]);
                    }
                    return 0;
                case IF:
                    if (ex(p->opr.op[0])) ex(p->opr.op[1]); else if (p->opr.nops > 2) ex(p->opr.op[2]);
                    return 0;
                case PRINT:
                    /*printing nasoka constant is not implemented */
                    if (p->opr.op[0]->type == 1 && p->opr.op[0]->id.s_type == 1) {
                        switch (ex(p->opr.op[0])) {
                            case 0:
                                fprintf(flout, "I\n");
                                break;
                            case 1:
                                fprintf(flout, "Z\n");
                                break;
                            case 2:
                                fprintf(flout, "S\n");
                                break;
                            case 3:
                                fprintf(flout, "J\n");;
                                break;
                        }
                    } else {
                        fprintf(flout, "%d\n", ex(p->opr.op[0]));
                    }
                    return 0;
                case ';':
                    ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case NEWLINE:
                    ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case ODI:
                    fprintf(flcommands, "WALK\n");
                    /*
                    if(canMove()){
                    robotMove();
                    fprintf(flcommands, "WALK\n");
                    }
                    else {
                    fprintf(flout, "CANT_WALK\n");
                    }
                    */
                    ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case ZEMI:
                    fprintf(flcommands, "TAKE\n");
                    /*
                    if(ENVIRONMENT[ri][rj]==COIN){
                    fprintf(flcommands, "TAKE\n");
                    nbrCoins++;
                    ENVIRONMENT[ri][rj]=0;
                    }
                    else {
                      fprintf(flout, "CANT_TAKE\n");
                    }
                    */
                    ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case OSTAVI:
                    fprintf(flcommands, "LEAVE\n");
                    /*
                    if(nbrCoins>0 && ENVIRONMENT[ri][rj]==0){
                    fprintf(flcommands, "LEAVE\n");
                    nbrCoins--;
                    ENVIRONMENT[ri][rj]=COIN;
                    }
                    else fprintf(flout, "CANT_LEAVE\n");
                    */
                    ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case SVRTIDESNO: robotTurn(1); fprintf(flcommands, "TURN_RIGHT\n"); ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case SVRTILEVO: robotTurn(0); fprintf(flcommands, "TURN_LEFT\n"); ex(p->opr.op[0]);
                    return ex(p->opr.op[1]);
                case '=':
                    return (symtab[p->opr.op[0]->id.i].value) = ex(p->opr.op[1]);
                case UMINUS:
                    return -ex(p->opr.op[0]);
                case '+':
                    return ex(p->opr.op[0]) + ex(p->opr.op[1]);
                case '-':
                    return ex(p->opr.op[0]) - ex(p->opr.op[1]);
                case '*':
                    return ex(p->opr.op[0]) * ex(p->opr.op[1]);
                case '/':
                    return ex(p->opr.op[0]) / ex(p->opr.op[1]);
                case '<':
                    return ex(p->opr.op[0]) < ex(p->opr.op[1]);
                case '>':
                    return ex(p->opr.op[0]) > ex(p->opr.op[1]);
                case GE:
                    return ex(p->opr.op[0]) >= ex(p->opr.op[1]);
                case LE:
                    return ex(p->opr.op[0]) <= ex(p->opr.op[1]);
                case NE:
                    return ex(p->opr.op[0]) != ex(p->opr.op[1]);
                case EQ:
                    return ex(p->opr.op[0]) == ex(p->opr.op[1]);
            }
    }
    return 0;
}