/**
   Updates the accel bias raw values
 */
void LevelCalibrationModel::getSample(UAVObject *obj)
{
    QMutexLocker lock(&sensorsUpdateLock);

    switch (obj->getObjID()) {
    case AttitudeState::OBJID:
    {
        AttitudeState::DataFields attitudeStateData = attitudeState->getData();
        rot_accum_roll.append(attitudeStateData.Roll);
        rot_accum_pitch.append(attitudeStateData.Pitch);
        break;
    }
    default:
        Q_ASSERT(0);
    }

    // Work out the progress based on whichever has less
    double p1 = (double)rot_accum_roll.size() / (double)LEVEL_SAMPLES;
    progressChanged(p1 * 100);

    if (rot_accum_roll.size() >= LEVEL_SAMPLES &&
        collectingData == true) {
        collectingData = false;

        AttitudeState *attitudeState = AttitudeState::GetInstance(getObjectManager());

        disconnect(attitudeState, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(getSample(UAVObject *)));

        position++;
        switch (position) {
        case 1:
            rot_data_pitch = OpenPilot::CalibrationUtils::listMean(rot_accum_pitch);
            rot_data_roll  = OpenPilot::CalibrationUtils::listMean(rot_accum_roll);

            displayInstructions(tr("Leave horizontally, rotate 180° along yaw axis and press Save Position..."), WizardModel::Prompt);
            displayVisualHelp(CALIBRATION_HELPER_PLANE_PREFIX + CALIBRATION_HELPER_IMAGE_SWD);

            savePositionEnabledChanged(true);
            break;
        case 2:
            rot_data_pitch += OpenPilot::CalibrationUtils::listMean(rot_accum_pitch);
            rot_data_pitch /= 2;
            rot_data_roll  += OpenPilot::CalibrationUtils::listMean(rot_accum_roll);
            rot_data_roll  /= 2;

            attitudeState->setMetadata(memento.attitudeStateMdata);

            m_dirty = true;

            stopped();
            displayVisualHelp(CALIBRATION_HELPER_IMAGE_EMPTY);
            displayInstructions(tr("Board level calibration completed successfully."), WizardModel::Success);
            break;
        }
    }
Exemple #2
0
 int main(void)
 {
         int base, exp, answer;


         displayInstructions();
         printf("Enter base : ");
         scanf("%d", &base);
         printf("Enter exponent : ");
         scanf("%d", &exp);

         answer = power(base, exp);

         printf("%d^%d = %d\n", base, exp, answer);
displayInstructions();
         return 0;
 }
// main task
task main ()
{
  int _dirDC = 0;
  int _dirAC = 0;
	int dcS1, dcS2, dcS3, dcS4, dcS5 = 0;
	int acS1, acS2, acS3, acS4, acS5 = 0;
	string tmpString;

  // show the user what to do
  displayInstructions();

  eraseDisplay();
  for (int i = 0; i < 8; ++i)
    sTextLines[i] = "";

  // display the current DSP mode
  // When connected to a SMUX, the IR Seeker V2 can only be
  // used in 1200Hz mode.
  nxtDisplayTextLine(0, "      DC  1200");

  // The sensor is connected to the first port
  // of the SMUX which is connected to the NXT port S1.
  // To access that sensor, we must use msensor_S1_1.  If the sensor
  // were connected to 3rd port of the SMUX connected to the NXT port S4,
  // we would use msensor_S4_3

  while (true)
  {
    // Read the current non modulated signal direction
    _dirDC = HTIRS2readDCDir(HTIRS2);
    if (_dirDC < 0)
      break; // I2C read error occurred

    // read the current modulated signal direction
    _dirAC = HTIRS2readACDir(HTIRS2);
    if (_dirAC < 0)
      break; // I2C read error occurred

    // Read the individual signal strengths of the internal sensors
    // Do this for both unmodulated (DC) and modulated signals (AC)
    if (!HTIRS2readAllDCStrength(HTIRS2, dcS1, dcS2, dcS3, dcS4, dcS5))
      break; // I2C read error occurred
    if (!HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 ))
      break; // I2C read error occurred

      displayText(1, "D", _dirDC, _dirAC);
      displayText(2, "0", dcS1, acS1);
      displayText(3, "1", dcS2, acS2);
      displayText(4, "2", dcS3, acS3);
      displayText(5, "3", dcS4, acS4);
      displayText(6, "4", dcS5, acS5);
    if (HTSMUXreadPowerStatus(HTSMUX))
      nxtDisplayTextLine(7, "Batt: bad");
    else
      nxtDisplayTextLine(7, "Batt: good");
  }
}
void GyroBiasCalibrationModel::start()
{
    // reset dirty state to forget previous unsaved runs
    m_dirty = false;

    // configure board for calibration
    RevoCalibration::DataFields revoCalibrationData = revoCalibration->getData();
    memento.revoCalibrationData = revoCalibrationData;
    revoCalibrationData.BiasCorrectedRaw = RevoCalibration::BIASCORRECTEDRAW_FALSE;
    revoCalibration->setData(revoCalibrationData);

    AttitudeSettings::DataFields attitudeSettingsData = attitudeSettings->getData();
    memento.attitudeSettingsData = attitudeSettingsData;
    // Disable gyro bias correction while calibrating
    attitudeSettingsData.BiasCorrectGyro = AttitudeSettings::BIASCORRECTGYRO_FALSE;
    // Zero board rotation
    attitudeSettingsData.BoardRotation[AttitudeSettings::BOARDROTATION_YAW]   = 0;
    attitudeSettingsData.BoardRotation[AttitudeSettings::BOARDROTATION_ROLL]  = 0;
    attitudeSettingsData.BoardRotation[AttitudeSettings::BOARDROTATION_PITCH] = 0;
    attitudeSettings->setData(attitudeSettingsData);

    UAVObject::Metadata gyroStateMetadata = gyroState->getMetadata();
    memento.gyroStateMetadata = gyroStateMetadata;
    UAVObject::SetFlightTelemetryUpdateMode(gyroStateMetadata, UAVObject::UPDATEMODE_PERIODIC);
    gyroStateMetadata.flightTelemetryUpdatePeriod = 100;
    gyroState->setMetadata(gyroStateMetadata);

    UAVObject::Metadata gyroSensorMetadata = gyroSensor->getMetadata();
    memento.gyroSensorMetadata = gyroSensorMetadata;
    UAVObject::SetFlightTelemetryUpdateMode(gyroSensorMetadata, UAVObject::UPDATEMODE_PERIODIC);
    gyroSensorMetadata.flightTelemetryUpdatePeriod = 100;
    gyroSensor->setMetadata(gyroSensorMetadata);

    gyro_accum_x.clear();
    gyro_accum_y.clear();
    gyro_accum_z.clear();

    gyro_state_accum_x.clear();
    gyro_state_accum_y.clear();
    gyro_state_accum_z.clear();

    started();
    progressChanged(0);
    displayVisualHelp(CALIBRATION_HELPER_PLANE_PREFIX + CALIBRATION_HELPER_IMAGE_NED);
    displayInstructions(tr("Calibrating the gyroscopes. Keep the vehicle steady..."));

    // Now connect to the accels and mag updates, gather for 100 samples
    collectingData = true;
    connect(gyroState, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(getSample(UAVObject *)));
    connect(gyroSensor, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(getSample(UAVObject *)));
}
void LevelCalibrationModel::savePosition()
{
    QMutexLocker lock(&sensorsUpdateLock);

    savePositionEnabledChanged(false);

    rot_accum_pitch.clear();
    rot_accum_roll.clear();

    collectingData = true;

    connect(attitudeState, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(getSample(UAVObject *)));

    displayInstructions(tr("Hold..."));
}
/**
   Updates the gyro bias raw values
 */
