コード例 #1
0
task main() {
  short raw = 0;
  short nrm = 0;

  nNxtButtonTask  = -2;

  eraseDisplay();
  displayTextLine(0, "Dexter Industries");
  displayCenteredBigTextLine(1, "dFlex");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);

  eraseDisplay();
  displayTextLine(0, "dFlex Sensor");

  while (true) {
    displayClearTextLine(5);
    displayClearTextLine(6);

    // Get the raw value from the sensor
    raw = DFLEXvalRaw(DFLEX);

    // Get the normalised value from the sensor
    nrm = DFLEXvalNorm(DFLEX);

    displayTextLine(2, "Raw:  %4d", raw);
    displayTextLine(4, "Norm: %4d", nrm);
    sleep(50);
  }
}
コード例 #2
0
 /*
  =============================================================================
  main task with some testing code

 */
task main() {
  // Standard range is set to short range
  bool shortrange = true;
  tObstacleZone zone = MSSUMO_NONE;
  nNxtButtonTask  = -2;

  eraseDisplay();

  displayCenteredTextLine(0, "Mindsensors");
  displayCenteredBigTextLine(1, "SUMO Eyes");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Press enter to");
  displayCenteredTextLine(6, "switch between");
  displayCenteredTextLine(7, "ranges");
  sleep(2000);
  eraseDisplay();

  // Set the sensor to short range
  MSSUMOsetShortRange(HTMSSUMO);

  while(true) {
    if (time1[T1] > 1000) {
      if (shortrange == false) {
        // set the sensor to short range and display this
        MSSUMOsetShortRange(HTMSSUMO);
        displayClearTextLine(1);
        displayTextLine(1, "Short range");
        shortrange = true;
      } else {
        // set the sensor to long range and display this
        MSSUMOsetLongRange(HTMSSUMO);
        displayClearTextLine(1);
        displayTextLine(1, "Long range");
        shortrange = false;
      }
      playSound(soundBeepBeep);
      while(bSoundActive)
      time1[T1] = 0;
    }

    while(nNxtButtonPressed != kEnterButton) {
      // Read the zone data
      zone = MSSUMOreadZone(HTMSSUMO);

      switch (zone) {
        case MSSUMO_FRONT: displayCenteredBigTextLine(4, "FRONT"); break;
        case MSSUMO_LEFT:  displayCenteredBigTextLine(4, "LEFT");  break;
        case MSSUMO_RIGHT: displayCenteredBigTextLine(4, "RIGHT"); break;
        case MSSUMO_NONE:  displayCenteredBigTextLine(4, "NONE");  break;
      }
      sleep(50);
    }
  }
}
コード例 #3
0
task main () {
  short raw = 0;
  short nrm = 0;
  // Get control over the buttons
  nNxtButtonTask  = -2;

  LSsetActive(LEGOLS);
  eraseDisplay();
  displayTextLine(0, "Light Sensor Cal.");
  displayTextLine(2, "Left:  set black");
  displayTextLine(3, "Right: set white");
  displayTextLine(7, "Grey:  exit");

  while (true) {
    switch(nNxtButtonPressed) {
      // if the left button is pressed calibrate the black value for the sensor
      case kLeftButton:
                        LScalLow(LEGOLS);
                        playSound(soundBeepBeep);
                        while(bSoundActive) sleep(1);
                        break;

      // if the left button is pressed calibrate the white value for the sensor
      case kRightButton:
                        LScalHigh(LEGOLS);
                        playSound(soundBeepBeep);
                        while(bSoundActive) sleep(1);
                        break;
    }

    displayClearTextLine(5);
    displayClearTextLine(6);

    // Read the raw value of the sensor
    raw = LSvalRaw(LEGOLS);

    // Read the normalised value of the sensor
    nrm = LSvalNorm(LEGOLS);

    // Display the raw and normalised values
    displayTextLine(5, "R: %4d N: %4d", raw, nrm);

    // Display the values for black and white
    displayTextLine(6, "B: %4d W: %4d", lslow[LEGOLS * 4], lshigh[LEGOLS * 4]);
    sleep(50);
  }
}
コード例 #4
0
task main() {
  short raw = 0;
  short nrm = 0;
  bool active = true;

  // Turn the light on
  LSsetActive(LEGOLS);

  displayCenteredTextLine(0, "Lego");
  displayCenteredBigTextLine(1, "LIGHT");
  displayCenteredTextLine(3, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and sensor to");
  displayCenteredTextLine(7, "SMUX Port 1");
  sleep(2000);

  displayClearTextLine(7);
  displayTextLine(5, "Press [enter]");
  displayTextLine(6, "to toggle light");
  sleep(2000);

  while (true) {
    // The enter button has been pressed, switch
    // to the other mode
  	if (getXbuttonValue(xButtonEnter))
  	{
      active = !active;
      if (!active)
        LSsetInactive(LEGOLS);
      else
        LSsetActive(LEGOLS);

      // wait 500ms to debounce the switch
      sleep(500);
    }

    displayClearTextLine(5);
    displayClearTextLine(6);
    raw = LSvalRaw(LEGOLS);
    nrm = LSvalNorm(LEGOLS);
    displayTextLine(5, "Raw:  %4d", raw);
    displayTextLine(6, "Norm: %4d", nrm);
    sleep(50);
  }
}
コード例 #5
0
task main () {
  displayTextLine(0, "HT Gyro");
  displayTextLine(1, "Test 1");
  displayTextLine(5, "Press enter");
  displayTextLine(6, "to set relative");
  displayTextLine(7, "heading");

  sleep(2000);
  eraseDisplay();

  // Create struct to hold sensor data
  tHTGYRO gyroSensor;

  // Initialise and configure struct and port
  initSensor(&gyroSensor, S1);

  time1[T1] = 0;
  while(true) {
    if (time1[T1] > 1000) {
      eraseDisplay();
      displayTextLine(1, "Resetting");
      displayTextLine(1, "offset");
      sleep(500);

      // Start the calibration and display the offset
      sensorCalibrate(&gyroSensor);

      displayTextLine(2, "Offset: %f", gyroSensor.offset);
      playSound(soundBlip);
      while(bSoundActive) sleep(1);
      time1[T1] = 0;
    }

    while(!getXbuttonValue(xButtonEnter)) {
      eraseDisplay();

      displayTextLine(1, "Reading");

      // Read the current rotational speed
      readSensor(&gyroSensor);

      // Read the current calibration offset and display it
      displayTextLine(2, "Offset: %4f", gyroSensor.offset);

      displayClearTextLine(4);
      // Read the current rotational speed and display it
      displayTextLine(4, "Gyro:   %4f", gyroSensor.rotation);
      displayTextLine(6, "Press enter");
      displayTextLine(7, "to recalibrate");
      sleep(100);
    }
  }
}
task main () {

  displayCenteredTextLine(0, "HiTechnic");
  displayCenteredBigTextLine(1, "MAGNETIC");
  displayCenteredTextLine(3, "Field Sensor");
  displayCenteredTextLine(4, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and sensor to");
  displayCenteredTextLine(7, "SMUX Port 1");
  sleep(2000);

  eraseDisplay();
  time1[T1] = 0;
  while(true) {
    eraseDisplay();
    displayTextLine(1, "Resetting");
    displayTextLine(2, "bias");
    sleep(500);

    // Start the calibration and display the offset
    displayTextLine(2, "Bias: %4d", HTMAGstartCal(HTMAG));
    playSound(soundBlip);
    while(bSoundActive) EndTimeSlice();
    while(nNxtButtonPressed != kNoButton) EndTimeSlice();

    while(nNxtButtonPressed != kEnterButton) {
      eraseDisplay();

      displayTextLine(1, "Reading");
      // Read the current calibration offset and display it
      displayTextLine(2, "Bias: %4d", HTMAGreadCal(HTMAG));

      displayClearTextLine(4);
      // Read the current rotational speed and display it
      displayTextLine(4, "Mag:   %4d", HTMAGreadVal(HTMAG));
      displayTextLine(6, "Press enter");
      displayTextLine(7, "to recalibrate");
      sleep(100);
    }
  }
}
コード例 #7
0
task main () {
  displayCenteredTextLine(0, "HiTechnic");
  displayCenteredBigTextLine(1, "MAGNETIC");
  displayCenteredTextLine(3, "Field Sensor");
  displayCenteredTextLine(4, "SMUX Test");
  displayCenteredTextLine(5, "Connect SMUX to");
  displayCenteredTextLine(6, "S1 and sensor to");
  displayCenteredTextLine(7, "SMUX Port 1");

  sleep(2000);

  displayCenteredTextLine(5, "Press enter");
  displayCenteredTextLine(6, "to set bias");

  sleep(2000);
  eraseDisplay();

  // Create struct to hold sensor data
  tHTMAG magneticSensor;

	// 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

  // Initialise and configure struct and port
  initSensor(&magneticSensor, msensor_S1_1);

  while(true) {
    eraseDisplay();
    displayTextLine(1, "Resetting");
    displayTextLine(2, "bias");
    sleep(500);

    // Start the calibration and display the offset
    sensorCalibrate(&magneticSensor);

    displayTextLine(2, "Bias: %4d", magneticSensor.bias);
    playSound(soundBlip);
    while(bSoundActive) sleep(1);
    while(getXbuttonValue(xButtonAny)) sleep(1);

    while(!getXbuttonValue(xButtonEnter)) {
      eraseDisplay();

      // Read the sensor data
      readSensor(&magneticSensor);

      displayTextLine(1, "Reading");
      // Display the current calibration value
      displayTextLine(2, "Bias: %4d", magneticSensor.bias);

      displayClearTextLine(4);
      // Display the current magnetic field strength
      displayTextLine(4, "Mag:   %4d", magneticSensor.strength);
      displayTextLine(6, "Press enter");
      displayTextLine(7, "to recalibrate");
      sleep(100);
    }
  }
}
コード例 #8
0
task gyro_loop () {

	gyro_loop_state=INIT;
	int dt=10;
  unsigned long prevTime,currTime;
	// Create struct to hold sensor data
	tHTGYRO gyroSensor;
	while(gyro_loop_state!=STOPPED) {
		switch(gyro_loop_state)
		{
		case INIT:
			// Initialise and configure struct and port
			hogCPU();
			initSensor(&gyroSensor, S3);
			gyro_loop_state=CALIBRATION;
			releaseCPU();
			break;
		case CALIBRATION:
			sleep(1000);//let it settle down
#ifdef TESTING
			eraseDisplay();
			displayTextLine(1, "Resetting");
			displayTextLine(2, "offset");
			sleep(500);
#endif
			hogCPU();
			// Start the calibration
			sensorCalibrate(&gyroSensor);

#ifdef TESTING
			//and display the offset in testing mode
			displayTextLine(2, "Offset: %f", gyroSensor.offset);
			clearDebugStream();
			writeDebugStreamLine("Offset: %f deadband: %f",gyroSensor.offset,gyroSensor.deadband);
			playSound(soundBlip);
			while(bSoundActive) sleep(1);
#endif
			gHeading=0.0;
			prevTime =nSysTime;
			gyro_loop_state=READING;
			releaseCPU();
			break;
		case READING:
			while(gyro_loop_state==READING){
				clearTimer(T2);
				hogCPU();
				// Read the current rotational speed
				readSensor(&gyroSensor);
        currTime = nSysTime;
        gRot = gyroSensor.rotation;
        //There is a possibility that nSysTime would reach max value of 32 bit long integer
        //then wrapped around. But it would be NXT has run over 1000 hours
	      gHeading +=  gRot* (currTime-prevTime)/1000.0;
	      prevTime=currTime;
				releaseCPU();
#ifdef TESTING
				eraseDisplay();
				displayTextLine(1, "Reading");
				// Read the current calibration offset and display it
				displayTextLine(2, "Offset: %f", gyroSensor.offset);
				writeDebugStreamLine("Offset: %f deadband: %f", gyroSensor.offset, gyroSensor.deadband);

				displayClearTextLine(4);
				// Read the current rotational speed and display it
				displayTextLine(4, "Gyro:   %f", gyroSensor.rotation);
				writeDebugStreamLine("Rotation: %f",gyroSensor.rotation);

				displayTextLine(5, "Degrees: %f", gHeading);
				writeDebugStreamLine("Heading: %f",gHeading);

				displayTextLine(6, "Press enter");
				displayTextLine(7, "to recalibrate");
#endif
				while(time1[T2]<dt && gyro_loop_state==READING){
					sleep(1);
				}
			}
			break;
		default:
			//should never happen
			break;
		}
	}
}