Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /********************************************************* 00002 *RenBuggyServoCtrl * 00003 *Author: Elijah Orr * 00004 * * 00005 *This program demonstates use of a library of functions * 00006 *(ServoDrive) to control the movement of the RenBuggy. * 00007 * * 00008 *********************************************************/ 00009 00010 /* include the libraries in use in this program. ServoDrive is a library that can 00011 be used to control a steering servo and two drive motors. */ 00012 #include "mbed.h" 00013 #include "ServoDrive.h" 00014 00015 /* open the main function */ 00016 int main() 00017 { 00018 /* instead of using wait() to make delays in the program, for loops will be used 00019 as the wait function caused some buggy behaviour. The for loops will require a 00020 variable so it is declared at the top of the main, this is where all variables 00021 used in the main function should be declared. */ 00022 int i; 00023 00024 /* the first function to be called from ServoDrive.h is used to configure the PWM 00025 output that controls the servo. Both parameters are values in micro seconds that 00026 correspond to the period (20000) and pulsewidth (1500) of the PWM signal. 1500 00027 corresponds the the servo in centre postion after the line executes. */ 00028 configurePWM(20000, 1500); 00029 00030 /* function to start the drive motors going is called */ 00031 go(); 00032 00033 /* the first delay goes here to make the buggy move forward for a time before 00034 turning. The for loop will initialise the variable i to be 0, and enter the 00035 program into a loop that will repeatedly check that i < 25000000 and increment 00036 i as long as the statement is true. When i = 25000000 the program will exit the 00037 loop and move on to the next line. */ 00038 for(i=0;i<25000000;i++){} 00039 00040 /* the function to set the direction the servo controlled wheel is facing is 00041 called. It takes a single parameter that can be any number between 0 and 90, 00042 which represents a value in degrees where 45 points the wheel directly forward. */ 00043 setDirection(70); 00044 for(i=0;i<25000000;i++){} 00045 00046 setDirection(10); 00047 for(i=0;i<25000000;i++){} 00048 00049 setDirection(90); 00050 for(i=0;i<25000000;i++){} 00051 00052 setDirection(30); 00053 for(i=0;i<25000000;i++){} 00054 00055 /* function to stop the drive motors is called */ 00056 stop(); 00057 00058 return 0; 00059 } 00060
Generated on Mon Aug 8 2022 17:27:12 by
