void HTMLChatViewTest::messagesAndEvents() { prepareTest("testingTheme/"); appendSomeEvents(); qDebug() << "after app ft event"; waitUntil(&helper.append); checkResultBody( "<div><b style=\"color: green\">header</b></div><hr>" "<div id=\"Chat\">" "<div class=\"status_container\"><div>fileTransferComplete :: 1970-02-05 - 01:00</div>" "Finished downloading screen.png. || event fileTransfer <br></div><span>" "<div class=\"combine\"><div class=\"ctime\">1970-02-05 - 01:00</div>" "http://url.com - myicon.png - ltr - [email protected] - senu - " "Jabber - [email protected] - http://url.com :: message \" <br>" " . || message outgoing <span style=\"color: #194978\">COLOR</span>" "</div><div id=\"insert\"></div></span>" "</div>" "<hr><div><b style=\"color: red\">footer</b></div>" ); }
void launcher() { if(vexRT[Btn7U] == 1) { lawnswap2 ++; if(lawnswap2 >= 3) { lawnswap2 = 0; } } if(vexRT[Btn7D] == 1) { lawnswap2 --; if(lawnswap2 <= -1) { lawnswap2 = 2; } } if(lawnswap2 == 0) { lawnswap = 0; } else if(lawnswap2 == 1) { lawnswap = 1; } else if(lawnswap2 == 2) { lawnswap = 0; } if(vexRT[Btn8L] == 1 && lawnswap == 0) { ideal = 39; enc2 = ideal - 2; enc3 = ideal + 2; if(lawnchair[0] < 30) { lawnchair[0] = 30; } } if(vexRT[Btn8D] == 1 && lawnswap == 0) { ideal = 34; enc2 = ideal - 2; enc3 = ideal + 2; if(lawnchair[0] < 30){ lawnchair[0] = 30; } } if(vexRT[Btn8U] == 1 && lawnswap == 0) { ideal = 42; enc2 = ideal - 2; enc3 = ideal + 2; if(lawnchair[0] < 30){ lawnchair[0] = 30; } } //Stop if(vexRT[Btn8R] == 1 && lawnswap == 0) { ideal = 0; lawnchair[0] = 0; } //Half Decrease if(vexRT[Btn8L] == 1 && lawnswap == 1) { lawnchair[1] = lawnchair[1] - 5; waitUntil(vexRT[Btn8L] == 0); } //Full Decrease if(vexRT[Btn8D] == 1 && lawnswap == 1) { lawnchair[1] = lawnchair[1] - 10; waitUntil(vexRT[Btn8D] == 0); } //Bump Up if(vexRT[Btn8U] == 1 && lawnswap == 1) { lawnchair[1] = lawnchair[1] + 10; waitUntil(vexRT[Btn8U] == 0); } //Stop if(vexRT[Btn8R] == 1 && lawnswap == 1) { lawnchair[1] = 0; waitUntil(vexRT[Btn8R] == 0); } motor[port9] = lawnchair[lawnswap]; motor[port8] = lawnchair[lawnswap]; }
void DASSL_integrate (SIM_simulator simulate) { CLC_simulator simulator = (CLC_simulator) simulate->state->sim; clcData = simulator->data; clcModel = simulator->model; simOutput = simulator->output; int i; double t = clcData->it; double tout; const double _ft = clcData->ft; double dQRel = clcData->dQRel[0]; double dQMin = clcData->dQMin[0]; double *_x = clcData->x; double *rwork; int is_sampled = simOutput->commInterval != CI_Step; double step_size; if (is_sampled) { step_size = simOutput->sampled->period[0]; } const int num_steps = ( is_sampled ? ceil (_ft / step_size) + 2 : MAX_OUTPUT_POINTS); double **solution = checkedMalloc (sizeof(double*) * simOutput->outputs); double *solution_time = checkedMalloc (sizeof(double) * num_steps); double **outvar = checkedMalloc (sizeof(double) * simOutput->outputs); int info[20], lrw, liw, *iwork; double *x, *dx, rel_tol = dQRel, abs_tol = dQMin; int numofconstr = clcData->events, method_info = 0; int *root_output; int size = clcData->states; int event_detected = 0; x = checkedMalloc (sizeof(double) * clcData->states); dx = checkedMalloc (sizeof(double) * clcData->states); root_output = checkedMalloc (sizeof(int) * clcData->events); lrw = 5000 + 15000 * clcData->states + /*clcData->states * clcData->states +*/8 * clcData->events; rwork = checkedMalloc (sizeof(double) * lrw); CLC_compute_outputs (simOutput, solution, num_steps); for (i = 0; i < clcData->states; i++) x[i] = _x[i]; cleanDoubleVector (dx, 0, clcData->states); cleanVector (root_output, 0, clcData->events); cleanVector (info, 0, 20); if (!is_sampled) { info[2] = 1; } liw = 60040; iwork = checkedMalloc (sizeof(int) * liw); int percentage = 0; // Save first step CLC_save_step (simOutput, solution, solution_time, t, clcData->totalOutputSteps, x, clcData->d, clcData->alg); clcData->totalOutputSteps++; getTime (simulator->sTime); #ifdef SYNC_RT setInitRealTime(); #endif while (t < _ft) { if (!is_sampled) { tout = _ft; } else { if (!event_detected) { tout = t + step_size; } else { if (fabs (tout - t) < 1e-12) { CLC_save_step (simOutput, solution, solution_time, tout, clcData->totalOutputSteps, x, clcData->d, clcData->alg); clcData->totalOutputSteps++; tout = t + step_size; } } event_detected = 0; } if (tout > _ft) tout = _ft; ddaskr_ (DASSL_model, &size, &t, x, dx, &tout, info, &rel_tol, &abs_tol, &method_info, rwork, &lrw, iwork, &liw, NULL, NULL, NULL, NULL, DASSL_events, &numofconstr, root_output); if (method_info < 0) { printf ( "Error: DASSL returned IDID = %d. Check DASSL documentation\n", method_info); exit (-1); } #ifdef SYNC_RT /* Sync */ waitUntil(t); #endif if (method_info == 5) { CLC_handle_event (clcData, clcModel, x, root_output, t, iwork); if (is_sampled) event_detected = 1; info[0] = 0; } if (!is_sampled) { CLC_save_step (simOutput, solution, solution_time, t, clcData->totalOutputSteps, x, clcData->d, clcData->alg); clcData->totalOutputSteps++; } else { if (!event_detected) { if (fabs (tout - solution_time[clcData->totalOutputSteps - 1]) > step_size / 10) { CLC_save_step (simOutput, solution, solution_time, tout, clcData->totalOutputSteps, x, clcData->d, clcData->alg); clcData->totalOutputSteps++; } } else { } } if ((int) (t * 100 / _ft) > percentage) { percentage = 100 * t / _ft; fprintf (stderr, "*%g", t); fflush (stderr); } } /* if (!event_detected && is_sampled) { if (solution_time[totalOutputSteps]<t) { CLC_save_step(simOutput,solution,solution_time,t,totalOutputSteps,x, clcData->d); totalOutputSteps++; } } */ clcData->totalSteps += iwork[10]; clcData->totalStepsDASSL += iwork[11]; clcData->totalJacobians += iwork[12]; clcData->totalCrossingEvaluations += iwork[35]; getTime (simulator->sTime); subTime (simulator->sTime, simulator->iTime); if (simulator->settings->debug == 0 || simulator->settings->debug > 1) { SD_print (simulator->simulationLog, "Simulation time (DASSL):"); SD_print (simulator->simulationLog, "----------------"); SD_print (simulator->simulationLog, "Miliseconds: %g", getTimeValue (simulator->sTime)); SD_print (simulator->simulationLog, "Function evaluations: %llu", clcData->funEvaluations); //SD_print (simulator->simulationLog, "Scalar function evaluations: %d", clcData->scalarEvaluations); //SD_print (simulator->simulationLog, "Zero Crossings : %d", clcData->zeroCrossings); SD_print (simulator->simulationLog, "Function evaluations (reported by DASSL): %d", clcData->totalStepsDASSL); SD_print (simulator->simulationLog, "Jacobian evaluations : %d", clcData->totalJacobians); SD_print (simulator->simulationLog, "Zero crossing evaluations : %d", clcData->totalCrossingEvaluations); SD_print (simulator->simulationLog, "Output steps: %d", clcData->totalOutputSteps); SD_print (simulator->simulationLog, "Simulation steps: %d", clcData->totalSteps); SD_print (simulator->simulationLog, "Events detected : %d", clcData->totalEvents); } CLC_write_output (simOutput, solution, solution_time, clcData->totalOutputSteps); // To avoid QSS output free (x); free (dx); free (outvar); free (root_output); free (solution_time); free (rwork); free (iwork); for (i = 0; i < simOutput->outputs; i++) { free (solution[i]); } free (solution); }
task Rijden() { // Geluid dat de robot maakt tijdens het rijden, in loop. k = 0; // Reset kruispuntboolean naar 0 //l = 0; int var = 0; // variabele die naar een waarde wordt geset afhankelijk van welke sensor een signaal geeft. while(true){ playSoundFile("hehe.rso"); // Linker sensor: Trigger wanneer de zwart-wit sensor (links) te weinig wit registreert en dus te veel op de lijn komt. Voer case 1 uit: stuur naar links. if(SensorValue[WIT] < 55) var=1; // Rechter sensor: Trigger wanneer de kleurensensor (rechts) zwart registreert en dus te veel op de lijn komt. Voer case 1 uit: stuur naar rechts. if((SensorValue[ZWART]==blackcolor)||(SensorValue[ZWART]==greencolor)) var=2; // kruispuntherkenning: Trigger wanneer zowel de kleurensensor als de zwartwit sensor getriggerd worden. Voer case 3 uit: stop, rij achteruit, wacht op commando. if(((SensorValue[ZWART]==blackcolor)||(SensorValue[ZWART]==greencolor))&&((SensorValue[WIT] <55))) var=3; // Tegenovergestelde van kruispuntherkenning: Trigger als de sensoren alleen wit registreren. Voer case 4 uit: rij naar voren. if(((SensorValue[ZWART]!=blackcolor)&&(SensorValue[ZWART]!=greencolor))&&((SensorValue[WIT] >55))) var=4; // Obstakelsensor: Trigger wanneer de sonar een obstakel registreert. Voer case 5 uit: geef geluid en stop. if (SensorValue[sonar] <30) var=5; switch(var) { case 1: //stuur naar links setMotor(motorB,30); setMotor(motorA,-5); var=0; k=0; break; case 2: //stuur naar rechts setMotor(motorB,-5); setMotor(motorA,30); var=0; k=0; break; case 3: //stoppen, ga achteruit, wacht op BlueTooth signaal setMotor(motorB,0); setMotor(motorA,0); wait1Msec(100); clearSounds(); setMotorTarget(motorA,85,-30); // ga achteruit setMotorTarget(motorB,85,-30); waitUntilMotorStop(motorA); waitUntilMotorStop(motorB); waitUntil(k==1); // wacht op een BlueTooth signaal dat links, rechts of vooruit zegt en k=1 triggert. var=0; k=0; break; case 4: // rij naar voren setMotor(motorB,30); setMotor(motorA,30); var=0; k=0; break; case 5: // als sonar wat ziet: schreeuw, rem rustig af en roteer 180*. clearSounds(); playSoundFile("scream4.rso"); for (int i=3000;i>0 ; i--) { setMotor(motorA,i/100); setMotor(motorB,i/100); } //waitUntil(l==1); //nxtDisplayTextLine(1,"%d",i); waitUntilMotorStop(motorA); waitUntilMotorStop(motorB); // oorspronkelijk hadden we code om een object te ontwijken, zowel linksom als rechtsom, // met als alternatief om 180* te draaien. Dit kregen we echter niet op tijd volledig // aan de praat, waardoor we hebben gekozen om hardcoded 180* te draaien. // zie hiervoor de AvoidObject.c en AvoidObject.h files. // //AvoidMain(); //waitUntil(avoidDone==1); //waitUntil(l==1); //avoidDone = 0; // // einde ontwijkcode // hardcoded rotate robot 180* //setMotorTarget(motorA, 360, 30); // rechtsom draaien //setMotorTarget(motorB, 360, -30); //waitUntilMotorStop(motorA); //waitUntilMotorStop(motorB); // end hardcoded rotate robot 180* setMotorTarget(motorA, 360, 30); waitUntilMotorStop(motorA); setMotorTarget(motorA, 135, 30); setMotorTarget(motorB, 135, 30); waitUntilMotorStop(motorA); setMotorTarget(motorB, 360,30); waitUntilMotorStop(motorB); setMotorTarget(motorA, 540, 30); setMotorTarget(motorB, 540, 30); waitUntilMotorStop(motorA); setMotorTarget(motorB, 360,30); waitUntilMotorStop(motorB); setMotorTarget(motorA, 135, 30); setMotorTarget(motorB, 135, 30); waitUntilMotorStop(motorA); var=0; l=0; break; } } }
int waitUntil(Mutex& mutex, const std::chrono::time_point<TickClock, Duration> timePoint) { return waitUntil(mutex, std::chrono::time_point_cast<TickClock::duration>(timePoint)); }
int waitFor(Mutex& mutex, const std::chrono::duration<Rep, Period> duration, Predicate predicate) { return waitUntil(mutex, TickClock::now() + duration + TickClock::duration{1}, std::move(predicate)); }
void loop() { // Though counter-intuitive, game creation cannot be in setup because of varying arduino boot times and boot gibberish if (!gameCreated) { drawGUI(); while(!waitUntil(JOYSTICK_BUTTON_PIN, false)); if (!startNetwork()) { tft.fillScreen(ST7735_BLACK); // we must clear all conflicting messages from screen tft.setCursor(0,0); dualPrint("Network connection failed!"); dualPrint("Please ensure:"); dualPrint("1) both arduinos are connected"); dualPrint("2) both parties pressed the joystick"); dualPrint("If both are true, consult someone who"); dualPrint("looks like he knows what he's talking about"); dualPrint("Reset both Arduinos to try again"); while(1); } /* Extensibility Goal: * Enable colour selection here, time permissible */ gameCreated = true; } if (!gameStarted) { setSpawns(&player1, &player2); setColour(&player1, &player2); tft.fillScreen(ST7735_BLACK); startCountdown(); gameStarted = true; } winner = gameOver(&player1.currentPosition, &player2.currentPosition); if (winner) { tft.setCursor(0, 80); String message; switch (winner) { case -1: message = "YOU SUPER TIE"; break; case 1: message = "YOU SUPER WIN"; player1.score++; break; case 2: message = "YOU SUPER LOSE"; player2.score++; break; } tft.println(message); tft.println("SCORES:"); tft.print("You: "); tft.print(player1.score); tft.print(" | Him: "); tft.println(player2.score); tft.println("Again? <Press Joystick>"); waitUntil(JOYSTICK_BUTTON_PIN, LOW); memset(&wallPositions, 0, 2560); // 2560 is a magic number because size_ts were acting unexpectedly gameStarted = false; tft.fillScreen(ST7735_BLACK); } else { // add a wall ad draw car at current position addWallPosition(player1.currentPosition); addWallPosition(player2.currentPosition); tft.fillRect(player1.currentPosition.x, player1.currentPosition.y, 2, 2, player1.colour); tft.fillRect(player2.currentPosition.x, player2.currentPosition.y, 2, 2, player2.colour); movement_t newDirection = getJoystickInput(); if (validInput(newDirection, player1.direction)) player1.direction = newDirection; sendDeltas(&player1.direction); receiveDeltas(&player2.direction); player1.currentPosition.x += player1.direction.x; player1.currentPosition.y += player1.direction.y; player2.currentPosition.x += player2.direction.x; player2.currentPosition.y += player2.direction.y; delay(75); // this is how we control the game speed /* Extensibility Goal: * Find a more efficient and reliable way of controlling game speed. * Implement it, and allow it to be customized */ } }