void DreamWebEngine::newPlace() { if (_vars._needToTravel == 1) { _vars._needToTravel = 0; selectLocation(); } else if (_autoLocation != 0xFF) { _newLocation = _autoLocation; _autoLocation = 0xFF; } }
task main() { int elevatorHeightTicks; // Set the following variables to false to hide the standard NXT LCD information bDisplayDiagnostics = false; bNxtLCDStatusDisplay = false; ////////// INITIALIZATIONS ////////// initializeRobot(); // Execute robot initialization routine /////////////// Variables to be used later ///////////////// //int maxArmHeightTicks = inchesToTicks(maxArmHeight); //int minRingPickupHeightTicks = inchesToTicks(minRingPickupHeight); //int WAMservoStep = 3; //Amount to inc1rement the WAM servo position //int WAMservoStep12 = 17; // Move a servo 15 degrees //float maxArmHeight = 45.25; // Maximum Safe Arm Height used during manual control of the arm //float minRingPickupHeight = 8.0; // User selected Autonomous information { selectStartLocation(); // Get the starting location of the robot selectAutoActions(); // Get Autononmous actions switch(AutoActions) { case 0: // No Autonomous break; case 1: // IR Beacon selectRow(); // runs the select row function selectAutoStartDelay(); // select the autonomous start delay break; case 2: // Left Colmnn selectRow(); // runs the select row function selectAutoStartDelay(); // select the autonomous start delay break; case 3: // Center Colmnn selectRow(); // runs the select row function selectAutoStartDelay(); // select the autonomous start delay break; case 4: // Right Colmnn selectRow(); // runs the select row function selectAutoStartDelay(); // select the autonomous start delay break; case 5: // Play Defense selectAutoStartDelay(); // select the autonomous start delay break; default: // Not a valid selection eraseDisplay(); nxtDisplayCenteredTextLine(1,"DITU SAYS"); nxtDisplayCenteredTextLine(2,"INPUT ERROR"); nxtDisplayCenteredTextLine(4,"TRY AGAIN"); wait1Msec(6000); break; } } eraseDisplay(); // Set the following variables to false to hide the standard NXT LCD information // Show the default FTC Display Information bDisplayDiagnostics = true; bNxtLCDStatusDisplay = true; //bDisplayDiagnostics = false; //bNxtLCDStatusDisplay = false; // Determine the autonomous start delay based on delayAutoStart switch(delayAutoStart) { case 0: // delay start = 0 seconds delayAutoStartValue = 0; break; case 1: // delay start = 1 second delayAutoStartValue = 1000; break; case 2: // delay start = 5 seconds delayAutoStartValue = 5000; break; case 3: // delay start = 10 seconds delayAutoStartValue = 10000; break; case 5: // delay start = 15 seconds delayAutoStartValue = 15000; break; default: // delay start = 0 seconds delayAutoStartValue = 0; break; } // Process robot starting location selection switch(robotStartLocation) { case 0: // Left Wall leftWall = true; break; case 1: // Corner corner = true; break; case 2: // Right Wall rightWall = true; break; default: // Not a valid starting location break; } // Process robot starting location selection switch(Row) { case 0: // Bottom Row pegHeightCmd = 1; break; case 1: // Middle Row pegHeightCmd = 2; break; case 2: // Top Row pegHeightCmd = 3; break; default: // Not a valid starting location break; } waitForStart(); // Wait for the signal to start from the Field Control System //reads the protoboard to see which switches are pressed. Since they are globals, nothing is returned. We may want to make this it's own task eventually ProcessProto(); switch(AutoActions) { case 0: // No Autonomous break; case 1: // Score Ring on the column designated by the IR Beacon wait1Msec(delayAutoStartValue); // INSERT CODE TO IDENTIFY THE COLUMN CONTAINING THE IR BEACON HERE elevatorHeightTicks = selectLocation(5); // Determine the number of encoder ticks to raise the elevator to the drive height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height wait1Msec(500); // Insert robot move commands here // Now that the robot is in the scoring location, raise the elevator to the commanded row elevatorHeightTicks = selectLocation(pegHeightCmd); // Determine the number of encoder ticks based on the commanded elevator height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height to score a ring wait1Msec(500); elevatorHeightTicks = selectLocation(4); // Determine the number of encoder ticks to lower the elevator and score the ring elevatorGoToHeight(elevatorHeightTicks); // Score Ring break; case 2: // Score Ring on Left Column wait1Msec(delayAutoStartValue); elevatorHeightTicks = selectLocation(5); // Determine the number of encoder ticks to raise the elevator to the drive height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height wait1Msec(500); // Insert robot move commands here // Now that the robot is in the scoring location, raise the elevator to the commanded row elevatorHeightTicks = selectLocation(pegHeightCmd); // Determine the number of encoder ticks based on the commanded elevator height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height to score a ring wait1Msec(500); elevatorHeightTicks = selectLocation(4); // Determine the number of encoder ticks to lower the elevator and score the ring elevatorGoToHeight(elevatorHeightTicks); // Score Ring break; case 3: // Score Ring on Center Column wait1Msec(delayAutoStartValue); elevatorHeightTicks = selectLocation(5); // Determine the number of encoder ticks to raise the elevator to the drive height tripped = elevatorGoToHeightFailSafe(elevatorHeightTicks, 10000); // Raise elevator to the commanded height if (tripped) //If the elevator trips the fail safe, break break; wait1Msec(500); move_forward(60-5, 5000, 90, 90); /////The alignment from the wall that could work...///// //move_forward(24, 4000, 80, 80); //turngyro_left(45, 60, 60); //move_forward(4, 2000, 80, 80); RAM_down(); // Drive forward until the RAM limit switch is activated or time expires ClearTimer(T1); while(ramLimit==0 && time1[T1] < 2500) { // Try to follow the white navigation tape if(SensorValue(colorSensorVal) >= 15) { // The color sensor sees the black platform, command the robot to drift to the right motor[Left1] = 35; motor[Left2] = 35; motor[Right1] = 15; motor[Right2] = 15; } else { // The color sensor sees the white navigation tape, command the robot to drift to the left motor[Left1] = 15; motor[Left2] = 15; motor[Right1] = 35; motor[Right2] = 35; } ProcessProto(); } ClearTimer(T1); while(time1[T1] < 1500) { motor[Left1] = -25; motor[Left2] = -25; motor[Right1] = 25; motor[Right2] = 25; motor[RAMright] = 95; motor[RAMleft] = 95; } ClearTimer(T1); while(time1[T1] < 1500) { motor[Left1] = 20; motor[Left2] = 20; motor[Right1] = -20; motor[Right2] = -20; motor[RAMright] = 95; motor[RAMleft] = 95; } ClearTimer(T1); while(time1[T1] < 1500) { motor[Left1] = 25; motor[Left2] = 25; motor[Right1] = 25; motor[Right2] = 25; motor[RAMright] = 95; motor[RAMleft] = 95; } /*ClearTimer(T1); while(time1[T1] < 200) { motor[Left1] = -20; motor[Left2] = -20; motor[Right1] = -20; motor[Right2] = -20; motor[RAMright] = 95; motor[RAMleft] = 95; }*/ motor[RAMright] = 0; motor[RAMleft] = 0; motor[Left1] = 0; motor[Left2] = 0; motor[Right1] = 0; motor[Right2] = 0; // Now that the robot is in the scoring location, raise the elevator to the commanded row elevatorHeightTicks = selectLocation(pegHeightCmd); // Determine the number of encoder ticks based on the commanded elevator height elevatorGoToHeightFailSafe(elevatorHeightTicks, 7000); // Raise elevator to the commanded height to score a ring if (tripped) //If the elevator trips the fail safe, break break; wait1Msec(500); elevatorHeightTicks = selectLocation(4); // Determine the number of encoder ticks to lower the elevator and score the ring elevatorGoToHeightFailSafe(elevatorHeightTicks, 7000); // Score Ring if (tripped) //If the elevator trips the fail safe, break break; break; case 4: // Score Ring on Right Column wait1Msec(delayAutoStartValue); elevatorHeightTicks = selectLocation(5); // Determine the number of encoder ticks to raise the elevator to the drive height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height wait1Msec(500); // Insert robot move commands here //asdfjkl; wait1Msec(500); move_forward(12, 5000, 90, 90); turngyro_right(45, 100); move_forward(20, 7000, 80, 80); //RAM_down(); motor[Right1] = 0; motor[Right2] = 0; motor[Left1] = 0; motor[Left2] = 0; /* // Drive forward until the RAM limit switch is activated or time expires ClearTimer(T1); while(ramLimit==0 && time1[T1] < 2500) { // Try to follow the white navigation tape if(SensorValue(colorSensorVal) >= 15) { // The color sensor sees the black platform, command the robot to drift to the right motor[Left1] = 35; motor[Left2] = 35; motor[Right1] = 15; motor[Right2] = 15; } else { // The color sensor sees the white navigation tape, command the robot to drift to the left motor[Left1] = 15; motor[Left2] = 15; motor[Right1] = 35; motor[Right2] = 35; } ProcessProto(); } ClearTimer(T1); while(time1[T1] < 1500) { motor[Left1] = -25; motor[Left2] = -25; motor[Right1] = 25; motor[Right2] = 25; motor[RAMright] = 95; motor[RAMleft] = 95; } ClearTimer(T1); while(time1[T1] < 1500) { motor[Left1] = 20; motor[Left2] = 20; motor[Right1] = -20; motor[Right2] = -20; motor[RAMright] = 95; motor[RAMleft] = 95; } ClearTimer(T1); while(time1[T1] < 1500) { motor[Left1] = 25; motor[Left2] = 25; motor[Right1] = 25; motor[Right2] = 25; motor[RAMright] = 95; motor[RAMleft] = 95; } /*ClearTimer(T1); while(time1[T1] < 200) { motor[Left1] = -20; motor[Left2] = -20; motor[Right1] = -20; motor[Right2] = -20; motor[RAMright] = 95; motor[RAMleft] = 95; }*/ /* motor[RAMright] = 0; motor[RAMleft] = 0; motor[Left1] = 0; motor[Left2] = 0; motor[Right1] = 0; motor[Right2] = 0; // Now that the robot is in the scoring location, raise the elevator to the commanded row elevatorHeightTicks = selectLocation(pegHeightCmd); // Determine the number of encoder ticks based on the commanded elevator height elevatorGoToHeightFailSafe(elevatorHeightTicks, 7000); // Raise elevator to the commanded height to score a ring if (tripped) //If the elevator trips the fail safe, break break; wait1Msec(500); elevatorHeightTicks = selectLocation(4); // Determine the number of encoder ticks to lower the elevator and score the ring elevatorGoToHeightFailSafe(elevatorHeightTicks, 7000); // Score Ring if (tripped) //If the elevator trips the fail safe, break break; break; // Now that the robot is in the scoring location, raise the elevator to the commanded row /*elevatorHeightTicks = selectLocation(pegHeightCmd); // Determine the number of encoder ticks based on the commanded elevator height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height to score a ring wait1Msec(500); elevatorHeightTicks = selectLocation(4); // Determine the number of encoder ticks to lower the elevator and score the ring elevatorGoToHeight(elevatorHeightTicks); // Score Ring break;*/ case 5: // Play Defense wait1Msec(delayAutoStartValue); elevatorHeightTicks = selectLocation(5); // Determine the number of encoder ticks to raise the elevator to the drive height elevatorGoToHeight(elevatorHeightTicks); // Raise elevator to the commanded height //wait1Msec(500); move_backwards(84.0, 10000, 100, 100); break; default: // Not a valid autonomous action break; } // All Done, time to stop all tasks StopAllTasks(); } // End Main Bracket
int main (int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: webclient URL\n"); return EXIT_FAILURE; } char msg[BUFFER_LEN]; int vsocket; tUrl url = decodeUrl(argv[1]); if (url.status != SUCCESS) { fprintf(stderr, "Wrong format of URL.\n"); return EXIT_FAILURE; } char filename[BUFFER_LEN]; char filechar[BUFFER_LEN]; exctractFileName(url.path, filechar); strcpy(filename, filechar); codeUnsafeChar(url.domain); codeUnsafeChar(url.path); createRequest(msg, url); if (connectToServer(url, &vsocket) == FAILED) { fprintf(stderr, "Failed: connect to server\n"); return EXIT_FAILURE; } if (write(vsocket, msg, strlen(msg)) == FAILED) { fprintf(stderr, "Failed: write request\n"); return EXIT_FAILURE; } char answer[BUFFER_LEN]; if (readHeader(vsocket, answer) == FAILED) { fprintf(stderr, "Failed: read header\n"); return EXIT_FAILURE; } int enconding = selectEnconding(answer); tConn connection; connection = selectStatus(answer); if (connection.status >= 400) { fprintf(stderr, "%d\n",connection.status); return EXIT_FAILURE; } char msg_redir[BUFFER_LEN]; int connect_try = 1; tUrl url_redir; // Redirection while (connection.status == 301 || connection.status == 302) { if (selectLocation(answer, msg_redir) == FAILED) { fprintf(stderr, "Failed: redirection\n"); return EXIT_FAILURE; } url_redir = decodeUrl(msg_redir); if (url_redir.status != SUCCESS) { fprintf(stderr, "Failed: decode URL (redirection %d)\n",connect_try); return EXIT_FAILURE; } exctractFileName(url_redir.path, filename); codeUnsafeChar(url_redir.domain); codeUnsafeChar(url_redir.path); createRequest(msg_redir, url_redir); if (connectToServer(url_redir, &vsocket) == FAILED) { fprintf(stderr, "Failed: connect to server\n"); return EXIT_FAILURE; } if (write(vsocket, msg_redir, strlen(msg_redir)) == FAILED) { fprintf(stderr, "Failed: write request (redirection %d)\n",connect_try); return EXIT_FAILURE; } if (readHeader(vsocket, answer) == FAILED) { fprintf(stderr, "Failed: read header\n"); return EXIT_FAILURE; } enconding = selectEnconding(answer); connection = selectStatus(answer); if (connection.status == FAILED) { fprintf(stderr, "%s\n", connection.message); return EXIT_FAILURE; } if (connection.status >= 400) { fprintf(stderr, "%d\n",connection.status); return EXIT_FAILURE; } connect_try++; if (connect_try > 5) { fprintf(stderr, "Multiple (5) redirection."); return EXIT_FAILURE; } } FILE *fw; remove(filename); if ((fw = fopen(filename,"a")) == NULL) { fprintf(stderr, "Failed: open dest file\n"); return EXIT_FAILURE; } // Non-chunked coding if (enconding != CHUNKED) { char ch; while (read(vsocket, &ch, sizeof(char)) > 0) fprintf(fw,"%c",ch); fclose(fw); return SUCCESS; } // Chunked coding char chr1 = '#'; char chr2 = '#'; int i = 0; int chunk = 0; char ch[BUFFER_LEN]; while (read(vsocket, &chr2, sizeof(char)) > 0) { ch[i] = chr2; i++; if (chr1 == '\r' && chr2 == '\n') { ch[i-2] = '\0'; chunk = (int) strtol(ch, NULL, 16); i = 0; break; } chr1 = chr2; } int w = chunk; char p; while (w > 0) { if (read(vsocket, &p, sizeof(char)) == FAILED) { fprintf(stderr, "Failed: read data\n"); return EXIT_FAILURE; } w--; fprintf(fw, "%c", p); } char ch1 = '#', ch2 = '#'; chunk = -1; char chr[BUFFER_LEN]; int n = 0; while (chunk != 0) { if (read(vsocket, &ch2, sizeof(char)) == FAILED) { fprintf(stderr, "Failed: read chunk or \\r\\n\n"); return EXIT_FAILURE; } if (ch1 == '\r' && ch2 == '\n') { while (ch2 != '\r') { if (read(vsocket, &ch2, sizeof(char)) == FAILED) { fprintf(stderr, "Failed: read chunk\n"); return EXIT_FAILURE; } chr[i] = ch2; i++; } ch1 = ch2; chr[i] = '\0'; i = 0; if (read(vsocket, &ch2, sizeof(char)) == FAILED) { fprintf(stderr, "Failed: read chunked data\n"); return EXIT_FAILURE; } if (ch1 == '\r' && ch2 == '\n') { chunk = (int) strtol(chr, NULL, 16); if (chunk == 0) break; n = chunk; while (n > 0) { if (read(vsocket, &p, sizeof(char)) == FAILED) { fprintf(stderr, "Failed: read chunked data\n"); return EXIT_FAILURE; } n--; fprintf(fw, "%c", p); } ch2 = '#'; } } ch1 = ch2; } fclose(fw); return EXIT_SUCCESS; }