예제 #1
0
void ModeTwo::loop()
{
	lcd->clear();
        processActions();
        displayData();
        delay(200);
        *btn = btn_none;
}
예제 #2
0
void Bubble::updateContent()
{
    m_body->setTitle(m_entity->summary());
    m_body->setText(m_entity->body());

    processIconData();
    processActions();
}
예제 #3
0
String SumoRobot::go(){
	
	if (!processActions()){	
		getLineSensorReadings();
		
		//check if robot is on the white ring
		if (m_lineSensorReadings[0] && m_lineSensorReadings[1]){
			m_actionBack = COUNTS_FOR_BACKING_UP; //go back for 10 counts
			m_actionSharpLeft = COUNTS_FOR_TURN;  //turn sharp left for 5 counts
			return "Both line sensors are active, will back up and turn";
		} else if (m_lineSensorReadings[0]){
			m_actionBack = COUNTS_FOR_BACKING_UP/2;
			m_actionSharpLeft = COUNTS_FOR_TURN;
			return "Left line sensor is active, will back up and turn";
		} else if (m_lineSensorReadings[1]){
			m_actionBack = COUNTS_FOR_BACKING_UP/2;
			m_actionSharpRight = COUNTS_FOR_TURN;
			return "Right line sensor is active, will back up and turn";
		} else if (m_lineSensorReadings[2]){
			//we are being pushed back, push forward  and then turn
			m_actionForward = COUNTS_FOR_BACKING_UP;
			m_actionSharpRight = COUNTS_FOR_TURN;
			return "Back line sensor is active, will go forward and turn";
		}
		
		//check if we see the other robot
		getDistanceSensorReadings();
		
		if (m_distanceSensorReadings[0] >= DISTANCE_SENSOR_THRESHOLD && 
			m_distanceSensorReadings[1] >= DISTANCE_SENSOR_THRESHOLD){
			//we see the other robot in front of us, attack!
			go(255, 255);
			return "Both distance sensors detect the other robot, attack full speed forward";
		} else if (m_distanceSensorReadings[0] >= DISTANCE_SENSOR_THRESHOLD){
			//we see the other robot on our left, sharp turn left
			go(-255, 255);
			return "Left distance sensors detects the other robot, sharp left";
		} else if (m_distanceSensorReadings[1] >= DISTANCE_SENSOR_THRESHOLD){
			//we see the other robot on our right, sharp turn right
			go(255, -255);
			return "Right distance sensors detects the other robot, sharp right";
		} else if (m_distanceSensorReadings[2] >= DISTANCE_SENSOR_THRESHOLD){
			//we see the other robot behind us, turn around
			m_actionSharpLeft = COUNTS_FOR_FULL_TURN;
			return "Back distance sensors detects the other robot, turn around";
		}
		
		//let's look for the other robot
		go(100, 125);
		return "Find the other robot";
	} else {
		return "Executing previously issued action: " + m_currAction;
	}
}
예제 #4
0
int processSelectedActionsAndConditions(struct crealNodeStruct nodes[], creal_t properties[], creal_t returnVector[], uint rangePointer[], uint rangeSize)
{	
	//this is the main function to process the creal nodes... through a selection!
	
		
	uint i, k, *actionTruFalseArray; //make vars 
	i = k = 0; //set to zero
	
	//~ memset(trueFalseArray, 0, sizeof(uint) * rangeSize);

	for (i = 0; i < rangeSize; i++)
	{
		
		
		actionTruFalseArray = (uint *) alloca(sizeof(uint) * nodes[rangePointer[i]].numberOfActions);
		
		memset(actionTruFalseArray, 0, sizeof(uint) * nodes[rangePointer[i]].numberOfActions);
		
		
		//~ #pragma omp parallel for //openMP parallel for loop
		for (k = 0; k < nodes[rangePointer[i]].numberOfActions; k++)
		{
	
			
			actionTruFalseArray[k] = evaluateConditions(&nodes[rangePointer[i]], properties, k);
			
		
		}//end of inner for iiteration
		
		//~ #pragma omp parallel for //openMP parallel for loop
		for (k = 0; k < nodes[rangePointer[i]].numberOfActions; k++)
		{
				if(actionTruFalseArray[k])
				{
					
					processActions(&nodes[rangePointer[i]], properties, returnVector, k);
					
				}
		
		}//end of inner for iiteration
		
		
	}//end of outer for iteration

						//end the function right here
	return 0; // everything was good	
}
예제 #5
0
int TestCFSM::runScenario(const int num)
{
    int result = -1;

    QString scenarioFilename =
        QString("scenario-%1.txt").arg(num, 2, 10, QChar('0'));
    QFile inputFile(scenarioFilename);
    if(inputFile.open(QIODevice::ReadOnly))
    {
        QTextStream in(&inputFile);
        processActions(in);
        result = processResults(in);
        if(result != 0)
        {
            // Test failed!
            QTextStream console(stdout);
            console << "--" << endl
                    << "Test failed: " << scenarioFilename << endl;
            if(result == 1)
            {
                console << "Model internal state does not match "
                        << "desired state.  Model data:" << endl;
                printModel();
            }
            console << "--" << endl << endl;
        }
    }
    else
    {
        QTextStream console(stdout);
        console << "ERROR: could not read file: " << scenarioFilename << endl;
        // Don't try to recover.
        QApplication::exit(1);
    }
    inputFile.close();

    return (result);
}
예제 #6
0
void TabManagerWidget::customContextMenuRequested(const QPoint &pos)
{
    QMenu menu;
    QAction* action;
    QMenu groupTypeSubmenu(tr("Group by"));
    action = groupTypeSubmenu.addAction(tr("&Window"), this, SLOT(changeGroupType()));
    action->setData(GroupByWindow);
    action->setCheckable(true);
    action->setChecked(m_groupType == GroupByWindow);

    action = groupTypeSubmenu.addAction(tr("&Domain"), this, SLOT(changeGroupType()));
    action->setData(GroupByDomain);
    action->setCheckable(true);
    action->setChecked(m_groupType == GroupByDomain);

    action = groupTypeSubmenu.addAction(tr("&Host"), this, SLOT(changeGroupType()));
    action->setData(GroupByHost);
    action->setCheckable(true);
    action->setChecked(m_groupType == GroupByHost);

    menu.addMenu(&groupTypeSubmenu);

    if (m_isDefaultWidget) {
        menu.addAction(QIcon(":/tabmanager/data/side-by-side.png"), tr("&Show side by side"), this, SIGNAL(showSideBySide()))->setObjectName("sideBySide");
    }

    menu.addSeparator();

    if (isTabSelected()) {
        menu.addAction(QIcon(":/tabmanager/data/tab-detach.png"), tr("&Detach checked tabs"), this, SLOT(processActions()))->setObjectName("detachSelection");
        menu.addAction(QIcon(":/tabmanager/data/tab-bookmark.png"), tr("Book&mark checked tabs"), this, SLOT(processActions()))->setObjectName("bookmarkSelection");
        menu.addAction(QIcon(":/tabmanager/data/tab-close.png"), tr("&Close checked tabs"), this, SLOT(processActions()))->setObjectName("closeSelection");
    }

    menu.exec(ui->treeWidget->viewport()->mapToGlobal(pos));
}
예제 #7
0
void ControllerThread::Main() {
    PTime tBase; // base time for tStep multiplier
    PTimeInterval tStep(1); // 1ms, loop step (1Hz); up to 14 bytes per step for 115200 serial line
    PTime tNow; // current time
    PTime tThen; // expected execution time
    unsigned short i = 0; // multiplier for tStep

    // initialize
    PTRACE(1, "Arduino initialization");
    char buffer[256];
    PINDEX iRead = 0;
    PINDEX len   = 0;
    // reset serial port
    pserial->ClearDTR();
    pserial->ClearRTS();
    pserial->ClearBreak();
    pserial->SetDTR();
    pserial->SetRTS();

    // drop junk from serial port
    do {
        if (shutdown.Wait(0)) {
            return;
        };
        pserial->Read(buffer, 256); // flush serial data
    } while (pserial->GetLastReadCount());
    memset(buffer, 0, 256);

    // waiting for 3 heat beat
    do {
        if (shutdown.Wait(0)) {
            return;
        };
        pserial->Read(buffer, 256);
        iRead = pserial->GetLastReadCount();
        if (iRead == 2 && buffer[0] == 0 && buffer[1] == 0) {
            len += iRead;
            PTRACE(1, "HeatBeat from Arduino #" << len/2);
        };
    } while(len < 6);
    PTRACE(1, "Arduino initialization done");
    fReady = PTrue;

    // reset Arduino
    pushAction(0xFF, CMD_RESET);
    pushAction(0xFF, CMD_SETBASE0); // X1
    pushAction(0xFF, calibrationTable[0]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE1); // Y1
    pushAction(0xFF, calibrationTable[1]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE2); // X2
    pushAction(0xFF, calibrationTable[2]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE3); // Y2
    pushAction(0xFF, calibrationTable[3]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE4); // LT
    pushAction(0xFF, calibrationTable[4]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE5); // RT
    pushAction(0xFF, calibrationTable[5]->GetAt(10000));
    pushAction(0xFF, CMD_RESET);
    // main loop
    do {
        bool fNewActions = false;
        BYTE naction;
        PInt32l value;
        /*
         * get x, y, button and other events
         */
        PTRACE(6, "Main\t" << dumpAction("actions before population: "));
        while(popAction(&naction, &value)) {
            PIntArray *actionQueue = actionQueuePool[naction];

            fNewActions = true;
            PTRACE(6, "Main\tadd new value to actionQueuePool[" << (int)naction << "] with queue size " << actionQueue->GetSize());
            actionQueue->SetAt(actionQueue->GetSize(), value);
        };
        if (fNewActions) {
            PTRACE(6, "Main\t" << dumpAction("actions after population: "));
            summarizeActions(); // summarize action events by type
            PTRACE(6, "Main\t" << dumpAction("actions after summarization: "));
        };
        /*
         * process actions:
         * send current state to arduino
         * then receive state from arduino
         * and update actions after sucsessful transmit
         */
        processActions();
        /*
         * wait next tStep ms
         */
        i++;
        tThen = tBase + tStep * i;
        tNow = PTime();
        // reset multiplier
        if (i >= 255) {
            i = 0;
            tBase = tThen;
        };
        // step was too long (tThen less than tNow)
        if (tNow.Compare(tThen) != LessThan) {
            PTRACE(6, "Main\tnow: " << tNow.AsString("h:m:s.uuuu") << " then: " << tThen.AsString("h:m:s.uuuu") << " i: " << (int)i << " diff: " << (tNow - tThen).GetMilliSeconds() << "ms");
            i += (tNow - tThen).GetMilliSeconds() / tStep.GetMilliSeconds() + 1; // number of steps + 1 step
            tThen = tBase + tStep * i;
            PTRACE(6, "Main\tcorrected then: " << tThen.AsString("h:m:s.uuuu") << " i: " << (int)i);
        };
        PTRACE(7, "Main\tstep " << (tThen - tNow).GetMilliSeconds() << "ms"); 
    } while(!shutdown.Wait((tThen - tNow).GetMilliSeconds()));
}