int Car::collision() { if ( collideWith == SlowDown ) { slowDown(); } else{ crashed = TRUE; } return 0; }
void phase_two(char* path) { //using shortest path, create map from start to finish double map[MAP_SIZE][2]; buildMap(map, path); printMap(map); //Follow map to finish followMap(map); slowDown(); }
void ACC(float actualTimeBetweenVehicles, S32 distanceToVehicle, float leadVehicleVelocity) { if(actualTimeBetweenVehicles > MAXIMUM_TIME_BETWEEN_VEHICLES) //No vehicle to follow or too far away. (Zone A) { controlMotors(INITIAL_MOTOR_POWER, BRAKE_OFF); /*Drive accordingly to normal Cruise Control*/ } else if(actualTimeBetweenVehicles < MINIMUM_TIME_BETWEEN_VEHICLES) //Vehicle too close. (Zone E) { //brake(); slowDown(MOTOR_POWER_ADJUST); } else { if(leadVehicleVelocity > vehicle.vFront) {//Vehicle in front drives faster than set speed. if((DESIRED_TIME_BETWEEN_VEHICLES - MAXIMUM_DEVIATION) > actualTimeBetweenVehicles && MINIMUM_TIME_BETWEEN_VEHICLES < actualTimeBetweenVehicles) {//Vehicle in front is too close to cruise but not close enought to brake. (Zone D) slowDown(MOTOR_POWER_ADJUST); } else { //(Zone C) maintainDistance(); } } else //Vehicle in front drives slower than set speed. { if((DESIRED_TIME_BETWEEN_VEHICLES + MAXIMUM_DEVIATION) >= actualTimeBetweenVehicles && (DESIRED_TIME_BETWEEN_VEHICLES - MAXIMUM_DEVIATION) <= actualTimeBetweenVehicles) {//Within tolerance. (Zone C) maintainDistance(); } else {//(Zone B) speedUp(MOTOR_POWER_ADJUST); } } acc.firstDistanceMeasurement = acc.secondDistanceMeasurement; } }
//_____________________________________ // Read user input and act on it bool controlMode( char ch ) { static int arg = -1; int retval = false; if (isdigit( ch )) { if (arg < 0) arg = 0; arg = arg * 10 + (ch - '0'); return false; } switch ( ch ) { // 'N' triggers the NTP protocol manually case 'N': case 'n': triggerNtp() ; retval = true ; break ; // Left-arrow (Less-Than) slows down the clock for simulation runs case '<': case ',': slowDown() ; retval = true ; break ; // Right-arrow (Greater-Than) speeds up the clock for simulation runs case '>': case '.': speedUp() ; retval = true ; break ; // PLUS advances the digital clock minute case '+': case '=': incMinutes() ; retval = true ; break ; // MINUS decrements the digital clock minute case '_': case '-': decMinutes() ; retval = true ; break ; // H, M, S set hours, minutes, seconds case 'H': case 'h': if (arg >= 0) setHours(arg); retval = true ; break ; case 'M': case 'm': if (arg >= 0) setMinutes(arg); retval = true ; break ; case 'S': case 's': if (arg >= 0) setSeconds(arg); syncTime() ; retval = true ; break ; // 'Z' resets the digital clock seconds case 'z': case 'Z': setSeconds(0) ; syncTime() ; return true ; // A, B and C manually force the A/B output pulses but do not affect the internal clock // A and B add to the force count for the A and B signals. C adds to both signals. case 'A': case 'a': if (arg < 0) arg = 1 ; sendPulsesA(arg) ; break ; case 'B': case 'b': if (arg < 0) arg = 1 ; sendPulsesB(arg) ; break ; case 'C': case 'c': if (arg < 0) arg = 1 ; sendPulsesA(arg) ; sendPulsesB(arg) ; break ; case 'D': case 'd': if (arg < 0) arg = 1 ; sendPulsesD(arg) ; break ; case 'E': case 'e': sendPulsesE(1) ; break ; case 'f': setState(LOW); break ; case 'F': setState(HIGH); break ; case 'I': case 'i': if (arg < 0) arg = 60*60; clockHold(arg, arg) ; break ; case 'U': case 'u': if (arg < 0) arg = 60*60; clockHold(arg, 0) ; break ; case 'V': case 'v': if (arg < 0) arg = 60*60; clockHold(0, arg) ; break ; default: break; } arg = -1; return retval ; }
Ant::Ant(double x, double y, double s, double start_angle) : Bug(x, y, s, 5 * s * s, s * s, start_angle, 2 + s / 2, CRAWL, "ant") { QImage tmp[3]; tmp[0] = QImage("./sprites/insects/fourmi1.png", "png"); tmp[1] = QImage("./sprites/insects/fourmi2.png", "png"); tmp[2] = QImage("./sprites/insects/fourmi3.png", "png"); int tsize = BASE_SIZE * size; image[0] = new QImage(tmp[0].scaled(tsize, tsize, Qt::KeepAspectRatio)); image[1] = new QImage(tmp[1].scaled(tsize, tsize, Qt::KeepAspectRatio)); image[2] = new QImage(tmp[2].scaled(tsize, tsize, Qt::KeepAspectRatio)); timer = new QTimer(); timer->setSingleShot(true); timer->setInterval(5000); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(slowDown())); }
/********************************************************** Name: runGreedyAlgorithm() Description: Finds the least amount of coins needed by starting with the largest coin value and progressing to the smallest coin value. It will calculate: 1) # of each coin used 2) Total # of coins used. **********************************************************/ int runGreedyAlgorithm(int v[], int a, int *c, int *m, int length) { int value = a, tempValue = 0, n = 1; *m = 0; //Set # of coins to zero while(value > 0 && (length - n) >= 0) { slowDown(); //slowing down the function so I can track its time. tempValue = value - v[length-n]; if (tempValue >= 0) { value = tempValue; c[length-n] = c[length-n]+1; //increment count array for coin used *m = *m+1; //increment number of coins used. /* FOR TESTING ONLY printf("Coin Used = %d\n", v[length-n]); printf("New Value: %d\n", value); printf("Total Coins Used: %d\n", *m); */ } else { n++; } } /*print out c test for(int x = 0; x < length; x++) { printf("c[%d] = %d; ", x, c[x]); } */ return 0; }
void Tram::run() { for(;;) { pthread_mutex_lock(&m_mutexTram); if(m_state != Tram::OutOfOrder) obstacleTracking(); if(m_nbTick == m_velocity - 1) { this->m_nbTick = ++m_nbTick % m_velocity; switch(m_state) { case Tram::Acceleration: speedUp(); move(); break; case Tram::OutOfOrder: m_velocity = VITESSE_MIN; break; case Tram::Desceleration: slowDown(); if(m_obstacle != NULL) { if(m_obstacle->place() == m_trip->next(m_coordinate)) { m_velocity = VITESSE_MIN; m_state = Tram::Off; sendIsStoped(); } else move(); } break; case Tram::On: move(); break; case Tram::Off: m_velocity = VITESSE_MIN; break; } } } }