void GyroBiasCalibrationModel::getSample(UAVObject *obj)
{
    QMutexLocker lock(&sensorsUpdateLock);

    switch (obj->getObjID()) {
    case GyroState::OBJID:
    {
        GyroState::DataFields gyroStateData = gyroState->getData();
        gyro_state_accum_x.append(gyroStateData.x);
        gyro_state_accum_y.append(gyroStateData.y);
        gyro_state_accum_z.append(gyroStateData.z);
        break;
    }
    case GyroSensor::OBJID:
    {
        GyroSensor::DataFields gyroSensorData = gyroSensor->getData();
        gyro_accum_x.append(gyroSensorData.x);
        gyro_accum_y.append(gyroSensorData.y);
        gyro_accum_z.append(gyroSensorData.z);
        break;
    }
    default:
        Q_ASSERT(0);
    }

    // Work out the progress based on whichever has less
    double p1 = (double)gyro_state_accum_x.size() / (double)LEVEL_SAMPLES;
    double p2 = (double)gyro_accum_y.size() / (double)LEVEL_SAMPLES;
    progressChanged(((p1 > p2) ? p1 : p2) * 100);

    if ((gyro_accum_y.size() >= LEVEL_SAMPLES || (gyro_accum_y.size() == 0 && gyro_state_accum_y.size() >= LEVEL_SAMPLES)) &&
        collectingData == true) {
        collectingData = false;
        m_dirty = true;

        disconnect(gyroSensor, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(getSample(UAVObject *)));
        disconnect(gyroState, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(getSample(UAVObject *)));

        gyroState->setMetadata(memento.gyroStateMetadata);
        gyroSensor->setMetadata(memento.gyroSensorMetadata);
        revoCalibration->setData(memento.revoCalibrationData);
        attitudeSettings->setData(memento.attitudeSettingsData);

        stopped();
        displayInstructions(tr("Gyroscope calibration completed successfully."), WizardModel::Success);
        displayVisualHelp(CALIBRATION_HELPER_IMAGE_EMPTY);
    }
/**
 * Starts an accelerometer bias calibration.
 */
void LevelCalibrationModel::start()
{
    memento.attitudeStateMdata = attitudeState->getMetadata();
    UAVObject::Metadata mdata = attitudeState->getMetadata();
    UAVObject::SetFlightTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_PERIODIC);
    mdata.flightTelemetryUpdatePeriod = 100;
    attitudeState->setMetadata(mdata);

    rot_data_pitch = 0;
    rot_data_roll  = 0;

    // reset dirty state to forget previous unsaved runs
    m_dirty  = false;

    position = 0;

    started();

    // Show instructions and enable controls
    progressChanged(0);
    displayInstructions(tr("Place horizontally and press Save Position..."), WizardModel::Prompt);
    displayVisualHelp(CALIBRATION_HELPER_PLANE_PREFIX + CALIBRATION_HELPER_IMAGE_NED);
    savePositionEnabledChanged(true);
}
// main task
task main ()
{
  int _dirDC = 0;
  int _dirAC = 0;
	int dcS1, dcS2, dcS3, dcS4, dcS5 = 0;
	int acS1, acS2, acS3, acS4, acS5 = 0;

  // show the user what to do
  displayInstructions();

  while(true)
  {
    PlaySound(soundBeepBeep);
    while(bSoundActive)
    {}
    eraseDisplay();
    nNumbCyles = 0;
    ++nInits;
    while (true)
    {
      if ((nNumbCyles & 0x04) == 0)
        nxtDisplayTextLine(0, "Initializing...");
      else
        nxtDisplayTextLine(0, "");
      nxtDisplayCenteredBigTextLine(1, "SMUX");

			// Before using the SMUX, you need to initialise the driver
			HTSMUXinit();

			// Tell the SMUX to scan its ports for connected sensors
			if (HTSMUXscanPorts(HTSMUX))
			  break;

      ++nNumbCyles;
      PlaySound(soundShortBlip);
      nxtDisplayTextLine(4, "Inits: %d / %d", nInits, nNumbCyles);
      nxtDisplayCenteredTextLine(6, "Connect SMUX");
      nxtDisplayCenteredTextLine(7, "to Port S1");
      wait1Msec(100);
    }

    eraseDisplay();
    for (int i = 0; i < 8; ++i)
      sTextLines[i] = "";

    // display the current DSP mode
    // When connected to a SMUX, the IR Seeker V2 can only be
    // used in 1200Hz mode.
    nxtDisplayTextLine(0, "      DC  1200");

	  // The sensor is connected to the first port
	  // of the SMUX which is connected to the NXT port S1.
	  // To access that sensor, we must use msensor_S1_1.  If the sensor
	  // were connected to 3rd port of the SMUX connected to the NXT port S4,
	  // we would use msensor_S4_3

    while (true)
    {
      // Read the current non modulated signal direction
      _dirDC = HTIRS2readDCDir(msensor_S1_1);
      if (_dirDC < 0)
        break; // I2C read error occurred

      // read the current modulated signal direction
      _dirAC = HTIRS2readACDir(msensor_S1_1);
      if (_dirAC < 0)
        break; // I2C read error occurred

      // Read the individual signal strengths of the internal sensors
      // Do this for both unmodulated (DC) and modulated signals (AC)
      if (!HTIRS2readAllDCStrength(msensor_S1_1, dcS1, dcS2, dcS3, dcS4, dcS5))
        break; // I2C read error occurred
      if (!HTIRS2readAllACStrength(msensor_S1_1, acS1, acS2, acS3, acS4, acS5 ))
        break; // I2C read error occurred

      displayText(1, "D", _dirDC, _dirAC);
      displayText(2, "0", dcS1, acS1);
      displayText(3, "1", dcS2, acS2);
      displayText(4, "2", dcS3, acS3);
      displayText(5, "3", dcS4, acS4);
      displayText(6, "4", dcS5, acS5);
      if (HTSMUXreadPowerStatus(HTSMUX))
        nxtDisplayTextLine(7, "Batt: bad");
      else
        nxtDisplayTextLine(7, "Batt: good");
    }
  }
}
Exemple #9
0
void
GPIOFIntHandler(void){
	// Method for handling multiple functions for a select button press

	// Clear the GPIO interrupt
	GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1);

	// Disable Interrupts
	GPIOPinIntDisable(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinIntDisable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	// Check which state we are in
	if (state==0){
		// This state handles the main menu

		if (pointer==0){
			// Begin Classic Mode
			state = 1;
			startClassic();
		}
		else if (pointer==1){
			// Begin Continuous Mode
			state = 3;
			startClassic();
		}
		else if (pointer==2){
			// Show the instructions
			state = 2;
			RIT128x96x4Clear();
			displayInstructions();
			done = 1;
		}
		else if (pointer==3){
			// Show the high scores
			state = 2;
			RIT128x96x4Clear();
			displayScores();
			done = 1;
		}
		else if (pointer==4){
			state = 0;
			initMain();
		}
	}
	else if (state==1){
		// This state handles classic mode

		// Black out the letter that was selected
		int idx = position + position2;
		int pos = 0;
		char *puc_letter = alpha[idx];
		if (idx>12){
			pos = position2 * 10;
			RIT128x96x4StringDraw(puc_letter, pos, 87, 2);
		}
		else {
			pos = position * 10;
			RIT128x96x4StringDraw(puc_letter, pos, 75, 2);
		}

		// Add the letter to the list of selected letters
		int i;
		int wrong = 1;
		int used = 0;
		// Loop through the list until we find an empty spot to place the letter
		for (i=0; i<26; i++){
			if (strcmp(selected[i],"!")==0){
				selected[i] = puc_letter;
				break;
			}
			if (strcmp(selected[i],puc_letter)==0){
				wrong = 0;
				used = 1;
				break;
			}
		}

		// Check to see if the letter was already used
		if (!used){
			// Check the word to see if a letter matches the one selected. If it
			// does, we need to display the letters instead of an underscore
			for (i=0; i<strlen(words[wotd]); i++){
				char w_let = words[wotd][i];
				static char g[3];
				usprintf(g, "%d", w_let);
				char p_let = *puc_letter;
				if (w_let==p_let){
					wrong = 0;
					// Display the letter selected
					RIT128x96x4StringDraw(puc_letter, 10+i*10, 53, 15);
					correct++;
				}
			}
		}

		// Check to see if it was a wrong selection
		if (wrong==1){
			// Increment the number of wrong attempts
			try++;
			// If the selection was wrong, we need to draw a piece of the hangman
			if (try==1){
				drawHead();
			}
			else if (try==2){
				drawBody();
			}
			else if (try==3){
				drawRightArm();
			}
			else if (try==4){
// main task
task main ()
{
  int _dirDC = 0;
  int _dirAC = 0;
	int dcS1, dcS2, dcS3, dcS4, dcS5 = 0;
	int acS1, acS2, acS3, acS4, acS5 = 0;

	// the default DSP mode is 1200 Hz.
  tHTIRS2DSPMode _mode = DSP_1200;

  // show the user what to do
  displayInstructions();

  while(true)
  {
    // You can switch between the two different DSP modes by pressing the
    // orange enter button

    PlaySound(soundBeepBeep);
    while(bSoundActive)
    {}
    eraseDisplay();
    nNumbCyles = 0;
    ++nInits;
    while (true)
    {
      if ((nNumbCyles & 0x04) == 0)
        nxtDisplayTextLine(0, "Initializing...");
      else
        nxtDisplayTextLine(0, "");
      nxtDisplayCenteredBigTextLine(1, "IR Seekr");

      // set the DSP to the new mode
      if (HTIRS2setDSPMode(HTIRS2, _mode))
        break; // Sensor initialized

      ++nNumbCyles;
      PlaySound(soundShortBlip);
      nxtDisplayTextLine(4, "Inits: %d / %d", nInits, nNumbCyles);
      nxtDisplayCenteredTextLine(6, "Connect Sensor");
      nxtDisplayCenteredTextLine(7, "to Port S1");
      wait1Msec(100);
    }

    eraseDisplay();
    for (int i = 0; i < 8; ++i)
      sTextLines[i] = "";

    // display the current DSP mode
    if (_mode == DSP_1200)
      nxtDisplayTextLine(0, "      DC  1200");
    else
      nxtDisplayTextLine(0, "      DC   600");

    while (true)
    {
      ++nNumbCyles;
      if (nNxtButtonPressed == kEnterButton)
      {
        // "Enter" button has been pressed. Need to switch mode

        _mode = (_mode == DSP_1200) ?  DSP_600 : DSP_1200;
        while(nNxtButtonPressed == kEnterButton)
        {
          // Wait for "Enter" button release
        }
        break;
      }

      // Read the current non modulated signal direction
      _dirDC = HTIRS2readDCDir(HTIRS2);
      if (_dirDC < 0)
        break; // I2C read error occurred

      // read the current modulated signal direction
      _dirAC = HTIRS2readACDir(HTIRS2);
      if (_dirAC < 0)
        break; // I2C read error occurred

      // Read the individual signal strengths of the internal sensors
      // Do this for both unmodulated (DC) and modulated signals (AC)
      if (!HTIRS2readAllDCStrength(HTIRS2, dcS1, dcS2, dcS3, dcS4, dcS5))
        break; // I2C read error occurred
      if (!HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 ))
        break; // I2C read error occurred

      displayText(1, "D", _dirDC, _dirAC);
      displayText(2, "0", dcS1, acS1);
      displayText(3, "1", dcS2, acS2);
      displayText(4, "2", dcS3, acS3);
      displayText(5, "3", dcS4, acS4);
      displayText(6, "4", dcS5, acS5);
      nxtDisplayTextLine(7, "Enter to switch");
    }
  }
}
Exemple #11
0
int main(){
	struct Player player[8];
	struct Player winner;
	int  playerCount = 0, score, highScore = 500, game = 0;
	char userInput, highName = NULL;
	printf("\nWelcome to CHECKOUT\n");
Menu:
	printf("\n\nMain Menu\n\n");
	printf("p - (p)lay q - (q)uit r - inst(r)uctions s - HI(s)core: ");
	userInput = getValidCharacter('p', 's');
	if (userInput == 'p'){
		int i = 0, boardSize;
		printf("Enter Number of Players:");
		playerCount = getValidItenger(1, 8);
		for (i = 0; i < playerCount; i++){													 //plares[i].id
			if (player[i].id != NULL){
				initPlayer(&player[i]);
			}
		}
        printf("Enter board size: ");
		boardSize = getValidItenger(5, 15);
		playGame(boardSize, player, playerCount);

		score = checkout(player);
		
		int p;
		for (i = 0; i<playerCount; ++i)                                                 /* Loop to store largest number to arr[0] */
		{
			if (score == player[i].playerScore){                                        /* Change < to > if you want to find smallest element*/
				p = i;
			}


		}
		winner.id = player[p].id;
		strcpy(winner.playerName, player[p].playerName);
		winner.playerScore = player[p].playerScore;
		printf("Congratulations %s (%c)!You win!", winner.playerName, winner.id);
		addToLeaderboard(game, &winner);
		goto Menu;


	}
	else if (userInput == 's'){
		displayHighestScore();
		goto Menu;
	}
	else if (userInput == 'r'){
		displayInstructions();

		main();
	}
	//Quit

	else if (userInput == 'q'){
		printf("This game is much more fun than bash...");
	}
	else{
		printf("INVALID!");
	}
	return 0;
}
// main task
 task main ()
 {
  int last = 0;
  int stage = 1;
  int _dirDC = 0;
  int _dirAC = 0;
  int dcS1, dcS2, dcS3, dcS4, dcS5 = 0;
  int acS1, acS2, acS3, acS4, acS5 = 0;

        // the default DSP mode is 1200 Hz.
  tHTIRS2DSPMode _mode = DSP_1200;

  // show the user what to do
  displayInstructions();
  while(true)
  {
    // You can switch between the two different DSP modes by pressing the
    // orange enter button

    PlaySound(soundBeepBeep);
    while(bSoundActive)
    {}
  eraseDisplay();
  nNumbCyles = 0;
  ++nInits;
  while (true)
  {
    if ((nNumbCyles & 0x04) == 0)
      nxtDisplayTextLine(0, "Initializing...");
    else
      nxtDisplayTextLine(0, "");
    nxtDisplayCenteredBigTextLine(1, "IR Seekr");

      // set the DSP to the new mode
    if (HTIRS2setDSPMode(HTIRS2, _mode))
        break; // Sensor initialized

      ++nNumbCyles;
      PlaySound(soundShortBlip);
      nxtDisplayTextLine(4, "Inits: %d / %d", nInits, nNumbCyles);
      nxtDisplayCenteredTextLine(6, "Connect Sensor");
      nxtDisplayCenteredTextLine(7, "to Port S2");
      wait1Msec(100);
    }

    eraseDisplay();
    for (int i = 0; i < 8; ++i)
      sTextLines[i] = "";

    // display the current DSP mode
    if (_mode == DSP_1200)
      nxtDisplayTextLine(0, "      DC  1200");
    else
      nxtDisplayTextLine(0, "      DC   600");

    while (true)
    {
      ++nNumbCyles;
      if (nNxtButtonPressed == kEnterButton)
      {
        // "Enter" button has been pressed. Need to switch mode

        _mode = (_mode == DSP_1200) ?  DSP_600 : DSP_1200;
        while(nNxtButtonPressed == kEnterButton)
        {
          // Wait for "Enter" button release
        }
        break;
      }


      // Read the current non modulated signal direction
      _dirDC = HTIRS2readDCDir(HTIRS2);
      if (_dirDC < 0)
        break; // I2C read error occurred

      // read the current modulated signal direction
      _dirAC = HTIRS2readACDir(HTIRS2);
      if (_dirAC < 0)
        break; // I2C read error occurred

      // Read the individual signal strengths of the internal sensors
      // Do this for both unmodulated (DC) and modulated signals (AC)
      if (!HTIRS2readAllDCStrength(HTIRS2, dcS1, dcS2, dcS3, dcS4, dcS5))
        break; // I2C read error occurred
      if (!HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 ))
        break; // I2C read error occurred

      displayText(1, "D", _dirDC, _dirAC);
      displayText(2, "0", dcS1, acS1);
      displayText(3, "1", dcS2, acS2);
      displayText(4, "2", dcS3, acS3);
      displayText(5, "3", dcS4, acS4);
      displayText(6, "4", dcS5, acS5);
      //displayText(7, "Last", dcS5, acS5);
      //nxtDisplayTextLine(7, "Last: "+last);
      /*
      if(acS3 >= 50){
        int speed = 20;
        motor[DFR] = -speed;
        motor[DFL]= -speed;
        motor[DBR] = -speed;
        motor[DBL]= -speed;
      }
      else if(acS4+acS5 >= 10){
        //Right
        int speed = 20;
        motor[DFR] = speed;
        motor[DFL]= -speed;
        motor[DBR] = speed;
        motor[DBL]= -speed;
      }
      else if(acS1+acS2 >= 10){
        //Left
        int speed = 20;
        motor[DFR] = -speed;
        motor[DFL]= speed;
        motor[DBR] = -speed;
        motor[DBL]= speed;
      }
      else{
        motor[DFR] = 0;
        motor[DFL]= 0;
        motor[DBR] = 0;
        motor[DBL]= 0;
      }
      */
      while(stage == 1){
      	int acS1, acS2, acS3, acS4, acS5 = 0;
      	HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 );
        if(acS1 > acS2-100&&last>10){

         motor[driveL]= motor[driveL2] = motor[driveR] = motor[driveR2] = -20;

         last = -1;
         stage = 2;
         wait1Msec(1000);
         motor[driveL]= motor[driveL2] = motor[driveR] = motor[driveR2] = 0;
       }
       else{
        if(last<acS1)
          last = acS1;
        int speed = 90-3*(acS2 + acS3);
        if (speed < 9) speed = 9;
        motor[driveL]= motor[driveL2] = motor[driveR] = motor[driveR2] = speed;
      }
    }
    while(stage == 2){
	        //Right
	        //stage_done = 1;
      HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5);
      int speed = 20-acS3;
      if(speed < 9) speed = 9;
      motor[DFR] = -speed;
      motor[DFL]= speed;
      motor[DBR] = -speed;
      motor[DBL]= speed;

      if(acS3>last)
       last = acS3;
     if(last-acS3 > 1&&last!=0){

      motor[DFR] = 0;
      motor[DFL]= 0;
      motor[DBR] = 0;
      motor[DBL]= 0;
      stage = 3;
      wait1Msec(1000);
    }
       // nxtDisplayTextLine(0, "Last: "+last);
       // nxtDisplayTextLine(1, "acS3: "+dcS3);
    wait1Msec(500);

  }
}
}
}
/**
 * Called by the "Start" button.  Sets up the meta data and enables the
 * buttons to perform six point calibration of the magnetometer (optionally
 * accel) to compute the scale and bias of this sensor based on the current
 * home location magnetic strength.
 */
