task main () { nNxtButtonTask = -2; displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "Angle"); displayCenteredTextLine(3, "Test 2"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); MSANGresetAngle(MSANG); sleep(2000); eraseDisplay(); while (true) { // Reset the angle to 0 if (nNxtButtonPressed == kEnterButton) { debounce(); calibrateScales(); debounce(); } displayCenteredTextLine(0, "GlideWheel-AS"); displayCenteredTextLine(1, "Weighing scale"); displayTextLine(7, "[enter] to calib."); displayCenteredBigTextLine(4, "%d g", weighObject()); sleep(20); } }
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); } }
/* ============================================================================= 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); } } }
task main () { short distance = 0; short voltage = 0; short mindist = 0; short maxdist = 0; string type; displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "DIST-nx"); displayCenteredTextLine(3, "Test 1"); sleep(2000); playSound(soundBeepBeep); while(bSoundActive) EndTimeSlice(); eraseDisplay(); // Read the minimum distance the sensor can "see" mindist = MSDISTreadMinDist(MSDIST); // Read the maximum distance the sensor can "see" maxdist = MSDISTreadMaxDist(MSDIST); // Get the type of Sharp IR module connected to the sensor switch(MSDISTreadModuleType(MSDIST)) { case MSDIST_GP2D12: type = " GP2D12"; break; case MSDIST_GP2D120: type = "GP2D120"; break; case MSDIST_GP2YA02: type = "GP2YA02"; break; case MSDIST_GP2YA21: type = "GP2YA21"; break; case MSDIST_CUSTOM: type = " CUSTOM"; break; } displayTextLine(5, "Type: %s", type); displayTextLine(6, "Min: %4dmm", mindist); displayTextLine(7, "Max: %4dmm", maxdist); while (true) { // Get the distance calculated based on the data from the IR Sharp module distance = MSDISTreadDist(MSDIST); // Get the raw voltage data from the Sharp IR module voltage = MSDISTreadVoltage(MSDIST); if (distance < 0) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } displayCenteredBigTextLine(0, "%4dmm", distance); displayCenteredBigTextLine(3, "%4dmV", voltage); sleep(50); } }
task main(){ short heading; short x_val, y_val, z_val; // axis values displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "IMU"); displayCenteredTextLine(3, "Test 2"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); while (true){ // Read the Compass heading = MSIMUreadHeading(MSIMU); displayTextLine(1, "%d", heading); // Read the tilt MSIMUreadTiltAxes(MSIMU, x_val, y_val, z_val); displayTextLine(5, "%d", x_val); displayTextLine(6, "%d", y_val); displayTextLine(7, "%d", z_val); sleep(50); } }
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); } }
task main () { nNxtButtonTask = -2; displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "Angle"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); displayCenteredTextLine(0, "GlideWheel-AS"); displayTextLine(1, "-------------------"); displayTextLine(5, "-------------------"); while (true) { // Reset the angle to 0 if (nNxtButtonPressed == kEnterButton) { MSANGresetAngle(MSANG); while (nNxtButtonPressed != kNoButton) sleep(1); } // Read the current angle, accumulated angle and RPM and display them displayTextLine(2, "Ang: %7d deg", MSANGreadAngle(MSANG)); displayTextLine(3, "Raw: %7d", MSANGreadRaw(MSANG)); displayTextLine(4, "RPM: %7d", MSANGreadRPM(MSANG)); displayTextLine(7, " Reset angle"); sleep(50); } }
void check_bleutooth(string *s){ /* This function makes a bleutooth connection and then waits for input from the connected phone */ TFileIOResult nBTCmdRdErrorStatus; int nSizeOfMessage; ubyte nRcvBuffer[kMaxSizeOfMessage]; while(1){ //wait on bleutooth nSizeOfMessage = cCmdMessageGetSize(INBOX); if (nSizeOfMessage > kMaxSizeOfMessage){//make the message shorter if its to long nSizeOfMessage = kMaxSizeOfMessage; } if (nSizeOfMessage > 0){//if the message is not empty, put the received information in string s nBTCmdRdErrorStatus = cCmdMessageRead(nRcvBuffer, nSizeOfMessage, INBOX); nRcvBuffer[nSizeOfMessage] = '\0'; stringFromChars(*s, (char *) nRcvBuffer); displayCenteredBigTextLine(4, *s); break; } wait1Msec(100);//no need to do a continues check every 100 miliseconds is enough } }
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); } }
// Allow the user to calibrate the scales void calibrateScales() { short calibrateWeight = 0; eraseDisplay(); displayCenteredTextLine(0, "GlideWheel-AS"); displayCenteredTextLine(2, "Place the object"); displayCenteredTextLine(3, "on the scales"); displayCenteredTextLine(4, "and press"); displayCenteredTextLine(5, "[enter]"); displayCenteredTextLine(6, "to calibrate"); while (nNxtButtonPressed != kEnterButton) sleep(1); debounce(); eraseDisplay(); calibrateWeight = weighObject(); displayCenteredTextLine(0, "GlideWheel-AS"); displayCenteredTextLine(2, "Enter the weight"); displayCenteredTextLine(3, "in grams"); displayCenteredTextLine(7, "- OK +"); while (true) { displayCenteredBigTextLine(5, "%d", calibrateWeight); switch(nNxtButtonPressed) { case kLeftButton: playTone(500,10); calibrateWeight--; calibrateWeight = max2(0, calibrateWeight); break; case kRightButton: playTone(1000,10); calibrateWeight++; break; case kEnterButton: playTone(1500,10);gramsPerUnit = (float)calibrateWeight / (float)MSANGreadRaw(MSANG); eraseDisplay(); return; } sleep(20); debounce(); } }
task main(){ displayCenteredTextLine(0, "Dexter Ind."); displayCenteredBigTextLine(1, "IMU"); displayCenteredTextLine(3, "Test 2"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); // Fire up the gyro and initialize it. Only needs to be done once. //DIMUconfigGyro(DIMU, DIMU_GYRO_RANGE_500); if (!DIMUconfigAccel(DIMU, DIMU_ACC_RANGE_2G)) playSound(soundException); if(!DIMUconfigGyro(DIMU, DIMU_GYRO_RANGE_250, true)) playSound(soundException); for (short i = 0; i < 500; i++){ // Read the GYROSCOPE // There are 3 ways to do this: // All at once, very convenient if you need all 3 DIMUreadGyroAxes(DIMU, xvals[i], yvals[i], zvals[i]); sleep(5); } for (short i = 0; i< 500; i++) { writeDebugStream("%f, %f", xvals[i], yvals[i]); writeDebugStreamLine(", %f", zvals[i]); sleep(2); } }
task main () { displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "TMUX"); displayCenteredTextLine(3, "SMUX Test"); displayCenteredTextLine(5, "Connect SMUX to"); displayCenteredTextLine(6, "S1 and TMUX to"); displayCenteredTextLine(7, "SMUX Port 1"); sleep(2000); while (true) { eraseDisplay(); displayTextLine(0, "MS Touch MUX"); // Get the raw data from the sensor, this is not processed // by the driver in any way. displayTextLine(1, "Raw: %d", 1023 - HTSMUXreadAnalogue(MSTMUX)); // Go through each possible touch switch attached to the TMUX // and display whether or not is active (pressed) for (short i = 1; i < 4; i++) { if (MSTMUXisActive(MSTMUX, i)) displayTextLine(i+2, "Touch %d: on", i); else displayTextLine(i+2, "Touch %d: off", i); } // 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, "Status: %d", MSTMUXgetActive(MSTMUX)); sleep(50); } }
task main () { short keys = 0; unsigned byte key[] = {0}; short number = 0; string output; displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "NumPad"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); displayCenteredTextLine(0, "Mindsensors NP"); displayTextLine(1, "-------------------"); displayTextLine(5, "-------------------"); displayTextLine(7, "X: no key"); while (true) { // Which key is being pressed now? if (!MSNPscanKeys(MSNP, keys, key[0], number)) stopAllTasks(); // "convert" to string so we can print it output = key; displayTextLine(3, "Numpad Key: %s", output); displayTextLine(4, "Numpad Num: %d", number); sleep(100); } }
task main () { short red = 0; short green = 0; short blue = 0; short _color = 0; string _tmp; displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "COLOUR"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); while (true) { // Read the currently detected colour from the sensor _color = HTCSreadColor(HTCS); // If colour == -1, it implies an error has occurred if (_color < 0) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } // Read the RGB values of the currently colour from the sensor // A return value of false implies an error has occurred if (!HTCSreadRGB(HTCS, red, green, blue)) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } displayCenteredTextLine(0, "Color: %d", _color); displayCenteredBigTextLine(1, "R G B"); eraseRect(0,10, 99, 41); fillRect( 0, 10, 30, 10 + (red+1)/8); fillRect(35, 10, 65, 10 + (green+1)/8); fillRect(70, 10, 99, 10 + (blue+1)/8); StringFormat(_tmp, " %3d %3d", red, green); displayTextLine(7, "%s %3d", _tmp, blue); sleep(100); } }
// 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 bleutooth_control(string *s){ /* This code is for taking over the robot completely using bleutooth to make sure you can stop de robot in case its needed. pressing the middle button ("FIRE") on the phone stops the robot due to it not being included in the code here. To get in to this function you have to press "B" */ TFileIOResult nBTCmdRdErrorStatus; int nSizeOfMessage; ubyte nRcvBuffer[kMaxSizeOfMessage]; int stopcode = 0; while (*s != "A"){//if A is pressed the robot will resume its duty the normal way nSizeOfMessage = cCmdMessageGetSize(INBOX); if (nSizeOfMessage > kMaxSizeOfMessage){ nSizeOfMessage = kMaxSizeOfMessage; } if (nSizeOfMessage > 0){ nBTCmdRdErrorStatus = cCmdMessageRead(nRcvBuffer, nSizeOfMessage, INBOX); nRcvBuffer[nSizeOfMessage] = '\0'; *s = ""; stringFromChars(*s, (char *) nRcvBuffer);//put bluetooth input in string s displayCenteredBigTextLine(4, *s); } //The next 4 if statements are for controlling the robot manually if(*s == "LEFT"){//if bleutooth input is left turn left motor(motorA) = 0; motor(motorB) = 30; startTask(music);//make sure the music is running } else if(*s == "RIGHT"){//if bleutooth input is right turn right motor(motorA) = 30; motor(motorB) = 0; startTask(music); } else if (*s == "UP"){//if bleutooth input is up drive forward setMultipleMotors(50, motorB, motorA); startTask(music); } else if (*s == "DOWN"){//if bleutooth input is down drive backwards setMultipleMotors(-50, motorB, motorA); startTask(music); } else {//if there is no correct input turn off the motors setMultipleMotors(0, motorA, motorB); stopTask(music);//make sure the music is stopped clearSounds();//empty the buffer } if (*s == "C"){//if the C button is pressed the loop stops and the stopcode == 1 to stop de code from running stopcode = 1; stopTask(music); clearSounds(); break; } } *s = "";//make sure s is empty return stopcode;//output of the function used to stop the code if chosen }
task main() { while (true) { int gyroValue = SensorValue[GyroSensor] - 589; displayCenteredBigTextLine(3, "%i", gyroValue); wait1Msec(10); } }
/*-----------------------------------------------------------------------------*/ void iqRunDisplayLogo() { #ifdef _LOGO drawBitmap( logo ); #else displayCenteredBigTextLine(2, "ROBOTC"); #endif }
task main() { displayCenteredTextLine(0, "Station"); displayCenteredBigTextLine(1, "RoboTaxi"); displayCenteredTextLine(3, "Using A*"); displayCenteredTextLine(5, "Ashesi"); displayCenteredTextLine(6, "Fall 2015"); sleep(5000); eraseDisplay(); //store input from the numeric keypad base_station(); //displays values received as location and destination displayTextLine(1, "Test Values: "); displayTextLine(2, "Xval: %d", passenger_location_x); displayTextLine(3, "Yval: %d", passenger_location_y); displayTextLine(4, "XDest: %d", passenger_destination_x); displayTextLine(5, "YDest: %d", passenger_destination_y); wait1Msec(100); goal_x = passenger_destination_x; goal_y = passenger_destination_y; //find goal with taxi1 in mind findGoal(taxi1base_x, taxi1base_y, passenger_location_x, passenger_location_y); //get distance from taxi1 to passenger int dist1 = get_distance(taxi1base_x, taxi1base_y, passenger_location_x, passenger_location_y); //find goal with taxi2 in mind findGoal(taxi2base_x, taxi2base_y, passenger_location_x, passenger_location_y); //get distance from taxi2 to passenger int dist2 = get_distance(taxi2base_x, taxi2base_y, passenger_location_x, passenger_location_y); //compare distances between taxis and passengers. select taxi with shorter distance if (dist1 < dist2){//if taxi1 is shorter eraseDisplay(); displayTextLine(1, "taxi 1 "); wait1Msec(500); sendMessageWithParm(TAXI1LOC,passenger_location_x,passenger_location_y);//11 is location to taxi1 wait1Msec(500); displayTextLine(1, "to taxi 1.1 "); sendMessageWithParm(TAXI1DEST,passenger_destination_x,passenger_destination_y);//12 is destination to taxi1 wait1Msec(500); displayTextLine(1, "to taxi 1.2 "); } else {//if taxi2 is shorter displayTextLine(1, "taxi 2 "); wait1Msec(500); sendMessageWithParm(TAXI2LOC,passenger_location_x,passenger_location_y);//21 is location to taxi2 wait1Msec(500); displayTextLine(1, "to taxi 2.1 "); sendMessageWithParm(TAXI2DEST,passenger_destination_x,passenger_destination_y);//22 is destination to taxi2 wait1Msec(500); displayTextLine(1, "to taxi 2.2 "); } }
// Display the instructions to the user void displayInstructions() { 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); }
/** * Show a fancy startup display */ void StartupDisplay() { displayCenteredBigTextLine(0, "WiFi"); displayCenteredTextLine(3, "Program to test"); displayCenteredTextLine(4, "Network with "); displayCenteredTextLine(5, "WifiBlock"); sleep(2000); eraseDisplay(); return; }
task main () { short soundraw = 0; short soundnorm = 0; bool dba = false; nNxtButtonTask = -2; displayCenteredTextLine(0, "Lego"); displayCenteredBigTextLine(1, "Sound"); displayCenteredTextLine(3, "SMUX Test"); displayCenteredTextLine(5, "Connect SMUX to"); displayCenteredTextLine(6, "S1 and snd sensor"); displayCenteredTextLine(7, "to SMUX Port 1"); sleep(2000); eraseDisplay(); displayTextLine(0, "Lego Sound Sensor"); displayTextLine(6, "[enter] to switch"); displayTextLine(7, "dB and dBA mode"); // Set the sensor to dB mode. SNDsetDB(LEGOSND); displayCenteredTextLine(1, "dB mode"); while(true) { // The enter button has been pressed, switch // to the other mode if (nNxtButtonPressed == kEnterButton) { dba = !dba; if (!dba) { // set the sensor to DB mode SNDsetDB(LEGOSND); displayCenteredTextLine(1, "dB mode"); } else { // set the sensor to dBA mode. SNDsetDBA(LEGOSND); displayCenteredTextLine(1, "dBA mode"); } // wait 500ms to debounce the switch sleep(500); } // Read the normalised value of the sensor soundraw = SNDreadRaw(LEGOSND); // Display the raw and normalised values soundnorm = SNDreadNorm(LEGOSND); // display the info from the sensor displayTextLine(3, "Raw: %3d", soundraw); displayTextLine(4, "Norm: %3d", soundnorm); sleep(50); } }
task main() { displayCenteredTextLine(0, "Mindsensors"); displayCenteredBigTextLine(1, "PFMate"); displayCenteredTextLine(3, "Test 1"); sleep(2000); // Run through each channel for testing. for (short channel = 1; channel < 5; channel++) { doTest(channel); } }
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); } }
// 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); } }
// Updates the string s to give it the value of the last input of the app. void CheckString(){ TFileIOResult nBTCmdRdErrorStatus; int nSizeOfMessage; ubyte nRcvBuffer[kMaxSizeOfMessage]; nSizeOfMessage = cCmdMessageGetSize(INBOX); if (nSizeOfMessage > kMaxSizeOfMessage){ nSizeOfMessage = kMaxSizeOfMessage; } if (nSizeOfMessage > 0){ nBTCmdRdErrorStatus = cCmdMessageRead(nRcvBuffer, nSizeOfMessage, INBOX); nRcvBuffer[nSizeOfMessage] = '\0'; stringFromChars(s, (char *) nRcvBuffer); displayCenteredBigTextLine(4, s); } }
// Use parameters gathered from command to move the motors, extrude, that sort of thing void executeCommand(string gcmd, float x, float y, float z, float e, float f) { float motorDegrees; // Amount the motor has to move float deltaPosition; // The difference between the current position and the one we want to move to // execute functions inside this algorithm if (strcmp(gcmd, "G1") == 0 ){ if(x != noParam){ writeDebugStreamLine("\n---------- X AXIS -------------"); long xPower = setXSpeed * calcMotorPower(x, y, z); deltaPosition = calcDeltaDistance(xAxisPosition, x); motorDegrees = calcMotorDegrees(deltaPosition, XdegreesToMM); moveMotorAxis(x_axis, motorDegrees, xPower); xPower = setXSpeed; } if(y != noParam){ writeDebugStreamLine("\n---------- Y AXIS -------------"); long yPower = setYSpeed; deltaPosition = calcDeltaDistance(yAxisPosition, y); motorDegrees = calcMotorDegrees(deltaPosition, YdegreesToMM); moveMotorAxis(y_axis, motorDegrees, yPower); yPower = setYSpeed; } if(z != noParam){ writeDebugStreamLine("\n---------- Z AXIS -------------"); long zPower = calcMotorPower(x, y, z); deltaPosition = calcDeltaDistance(zAxisPosition, z); motorDegrees = calcMotorDegrees(deltaPosition, ZdegreesToMM); moveMotorAxis(z_axis, motorDegrees, zPower); } #ifndef DISABLE_MOTORS waitForMotors(); #endif } //this is where to add else if statements for new g commands else { //error displayCenteredBigTextLine(1 , "error! :: gcmd value is unknown!"); } }
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); } }
/** * The main task */ task main(){ displayCenteredTextLine(0, "Dexter Ind."); displayCenteredBigTextLine(1, "IMU"); displayCenteredTextLine(3, "Test 3"); displayCenteredTextLine(5, "Connect sensor"); displayCenteredTextLine(6, "to S1"); sleep(2000); eraseDisplay(); // If configuration fails, the program ends. if (!DIMUconfigAccel(DIMU, DIMU_ACC_RANGE_2G)) { playSound(soundException); while(bSoundActive){} stopAllTasks(); } while(nNxtButtonPressed == kNoButton) { z_val = DIMUreadAccelZAxis10Bit(DIMU); x_val = DIMUreadAccelXAxis10Bit(DIMU); // Since the axes are constantly 90 degrees apart, we can use the sum of forces law, // which looks like the pythagorean theorem, to discover the total force along both axes. Gforce = sqrt(pow(z_val, 2) + pow(x_val, 2)); // Then we divide both values received by the total force to get numbers on the interval [-1,1]. // This way we can input them into the arcsine and arccosine functions. z_val = z_val/Gforce; x_val = x_val/Gforce; pXrads[0] = asin(x_val); pXrads[1] = PI-pXrads[0]; //other possible X tilt value. pZrads[0] = acos(z_val); pZrads[1] = -1*pZrads[0]; //other possible Z tilt value. normalize(); displayArrow(radiansToDegrees(match())); // This stops the screen from flashing. sleep(100); } }
task main () { short _dir = 0; short dcS1, dcS2, dcS3, dcS4, dcS5 = 0; displayCenteredTextLine(0, "HiTechnic"); displayCenteredBigTextLine(1, "IR Seekr"); displayCenteredTextLine(3, "Test 1"); displayCenteredTextLine(5, "This is for the"); displayCenteredTextLine(6, "v1 seeker"); sleep(2000); while(true) { eraseDisplay(); // read all of the sensors' values at once, // exit the app if an error occurs if (! HTIRSreadAllStrength(HTIRS, dcS1, dcS2, dcS3, dcS4, dcS5)) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } // read the direction from which the signal is coming, // exit the app if an error occurs _dir = HTIRSreadDir(HTIRS); if (_dir < 0) { displayTextLine(4, "ERROR!!"); sleep(2000); stopAllTasks(); } // display the info from the sensor displayTextLine(0,"HT IR Seeker"); displayTextLine(2, "dir: %2d", _dir); displayTextLine(3, "S1: %3d", dcS1); displayTextLine(4, "S2: %3d", dcS2); displayTextLine(5, "S3: %3d", dcS3); displayTextLine(6, "S4: %3d", dcS4); displayTextLine(7, "S5: %3d", dcS5); sleep(100); } }