Directions for converting this file to an executable program using Dev-C++ A free copy of Dev-C++ is available here: http://sourceforge.net/projects/orwelldevcpp/ Dev-C++ is not available for Apple computers as far as I am aware. You need to have Dev-C++ installed on your computer to compile the code on this page and run the program. The code starting with the line "#include " and ending with "} // end of main() block" provides the C language code for a program that does calculations helpful in creating driving code for ActivityBot robots. You can used the Integrated Development Environment (IDE) named Dev-C++ to create an executable program using the code below. Here are the directions for compiling the program in executable form. 1.Start Dev-C++. 2.Open the File menu and select New. Then select Source File. 3. Copy the code below, starting with the line "#include " and ending with "} // end of main() block" 4. Click the mouse in the text window of Dev-C++ and paste in the copied code text 5. Open the File menu and select Save, which opens a Save As dialog box. In the dialog box, open the drop-down labeled Save as type and select c source files(*.c). 6. In the file name slot enter a name for the file, for example, driving ActivityBot 7. At the top of the dialog box there is a Save in slot, which determines where the file will be saved. Make sure you know the location where you are saving your file so that you can find it later. 8. Now click the Save button to save your program file. 9. Run the program by opening the Execute menu and selecting Compile and Run. If there are no errors in the program, a small program window will open. If the program does not run, you probably made a mistake and did not copy all of the code below. 10. When the program opens in a small terminal window it will provide directions for running the program. Read these carefully and run the program to make some calculations for driving the robot. The program will help you write code for driving the robot in a straight line for a specified distance and turning the robot by three different methods, specifying the number of degrees for the turn. 11. After you have compiled and run the program, you should look in the folder where you saved the program. There you should find a file named driving ActivityBot.c (that is if you used the suggested name). Also you should find a file named driving ActivityBot.exe The file with the extension .c is the file to open with Dev-C++ if you wanted to edit the program (not recommended unless you save a separate copy first). The file with the extension .exe is the executable file. Open this file to run the program without the assistance of Dev-C++. In fact, you could copy the .exe file to another Windows computer and run it there even if that computer did not have Dev-C++ installed. Code starts with next line below, do not copy this line or anything above this line #include // calculations for driving ActivityBot // code by Jeffrey La Favre int main() { // start of main() block of code while(1) { int program; printf("This program does calculations for driving code for ActivityBot\n"); printf("Press 1 for driving straight, Press 2 for pivot or 0 radius turn \n"); printf("Press 3 for arc turn, Press 4 for accurate arc turns\nPress 5 for more information\nPress Enter key after making your selection.\n"); scanf("%d", &program); system ( "cls" ); //clears the screen for windows computers I think, may have to disable this line if it causes problems if (program == 1) // calculate the number of ticks to move ActivityBot forward or backward a specified distance in mm { float distance, ticks; //create two variables of the floating point type named distance and ticks printf("Program number 1 does calculations for driving straight \n"); printf("a specific distance in millimeters.\n\n"); printf("Enter the distance to travel in millimeters and then press the Enter key\n\n"); scanf("%f", &distance); //get input from keyboard and store it in variable named distance ticks = distance / 3.25; // divide value stored in distance by 3.25 and store answer in variable named ticks printf("\n To travel %.0f mm forward, use %.0f ticks for each wheel\n", distance, ticks); //display number of ticks to move desired mm printf("The code would be like this: drive_goto(%.0f, %.0f);\n\n", ticks, ticks); //display code to move forward desired mm printf("\nTo travel %.0f mm backward, use -%.0f ticks for each wheel\n", distance, ticks); printf("The code would be like this: drive_goto(-%.0f, -%.0f);\n\n", ticks, ticks); //display code to move backward desired mm printf("Press Enter Key to continue."); getchar(); //purge Enter character getchar(); //halt program waiting for user to press Enter key system ( "cls" ); //clears the screen for windows computers I think, may have to disable this line if it causes problems } // end of if (program == 1) else if(program == 2) { // calculate the number of ticks to make ActivityBot turn a specified number of degrees. float degrees, ticks; //create two variables named degrees and ticks of the floating point data type printf("Program 2 does calculations for pivot and zero radius turns. \n\n"); printf("Enter the degrees to turn and then press the Enter key\n\n"); scanf("%f", °rees); //get input from keyboard and store in the variable named degrees ticks = degrees * 0.5672; //calculate the number of ticks required to turn specified degrees printf("\n To turn %.0f degrees with a pivot, use %.0f ticks for one wheel and 0 ticks\n", degrees, ticks); printf("for the other wheel.\n\n"); printf("The code to pivot right would be like this: drive_goto(%.0f, 0);\n\n", ticks); printf("The code to pivot left would be like this: drive_goto(0, %.0f);\n\n", ticks); printf("\nTo zero radius turn, assign half the ticks to one wheel as a positive value\n "); printf("and the other half to the other wheel as a negative value. "); printf("Let us take the\n example of a 90 degree turn, which takes 51 ticks.\n"); printf("Half of 51 is 25.5 ticks. Therefore, one wheel gets 26 ticks the other 25 ticks\n"); printf("Code for zero radius turn 90 degrees right would be:\n"); printf("drive_goto(26, -25)\n"); printf("Code for zero radius turn 90 degrees left would be:\n"); printf("drive_goto(-25, 26)\n\n\n\n"); printf("Press Enter Key to continue."); getchar(); //purge Enter character getchar(); //halt program waiting for user to press Enter key system ( "cls" ); //clears the screen for windows computers I think, may have to disable this line if it causes problems } // emd of else if(program == 2) else if(program == 3) { /* program to calculate wheel speeds for a robot arc turn of specified number of degrees */ float ro, ri, spo, spi, tp; float co, c1d, degrees, sow, doc; // ro = radius of outboard wheel in mm, ri = radius of inboard wheel, spo = speed of outboard wheel in ticks per sec, //spi = speed of inboard wheel //co = circumference of outboard circle in mm, c1d = co/360, degrees = degrees to turn, sow = speed of outboard wheel in mm/ms, //tp = time for pause in ms, doc = distance to travel on outboard circle in mm printf("Program 3 calculates the speeds for wheels of ActivityBot\n"); printf("for arc turns of specified degrees using the function drive_ramp \n"); printf("Keep in mind that the maximum wheel speed is 128.\n\n"); printf("Enter the outside radius of the turn in millimeters (no less than 106) and then press Enter key \n\n"); scanf("%f", &ro); //get input from keyboard and store in variable named ro ri = ro - 106; // subtract 106 mm from ro to get ri printf("Enter the desired speed of outboard wheel (maximum value is 128) and then press Enter key \n\n"); scanf("%f", &spo); //get input from keyboard and store in variable named spo printf("Enter the desired degrees for the turn and then press Enter key \n\n"); scanf("%f", °rees); //get input from keyboard and store in variable named degrees spi = spo * ri / ro; //speed of inboard wheel (spi) will be ratio of inboard and outboard radii multiplied by speed of outboard wheel co = 6.283 * ro; // calculate circumference of outboard circle and store in variable named co c1d = co / 360; //calculate c1d, distance in mm along circumference of outboard circle per degree doc = c1d * degrees; // calculate distance to travel in mm (doc) for specified number of degrees sow = spo * 0.00325; // converts outboard wheel speed (spo) from ticks per second to mm per millisecond (sow) tp = doc / sow; // calculates time in milliseconds to run (td value goes in the pause() function after the drive function) printf("You specified a %.0f degree arc turn with an outside radius of %.0f mm \n", degrees, ro); printf("and a speed of %.0f for the outboard wheel. \nUse a speed of %.0f for inboard wheel\n", spo, spi); printf("The pause after drive_ramp() should be %.0f milliseconds\n", tp); printf("For a right turn write the code like this: drive_ramp(%.0f, %.0f);\n", spo, spi); printf("The next line should be this: pause(%.0f);\n", tp); printf("For a left turn write the code like this: drive_ramp(%.0f, %.0f);\n", spi, spo); printf("The next code line should be this: pause(%.0f);\n", tp); printf("Keep in mind that additional code will be needed before and after the turn\n to start and stop the robot\n\n\n\n" ); printf("Press Enter Key to continue."); getchar(); //purge Enter character getchar(); //halt program waiting for user to press Enter key system ( "cls" ); //clears the screen for windows computers I think, may have to disable this line if it causes problems } // end of else if(program == 3) else if(program == 4) { float ro, ri, spo, spi; float co, c1d, degrees, doc, ticks; // ro = radius of outboard wheel in mm, ri = radius of inboard wheel, spo = speed of outboard wheel in ticks per sec, //spi = speed of inboard wheel //co = circumference of outboard circle in mm, c1d = co/360, degrees = degrees to turn, ticks = number of ticks for outboard wheel //doc = distance to travel on outboard circle in mm printf("Program 4 calculates the speeds for wheels of ActivityBot\n"); printf("for arc turns of specified degrees using the functions drive_ramp \n and drive_getTicks()\n "); printf("Keep in mind that the maximum wheel speed is 128.\n\n"); printf("Enter the outside radius of the turn in millimeters (no less than 106) and then press Enter key \n\n"); scanf("%f", &ro); //get input from keyboard and store in variable named ro ri = ro - 106; // subtract 106 mm from ro to get ri printf("Enter the desired speed of outboard wheel (maximum value is 128) and then press Enter key \n\n"); scanf("%f", &spo); //get input from keyboard and store in variable named spo printf("Enter the desired degrees for the turn and then press Enter key \n\n"); scanf("%f", °rees); //get input from keyboard and store in variable named degrees spi = spo * ri / ro; //speed of inboard wheel (spi) will be ratio of inboard and outboard radii multiplied by speed of outboard co = 6.283 * ro; // calculate circumference of outboard circle and store in variable named co c1d = co / 360; //calculate c1d, distance in mm along circumference of outboard circle per degree doc = c1d * degrees; // calculate distance to travel in mm (doc) for specified number of degrees ticks = doc / 3.25; // convert distance to travel in mm to number of wheel ticks printf("You specified a %.0f degree arc turn with an outside radius of %.0f mm \n", degrees, ro); printf("and a speed of %.0f for the outboard wheel. \nUse a speed of %.0f for inboard wheel\n", spo, spi); printf("The number of ticks for the outboard wheel is %.0f ticks\n", ticks); printf("For a right turn write the code like this: drive_ramp(%.0f, %.0f);\n", spo, spi); printf("For a left turn write the code like this: drive_ramp(%.0f, %.0f);\n", spi, spo); printf("Consult paper on using the function drive_getTicks() for complete \ncoding guidance\n "); printf("Press Enter Key to continue."); getchar(); //purge Enter character getchar(); //halt program waiting for user to press Enter key system ( "cls" ); //clears the screen for windows computers I think, may have to disable this line if it causes problems } //end of else if (program == 4) else if(program == 5) { //general information goes here printf(" The drive_goto() function is used to make the wheels turn a specified amount.\n"); printf("The encoder for each wheel sends 64 ticks to the microprocessor for each \n"); printf("revolution of the wheel. Each wheel tick is equivalent to 3.25 mm of movement.\n"); printf("The format for the drive_goto() function is:\n"); printf(" drive_goto(number of ticks for left wheel, number of ticks for right wheel)\n"); printf("For example, drive_goto(234, 234) will cause both wheels to rotate forward 234 \nticks.\n\n"); printf("The robot makes a pivot turn by rotating one wheel only.\n"); printf("The robot makes a zero radius turn by rotating both wheels, but in opposite\ndirections. " ); printf("To execute a full 360 degree turn, the total ticks required is\n204.3 ticks "); printf("or 0.5672 ticks per degree.\n"); printf("For example, drive_goto(51, 0) will cause the robot to pivot turn 90 degrees \nright.\n"); printf("drive_goto(26, -25) will cause the robot to zero radius turn 90 degrees right.\n\n"); printf("Press Enter Key to continue."); getchar(); //purge Enter character getchar(); //halt program waiting for user to press Enter key system ( "cls" ); //clears the screen for windows computers I think, may have to disable this line if it causes problems } else { printf("You did not press a valid number.\n\n"); getchar();// purge enter key } // end of else just 3 lines above } // end of highest level while } // end of main() block