void SixPointCalibrationModel::start(bool calibrateAccel, bool calibrateMag)
{
    calibratingAccel = calibrateAccel;
    calibratingMag   = calibrateMag;

    started();

    // check if Homelocation is set
    HomeLocation::DataFields homeLocationData = homeLocation->getData();
    if (!homeLocationData.Set) {
        displayInstructions(tr("Home location not set, please set your home location and retry."), WizardModel::Warn);
        displayInstructions(tr("Aborting calibration!"), WizardModel::Failure);
        stopped();
        return;
    }

    // Store and reset board rotation before calibration starts
    storeAndClearBoardRotation();

    // Calibration accel
    AccelGyroSettings::DataFields accelGyroSettingsData = accelGyroSettings->getData();
    memento.accelGyroSettingsData = accelGyroSettingsData;

    accelGyroSettingsData.accel_scale[AccelGyroSettings::ACCEL_SCALE_X] = 1;
    accelGyroSettingsData.accel_scale[AccelGyroSettings::ACCEL_SCALE_Y] = 1;
    accelGyroSettingsData.accel_scale[AccelGyroSettings::ACCEL_SCALE_Z] = 1;
    accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_X]   = 0;
    accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_Y]   = 0;
    accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_Z]   = 0;

    accelGyroSettings->setData(accelGyroSettingsData);

    // Calibration mag
    RevoCalibration::DataFields revoCalibrationData = revoCalibration->getData();
    memento.revoCalibrationData = revoCalibrationData;

    // Reset the transformation matrix to identity
    for (int i = 0; i < RevoCalibration::MAG_TRANSFORM_R2C2; i++) {
        revoCalibrationData.mag_transform[i] = 0;
    }
    revoCalibrationData.mag_transform[RevoCalibration::MAG_TRANSFORM_R0C0] = 1;
    revoCalibrationData.mag_transform[RevoCalibration::MAG_TRANSFORM_R1C1] = 1;
    revoCalibrationData.mag_transform[RevoCalibration::MAG_TRANSFORM_R2C2] = 1;
    revoCalibrationData.mag_bias[RevoCalibration::MAG_BIAS_X] = 0;
    revoCalibrationData.mag_bias[RevoCalibration::MAG_BIAS_Y] = 0;
    revoCalibrationData.mag_bias[RevoCalibration::MAG_BIAS_Z] = 0;

    // Disable adaptive mag nulling
    revoCalibrationData.MagBiasNullingRate = 0;

    revoCalibration->setData(revoCalibrationData);

    // Calibration AuxMag
    AuxMagSettings::DataFields auxMagSettingsData = auxMagSettings->getData();
    memento.auxMagSettings = auxMagSettingsData;

    // Reset the transformation matrix to identity
    for (int i = 0; i < AuxMagSettings::MAG_TRANSFORM_R2C2; i++) {
        auxMagSettingsData.mag_transform[i] = 0;
    }
    auxMagSettingsData.mag_transform[AuxMagSettings::MAG_TRANSFORM_R0C0] = 1;
    auxMagSettingsData.mag_transform[AuxMagSettings::MAG_TRANSFORM_R1C1] = 1;
    auxMagSettingsData.mag_transform[AuxMagSettings::MAG_TRANSFORM_R2C2] = 1;
    auxMagSettingsData.mag_bias[AuxMagSettings::MAG_BIAS_X] = 0;
    auxMagSettingsData.mag_bias[AuxMagSettings::MAG_BIAS_Y] = 0;
    auxMagSettingsData.mag_bias[AuxMagSettings::MAG_BIAS_Z] = 0;

    // Disable adaptive mag nulling
    auxMagSettingsData.MagBiasNullingRate = 0;

    auxMagSettings->setData(auxMagSettingsData);

    QThread::usleep(100000);

    mag_accum_x.clear();
    mag_accum_y.clear();
    mag_accum_z.clear();

    mag_fit_x.clear();
    mag_fit_y.clear();
    mag_fit_z.clear();

    // Need to get as many accel updates as possible
    memento.accelStateMetadata = accelState->getMetadata();
    if (calibrateAccel) {
        UAVObject::Metadata mdata = accelState->getMetadata();
        UAVObject::SetFlightTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_PERIODIC);
        mdata.flightTelemetryUpdatePeriod = 100;
        accelState->setMetadata(mdata);
    }

    // Need to get as many mag updates as possible
    memento.magSensorMetadata    = magSensor->getMetadata();
    memento.auxMagSensorMetadata = auxMagSensor->getMetadata();

    if (calibrateMag) {
        UAVObject::Metadata mdata = magSensor->getMetadata();
        UAVObject::SetFlightTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_PERIODIC);
        mdata.flightTelemetryUpdatePeriod = 100;
        magSensor->setMetadata(mdata);

        mdata = auxMagSensor->getMetadata();
        UAVObject::SetFlightTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_PERIODIC);
        mdata.flightTelemetryUpdatePeriod = 100;
        auxMagSensor->setMetadata(mdata);
    }

    // reset dirty state to forget previous unsaved runs
    m_dirty = false;

    if (calibrateMag) {
        currentSteps = &calibrationStepsMag;
    } else {
        currentSteps = &calibrationStepsAccelOnly;
    }

    position = 0;

    // Show instructions and enable controls
    progressChanged(0);
    displayInstructions((*currentSteps)[0].instructions, WizardModel::Prompt);
    showHelp((*currentSteps)[0].visualHelp);
    savePositionEnabledChanged(true);
}
Exemple #14
0
void main ()
{
#ifndef GUSSOUND_STANDALONE
  guslib::AppRestarter::getPtr ()->setRestartParameter ("--restart");

  if( guslib::AppRestarter::getPtr()->restartProcessStarted() )
  {
    guslib::AppRestarter::getPtr()->waitForPreviousProcessToFinish();
  }

  GSTARTTRACING ("zsndtrace.txt", 10);
#endif
  try
  {
#ifndef GUSSOUND_STANDALONE
    SoundManagerFactory::getPtr ()->Register ("audiere", GAudiere::AudiereManagerUtil::createSoundManager);
#endif
    SoundManagerFactory::getPtr ()->Register ("openal", GOpenAl::OpenAlManagerUtil::createSoundManager);

    SoundManager::setPtr (SoundManagerFactory::getPtr ()->CreateObject ("openal"));
    //SoundManager::setPtr (SoundManagerFactory::getPtr ()->CreateObject ("audiere"));

#ifndef GUSSOUND_STANDALONE
    GTRACE (3, "Starting Sound Manager version: " << SoundManager::getPtr ()->getVersion ());
#endif
    SoundManager::getPtr ()->getMusicPlayer ()->setFadeDuration (2500);
    SoundManager::getPtr ()->getMusicPlayer ()->setRepeat (true);

    // make sure the first call to elapse time won't return many seconds. 
    SoundManager::getPtr ()->elapseTime ();

    // Start adding sounds to the sound repository.
    SoundManager::getPtr ()->getRepository ()->addSound ("gus" // name
                            , "../Game/data/sounds/Mulchsound.wav" // path
                            , true // load entire sound into memory? don't do it for songs! only for small sounds.
                            , GSC_Effect); // a category for the sound; you can change the volume for all sounds in a category.

    // Play this sound immediately.
    SoundManager::getPtr ()->getRepository ()->getSound ("gus")->play2D ();

    SoundManager::getPtr ()->getRepository ()->setVolumeForCategory (GSC_Music, (SoundVolume)0.75);
    SoundManager::getPtr ()->getRepository ()->setVolumeForCategory (GSC_Voice, (SoundVolume)0.8);

    SoundManager::getPtr ()->addSoundGroup("empty group");
    try
    {
      std::string sTemp = SoundManager::getPtr ()->getSoundGroup ("empty group")->getRandomSound ();
      SoundManager::getPtr ()->getRepository ()->getSound (sTemp)->play2D ();
    }
    catch (std::exception& e)
    {
      GTRACE (2, "Caught exception: " << e.what ());
    }


    // Place some sounds together in the same group. This could be used to offer a varied response to the same action.
    // E.g. in a strategy game, select a swordsman. Sometimes he will reply with "hey", sometimes with "hello", sometimes with "hmm?"
    SoundManager::getPtr ()->addSoundGroup("swordsman selected");
    SoundManager::getPtr ()->getRepository ()->addSound ("srd_select1", "../Game/data/sounds/Mulchsound.wav", true, GSC_Voice, false);
    SoundManager::getPtr ()->getRepository ()->addSound ("srd_select2", "../Game/data/sounds/MenuSelectionClicked.wav", true, GSC_Voice, false);
    SoundManager::getPtr ()->getRepository ()->addSound ("srd_select3", "../Game/data/sounds/Huiitysound.wav", true, GSC_Voice, false);

    SoundManager::getPtr ()->getSoundGroup("swordsman selected")->addSound("srd_select1", 20); // % chance to play this: (20 * 100) / (20 + 15 + 10) = 44%
    SoundManager::getPtr ()->getSoundGroup("swordsman selected")->addSound("srd_select2", 15); // % chance to play this: (15 * 100) / (20 + 15 + 10) = 33%
    SoundManager::getPtr ()->getSoundGroup("swordsman selected")->addSound("srd_select3", 10); // % chance to play this. (10 * 100) / (20 + 15 + 10) = 22%

    SoundManager::getPtr ()->addSoundGroup("single sound selection");
    SoundManager::getPtr ()->getRepository ()->addSound ("srd_select1_single", "../Game/data/sounds/Mulchsound.wav", true, GSC_Voice, true);
    SoundManager::getPtr ()->getSoundGroup("single sound selection")->addSound("srd_select1_single", 20); // % chance to play this: (20 * 100) / (20 + 15 + 10) = 44%

    SoundManager::getPtr ()->getMusicPlayer ()->registerPlaylist ("menu");
    SoundManager::getPtr ()->getMusicPlayer ()->registerPlaylist ("game");
    
    SoundManager::getPtr ()->addPlaylistTrack ("menu", "../Game/data/music/menu/General Fuzz - Cliff Notes.ogg");

    SoundManager::getPtr ()->addPlaylistTrack ("game", "../Game/data/music/game/General Fuzz - Comfort Zone.ogg");
    SoundManager::getPtr ()->addPlaylistTrack ("game", "../Game/data/music/game/General Fuzz - Starry.ogg");
    SoundManager::getPtr ()->addPlaylistTrack ("game", "../Game/data/music/game/General Fuzz - Warm Steel.ogg");

    //SoundManager::getPtr ()->addPlaylistTrack ("game", "../Game/data/music/the_prophecy.ogg");
    //SoundManager::getPtr ()->addPlaylistTrack ("game", "../Game/data/music/Dark_Exploration_mini.ogg");
    //SoundManager::getPtr ()->addPlaylistTrack ("game", "../Game/data/music/tread_lightly_mini.ogg");
    SoundManager::getPtr ()->getMusicPlayer ()->setRepeat (true);
    //SoundManager::getPtr ()->getMusicPlayer ()->setShuffle (true);

    ((GOpenAl::OpenAlManagerUtil*)SoundManager::getPtr ())->setListenerPosition (0, 0, 0);
    SoundManager::getPtr()->getMusicPlayer()->switchToPlaylist("game");

#ifndef GUSSOUND_STANDALONE
    displayInstructions ();

    menutest ();
#endif
    SoundManager::destroy ();
  }
  catch (std::exception & e)
  {
#ifndef GUSSOUND_STANDALONE
    GTRACE (1, "ex: " << e.what ());
#endif
  }

#ifndef GUSSOUND_STANDALONE
  GTRACE (7, "ending");
  GSTOPTRACING ();

  guslib::AppRestarter::getPtr()->finishRestart();
#endif
}
Exemple #15
0
int main(int argc, char* argv[]) {
    printf("Choose your difficulty: (e)asy or (n)ormal.\n");
    char buffer[1];
    int difficulty;
    bool entered_command = false, play_again = true;
    for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
        memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
    }

    while( (buffer[0] != 'e') && (buffer[0] != 'n') ) {
        if(entered_command) {printf("Invalid Command.\n");}
        printf("> ");
        for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
            memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
        }
        fgets(buffer, 15, stdin);
        entered_command = true;
    }

    if(buffer[0] == 'e') {difficulty = 1;}
    else {difficulty = 2;}
    for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
        memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
    }
    printf("Welcome to tic-tac-toe! You'll play as 'x'.\n");
    printf("If you need to hear the rules for the game, press r and hit enter.\n");
    printf("Otherwise, press s and hit enter to start a new game.\n");
    entered_command = false;

    while( (buffer[0] != 'r') && (buffer[0] != 's') ) {
        if(entered_command) {printf("Invalid Command.\n");}
        printf("> ");
        for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
            memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
        }
        fgets(buffer, 15, stdin);
        entered_command = true;
    }

    if(buffer[0] == 'r') {
        displayRules();
        printf("Now starting game.\n");
    }

    displayInstructions();
    while(play_again) {
        beginNewGame(difficulty);
        entered_command = false;
        buffer[0] = 'i';

        while( (buffer[0] != 'y') && (buffer[0] != 'n') ) {
            if(entered_command) {printf("Invalid Command.\n");}
            printf("Play Again? (y)es/(n)o > ");
            for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
                memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
            }
            fgets(buffer, 15, stdin);
            entered_command = true;
        }
        if(buffer[0] == 'n') {play_again = false;}
    }
    return 0;
}
Exemple #16
0
void CMenu::displayMenu(void) {
    u16 position_castle(36);
    s8 l_i;
    // Reset the background system
    PA_ResetBgSys();
    // Initialize the text at the top and bottom screens
    PA_InitText(1,0);
    PA_Init16cBg(1, 1);
    //PA_Init16cBg(1, 1);
    //PA_InitCustomText(1, 0, PA_Text);
    //PA_InitText(0,0);
    PA_Init16cBg(0, 1);
    // Load the grass background at the top screen
    PA_EasyBgLoad(1, 2, grass);
    // Set the screens' brightness to white
    PA_SetBrightness(1, 31);
    PA_SetBrightness(0, 31);
    // Load the title background at the top screen
    PA_EasyBgLoad(1, 3, title);
    // Change the brightness of the top screen to neutral (fading)
    for (l_i = 31; l_i >= 0; l_i--) {
        PA_SetBrightness(1, l_i);
        PA_WaitForVBL();
        PA_WaitForVBL();
    }
    // Create the sprites for the two castles below the grass level
    PA_DualCreateSprite(SPRITE_NB_CASTLE1_PART1, (void*)topcastle_Sprite,
                        OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE,
                        69, 192-position_castle);
    PA_DualCreateSprite(SPRITE_NB_CASTLE1_PART2, (void*)castle_Sprite,
                        OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE,
                        69, 192+64-position_castle);
    PA_DualCreateSprite(SPRITE_NB_CASTLE2_PART1, (void*)topcastle_Sprite,
                        OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE,
                        151, 192-position_castle);
    PA_DualCreateSprite(SPRITE_NB_CASTLE2_PART2, (void*)castle_Sprite,
                        OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE,
                        151, 192+64-position_castle);
    // Display the castle sprites behind the grass
    PA_DualSetSpritePrio (SPRITE_NB_CASTLE1_PART1, 3);
    PA_DualSetSpritePrio (SPRITE_NB_CASTLE1_PART2, 3);
    PA_DualSetSpritePrio (SPRITE_NB_CASTLE2_PART1, 3);
    PA_DualSetSpritePrio (SPRITE_NB_CASTLE2_PART2, 3);
    // Move gradually the castle sprites above the grass
    for (position_castle = 36; position_castle <= 90; position_castle++) {
        PA_WaitForVBL();
        PA_DualSetSpriteXY(SPRITE_NB_CASTLE1_PART1, 69, 192-position_castle);
        PA_DualSetSpriteXY(SPRITE_NB_CASTLE1_PART2, 69, 192+64-position_castle);
        PA_DualSetSpriteXY(SPRITE_NB_CASTLE2_PART1, 151, 192-position_castle);
        PA_DualSetSpriteXY(SPRITE_NB_CASTLE2_PART2, 151, 192+64-position_castle);
    }
    // Display the main menu
    PA_EasyBgLoad(0, 0, menu2);
    PA_SetBrightness(0, 0);
    // Wait for a player's action
    m_itemTouched = NO_MODE;
    while ((m_itemTouched == NO_MODE) || (m_itemTouched == MODE_TWOPLAYERS) || (m_itemTouched == BACK)) {
        m_itemTouched = itemTouched();
        if (m_itemTouched == MODE_INSTRUCTIONS)
            displayInstructions();
        if (m_itemTouched == MODE_TWOPLAYERS) {
            PA_DeleteBg (0, 0);
            PA_EasyBgLoad(0, 0, hotseat_wifi);
        }
        if (m_itemTouched == BACK) {
            PA_DeleteBg (0, 0);
            PA_EasyBgLoad(0, 0, menu2);
        }
        PA_WaitForVBL();
    }
    // Delete the castle sprites
    PA_DualDeleteSprite(SPRITE_NB_CASTLE1_PART1);
    PA_DualDeleteSprite(SPRITE_NB_CASTLE1_PART2);
    PA_DualDeleteSprite(SPRITE_NB_CASTLE2_PART1);
    PA_DualDeleteSprite(SPRITE_NB_CASTLE2_PART2);
    // Load the empty bottom screen
    PA_EasyBgLoad(0, 3, bottomscreen);
    // Activate the Wifi
    if (m_itemTouched == MODE_WIFI) {
        PA_DeleteBg (0, 0);
        PA_EasyBgLoad(1, 2, opponentchoice);
        l_wifi.goToState(WIFI_STATE_ACTIVE);
        m_playerOrder = l_wifi.connection();
    }
    // Fading to white at the top screen
    for (l_i = 0; l_i <=31; l_i++) {
        PA_SetBrightness(1, l_i);
        PA_WaitForVBL();
        PA_WaitForVBL();
    }
    // Start to play the music
#ifndef DEBUG
    AS_SetMP3Loop(true);
    AS_SetMP3Volume(m_musicVolume);
    AS_MP3DirectPlay((u8*)sound9, (u32)sound9_size);
#endif
    CGame l_game;  // Main game object
    // Initialise the game object where m_itemTouched corresponds to the game mode
    l_game.initGame(m_musicVolume, m_cardSpeed, m_itemTouched, m_playerOrder);
    // Infinite loop to keep the program running
    bool finish = false;
    while(!finish) {
        // Play the game
        finish = l_game.play(&m_musicVolume, &m_cardSpeed);
        PA_WaitForVBL();
    }
    // Stop the music
#ifndef DEBUG
    AS_MP3Stop();
#endif
}