// --------------------------------------------------------------------------------------------------------------------------------------------------- // bool ofxOculusRift::init( int _width, int _height, int _fboNumSamples ) { initFBO( _width, _height ); hmdWarpShader.load("Shaders/HmdWarp"); ofDisableArbTex(); ofFbo::Settings tmpSettings = ofFbo::Settings(); tmpSettings.width = _width/2; tmpSettings.height = _height; tmpSettings.internalformat = GL_RGB; tmpSettings.textureTarget = GL_TEXTURE_2D; tmpSettings.numSamples = _fboNumSamples; eyeFboLeft.allocate( tmpSettings ); eyeFboRight.allocate( tmpSettings ); ofEnableArbTex(); setNearClip( 0.001f ); setFarClip( 2048.0f ); setFov( 90.0f ); setInterOcularDistance( -0.6f ); setShaderScaleFactor( 1.0f ); setDoWarping( true ); return initSensor(); }
task main(){ // This struct holds all the sensor related data tDIMC compass; displayCenteredTextLine(0, "Dexter Ind."); displayCenteredBigTextLine(1, "dCompass"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); // Fire up the compass and initialize it. Only needs to be done once. if (!initSensor(&compass, DIMC)) playSound(soundException); sleep(100); while (true){ // Read the Compass if (!readSensor(&compass)) playSound(soundException); displayCenteredBigTextLine(2, "%3.2f", compass.heading); displayTextLine(5, "%d", compass.axes[0]); displayTextLine(6, "%d", compass.axes[1]); displayTextLine(7, "%d", compass.axes[2]); sleep(50); } }
task main () { // declare and initialise the sensor tTIR tir; initSensor(&tir, S1); displayCenteredTextLine(0, "Dexter Industries"); displayCenteredTextLine(1, "Thermal Infrared"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); // set emissivity for light skin setEmissivity(&tir, TIR_EM_SKIN_LIGHT); sleep(200); displayCenteredTextLine(0, "Dexter Industries"); displayCenteredTextLine(1, "Thermal Infrared"); while (true) { // Read the currently detected ambient and object temp from the sensor readSensor(&tir); displayTextLine(3, "A: %3.2f", tir.ambientTemp); displayTextLine(4, "O: %3.2f", tir.objectTemp); sleep(100); } }
task main () { // This struct holds all the sensor related data tDIMC compass; tSensors DIMC = S1; // Our local variables short strength = 0; // Fire up the compass and initialize it. Only needs to be done once. if (!initSensor(&compass, DIMC)) playSound(soundException); // Loop forever, reading the sensor and calulating total // field strength while (true) { // Read the Compass if (!readSensor(&compass)) playSound(soundException); // calculate the field strength strength = sqrt(pow(compass.axes[0], 2) + pow(compass.axes[1], 2) + pow(compass.axes[2], 2)); // Play a tone of the frequency of the field strength // Great for annoying the cat/dog/wife/parent playImmediateTone(strength, 8); // display on the screen displayCenteredBigTextLine(3, "%d", strength); sleep(50); } }
void CSensor::load() { if (m_handle) { char *error; error = nullptr; TFGetStatistics getStatistics; TFGetFrameAvialable getFrameAvialable; MON_IMPORT(TFInitSensor , initSensor ); MON_IMPORT(TFGetName , getName ); MON_IMPORT(TFGetDefinition , getDefinition ); MON_IMPORT(TFGetDefinitionLength, getDefinitionLength); MON_IMPORT(TFGetStatistics , getStatistics ); MON_IMPORT(TFGetFrameAvialable , getFrameAvialable ); initSensor(MON_ST_LOGGER, MON_ST_CONFIG->folder("sensors")->folder(name())); setDefinition(getDefinition()); if(name().compare(getName()) != 0) { MON_LOG_ERR("Detected try to load sensor " << getName() << ", renamed to " << name()); } for(auto &frame : definition()->frames()) { m_frames[frame] = new CFrame(this, getStatistics, getFrameAvialable, frame); } } }
// main task task main () { displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "IR Seekr"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Press enter to"); displayCenteredTextLine(6, "switch between"); displayCenteredTextLine(7, "600 and 1200 Hz"); sleep(2000); // Create struct to hold sensor data tHTIRS2 irSeeker; // Initialise and configure struct and port initSensor(&irSeeker, S1); while(true) { // You can switch between the two different DSP modes by pressing the // orange enter button playSound(soundBeepBeep); while(bSoundActive) {} eraseDisplay(); // display the current DSP mode if (irSeeker.mode == DSP_1200) displayTextLine(0, " DC 1200"); else displayTextLine(0, " DC 600"); while (true) { if (getXbuttonValue(xButtonEnter)) { // "Enter" button has been pressed. Need to switch mode irSeeker.mode = (irSeeker.mode == DSP_1200) ? DSP_600 : DSP_1200; while(getXbuttonValue(xButtonEnter)) { sleep(1); } break; } // Read the sensor data. readSensor(&irSeeker); displayTextLine(1, "D:%4d %4d 3%d", irSeeker.dcDirection, irSeeker.acDirection, irSeeker.enhDirection); displayTextLine(2, "0:%4d %d", irSeeker.dcValues[0], irSeeker.acValues[0]); displayTextLine(3, "0:%4d %4d", irSeeker.dcValues[1], irSeeker.acValues[1]); displayTextLine(4, "0:%4d %4d %3d", irSeeker.dcValues[2], irSeeker.acValues[2], irSeeker.enhStrength); displayTextLine(5, "0:%4d %4d", irSeeker.dcValues[3], irSeeker.acValues[3]); displayTextLine(6, "0:%4d %4d", irSeeker.dcValues[4], irSeeker.acValues[4]); displayTextLine(7, "Enter to switch"); } } }
int HTS221::setOneShotMode(void) { /* Set one shot mode with the following parameters: * - pressure and temperature internal average values: AVGT = 256 and AVGP = 512; * - block data update bit in CTRL_REG1 set to 1; * - power ON the sensor. */ return initSensor(0x3F,0x84); }
task main() { //Create and configure struct for the compass: // Create struct to hold sensor data: tHTMC compass; // Initialise and configure struct and port: initSensor(&compass, S4); //Define destination coordinates: long destLat = 0; // Add the latitude destination here. long destLong = 0; // Add the longitude destination here. long GPSrelHeading; long distance; DGPSsetDestination(DGPS, destLat, destLong); while (DGPSreadDistToDestination(DGPS) > 0) //Travelling to destination { GPSrelHeading = DGPSreadRelHeading(DGPS); distance = DGPSreadDistToDestination(DGPS); // Here, the relative heading of the GPS is set as the target heading of the compass; // a compass.relativeHeading of 0 means the destination is straight ahead, > 0 heading means it // is to the left, and < 0 means the dest is to the right. readSensor(&compass); compass.offset = GPSrelHeading; displayTextLine(3, "GPSRelHead: %d", GPSrelHeading); readSensor(&compass); displayTextLine(5, "CompRelHead: %d", compass.relativeHeading); displayTextLine(7, "Distance: %d", distance); setMotorSpeed(LEFT, 75); setMotorSpeed(RIGHT, 75); readSensor(&compass); if (compass.relativeHeading > 5) //If car is right of dest., turn left { steerLeft(); } else if (compass.relativeHeading < -5) //If car is left of dest., turn right { steerRight(); } else //dest. is forward { steerRecenter(); } sleep(1000); } //Destination reached setMotorSpeed(LEFT, 0); setMotorSpeed(RIGHT, 0); steerRecenter(); }
void initTank(struct tankdef* theTank) { int i; strcpy(theTank->name, "noname"); strcpy(theTank->author, "noauthor"); strcpy(theTank->color, "#808080"); strcpy(theTank->program, ""); for(i=0; i<TANK_MAX_SENSORS; i++) { initSensor(&theTank->sensors[i]); } }
KinectInput::KinectInput(bool sitMode, TrackingPoint hand) : sitMode(sitMode) { kinectSensor = NULL; nextSkeletonUpdate = NULL; switchHand(hand); handPos = { 0, 0, 0 }; initSensor(); }
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() { // Create struct to hold sensor data tHTIRS2 irSeeker; // Initialise and configure struct and port initSensor(&irSeeker, S3); int leftSpeed = 40; int rightSpeed = 40; OpenWrite( while (true) { int leftSum = irSeeker.dcValues[0] + irSeeker.dcValues[1]; int rightSum = irSeeker.dcValues[3] + irSeeker.dcValues[4]; if (leftSum < rightSum && rightSum - leftSum > 22) { leftSpeed = 40; rightSpeed = -40; } else if (rightSum < leftSum && leftSum - rightSum > 22) { leftSpeed = -40; rightSpeed = 40; } else { leftSpeed = -40; rightSpeed = -40; } motor[frontRight] = rightSpeed; motor[backRight] = rightSpeed; motor[frontLeft] = leftSpeed; motor[backLeft] = leftSpeed; readSensor(&irSeeker); writeDebugStreamLine("irSeeker values"); for (int i = 0; i < 5; i++) { writeDebugStreamLine("irSeeker[%d]: %d", i, irSeeker.dcValues[i]); } for (int i = 0; i < 5; i++) { writeDebugStreamLine("irSeeker[%d]: %d", i, irSeeker.dcValues[i]); } writeDebugStreamLine("-----------------------"); wait1Msec(50); } }
void BH1750Sensor::onCmdTestInst() { if (!initSensor()) return; tsl->SetSensitivity(1.00F); for (int i=0; i < 100; i++) { Serial << "AutoLux: "<< tsl->getLuxAutoScale() << endl; measureMT(31); measureMT(69); measureMT(254); Serial << endl; menuHandler.loop(); delay(1000); } closeSensor(); }
void initializeRobot() { //eraseDisplay(); //servo[rampLease] = leaseInitial; //servo[tail] = tailInitial; //servo[rampDrop] = rampInitial; nMotorEncoder[lift] = 0; nMotorEncoder[leftFront] = 0; nMotorEncoder[rightFront] = 0; //clearDebugStream(); // Initialise and configure struct and port initSensor(&irSeeker, seeker); // startTask(irSeek); }
// main task task main () { displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "IRSeekr2"); displayCenteredTextLine(3, "SMUX Test"); displayCenteredTextLine(5, "Connect SMUX to"); displayCenteredTextLine(6, "S1 and sensor to"); displayCenteredTextLine(7, "SMUX Port 1"); sleep(2000); // Create struct to hold sensor data tHTIRS2 irSeeker; // 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(&irSeeker, msensor_S3_2); wait1Msec(2000); eraseDisplay(); time1[T1] = 0; // You can switch between the two different DSP modes by pressing the // orange enter button playSound(soundBeepBeep); while(bSoundActive) {} eraseDisplay(); displayCenteredTextLine(0, "DC 1200"); while (true) { // Read the sensor data. readSensor(&irSeeker); displayTextLine(1, "D:%4d:%4d:3%d", irSeeker.dcDirection, irSeeker.acDirection, irSeeker.enhDirection); displayTextLine(2, "0:%4d:%d", irSeeker.dcValues[0], irSeeker.acValues[0]); displayTextLine(3, "0:%4d:%4d", irSeeker.dcValues[1], irSeeker.acValues[1]); displayTextLine(4, "0:%4d:%4d:%3d", irSeeker.dcValues[2], irSeeker.acValues[2], irSeeker.enhStrength); displayTextLine(5, "0:%4d:%4d", irSeeker.dcValues[3], irSeeker.acValues[3]); displayTextLine(6, "0:%4d:%4d", irSeeker.dcValues[4], irSeeker.acValues[4]); displayTextLine(7, "Enter to switch"); sleep(500); } }
void initNode (void) { int i = 0; uint8_t * ID_Sensor_List; this.ID = SENSOR_NODE_ID; this.num_sensors = getSensorNumber(); // dobbiamo modificare con la getSensorNumbers this.authentication_key = SENSOR_NODE_KEY; this.sensor = malloc(this.num_sensors*sizeof(Sensor)); ID_Sensor_List = malloc(this.num_sensors*sizeof(uint8_t)); getIDSensorList(ID_Sensor_List); for (i = 0; i < this.num_sensors; i++) { this.sensor[i].ID = ID_Sensor_List[i]; initSensor(&(this.sensor[i])); } }
task main () { string _tmp; displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "Color V2"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); // Create struct to hold sensor data tHTCS2 colorSensor; // Initialise and configure struct and port initSensor(&colorSensor, S1); eraseDisplay(); while (true) { // Read the currently detected colour and RGB/HSV data from the sensor if (!readSensor(&colorSensor)) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } displayCenteredTextLine(0, "Color: %d", colorSensor.color); displayCenteredBigTextLine(1, "R G B"); eraseRect(0,10, 99, 41); fillRect( 0, 10, 30, 10 + (colorSensor.red+1)/8); fillRect(35, 10, 65, 10 + (colorSensor.green+1)/8); fillRect(70, 10, 99, 10 + (colorSensor.blue+1)/8); StringFormat(_tmp, " %3d %3d", colorSensor.red, colorSensor.green); displayTextLine(7, "%s %3d", _tmp, colorSensor.blue); sleep(100); } }
task main () { displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "TMUX"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "This is for the"); displayCenteredTextLine(6, "Touch MUX"); sleep(2000); // Create struct to hold sensor data tHTTMUX touchMUX; // Initialise and configure struct and port initSensor(&touchMUX, S1); while (true) { eraseDisplay(); displayTextLine(0, "HT Touch MUX"); // Read the data from the sensor readSensor(&touchMUX); // Go through each possible touch switch attached to the TMUX // and display whether or not is active (pressed) for (short i = 0; i < 4; i++) { if (touchMUX.status[i]) displayTextLine(i+2, "Touch %d: on", i+1); else displayTextLine(i+2, "Touch %d: off", i+1); } // Display the binary value of the active touch switches // 0 = no touch, 1 = touch 1 active, 2 = touch 2 active, etc. // touch 1 + touch 2 active = 1 + 2 = 3. displayTextLine(7, "Mask: %d", touchMUX.statusMask); sleep(50); } }
task main () { displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "Accel"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); playSound(soundBeepBeep); while(bSoundActive) sleep(1); // Create struct to hold sensor data tHTAC accelerometer; // Initialise and configure struct and port initSensor(&accelerometer, S1); while (true) { eraseDisplay(); // Read all of the axes at once if (!readSensor(&accelerometer)) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } displayTextLine(0,"HTAC Test 1"); displayTextLine(2, " X Y Z"); displayTextLine(3, "%4d %4d %4d", accelerometer.x, accelerometer.y, accelerometer.z); // Alternatively, you can read them like this: displayTextLine(4, "%4d %4d %4d", accelerometer.axes[0], accelerometer.axes[1], accelerometer.axes[2]); sleep(100); } }
void BH1750Sensor::setup(MenuHandler *handler) { handler->registerCommand(new MenuEntry(F("bhTest"), CMD_EXACT, &BH1750Sensor::onCmdTest, F(""))); initSensor(); closeSensor(); }
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); } } }
void TSL2561Sensor::getData(LinkedList<Pair *> *data) { if (!initSensor()) return; data->add(new Pair("LUX", String(tsl->getLuxAutoScale()))); closeSensor(); }
void TSL2561Sensor::setup(MenuHandler *handler) { //handler->regsterCommand(new MenuEntry(F("tslInit"), CMD_EXACT, &TSL2561Sensor::onCmdInit, F(""))); initSensor(); closeSensor(); }
int main(void) { initTMR(); initSensor(); initMotor(); TRISButton = OUTPUT; WEAKASSPULLUP = ENABLED; TRISLEDR = OUTPUT; TRISLEDF = OUTPUT; TRISLEDL = OUTPUT; while (1) { switch (state) { case idle: stop(); if (button == PRESSED) state = debouncePress; nextState = follow; break; case wait: if (button == UNPRESSED) state = debounceRelease; break; case debouncePress: delayUs(5000); state = wait; break; case debounceRelease: delayUs(5000); state = nextState; break; case follow: nextState = idle; //delayUs(5000); if (IFS0bits.AD1IF == 1) { IFS0bits.AD1IF = 0; front = getSensorFront(); left = getSensorLeft(); right = getSensorRight(); } if ((right == ONTAPE || left == ONTAPE)) { stop(); if (left == ONTAPE && front == OFFTAPE) alignLeft(); else if (right == ONTAPE && front == OFFTAPE) alignRight(); else if(right == ONTAPE && front == ONTAPE && left == ONTAPE) flip(); else forward(); } else if (front == ONTAPE) { forward(); } /*else if(front == ONTAPE && (right == ONTAPE || left == ONTAPE)) { stop(); if(turns < 3) turnRight(); else if (turns == 3) flip(); else turnLeft(); turns++; }*/ if (button == PRESSED) state = debouncePress; break; } } }
int LPS25H::setOneShotMode(void) { return initSensor(0x84, 0x00, 0x05); }
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; } } }