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.
TimedMovement.cpp
00001 /********************************************************* 00002 *TimedMovement.cpp * 00003 *Author: Elijah Orr * 00004 * * 00005 *A library of functions that can be used to control the * 00006 *RenBuggy. * 00007 *********************************************************/ 00008 00009 #ifndef TIMEDMOVEMENT_C 00010 #define TIMEDMOVEMENT_C 00011 00012 /* necessary includes */ 00013 #include "mbed.h" 00014 #include "TimedMovement.h" 00015 00016 /* PwmOut is a class included in the mbed.h library that allows 00017 a pin to be configured as a PWM output. This is used to control 00018 the speed of the motors. Lmotor and Rmotor are chosen names for 00019 the pins, LeftMotorPin and RightMotorPin (see TimedMovement.h) 00020 specify the physical pins to be used. */ 00021 PwmOut Lmotor(LeftMotorPin); 00022 PwmOut Rmotor(RightMotorPin); 00023 00024 /* Function definitions contain the code that will execute when 00025 the function is called. These must have the same return type 00026 and parameters as the function declarations. */ 00027 00028 /**************************************************************** 00029 * Function: forward() * 00030 * * 00031 * Moves the RenBuggy directly forwards * 00032 * * 00033 * Inputs: A floating point value representing the length of * 00034 * time the buggy will move for * 00035 * * 00036 * Returns: none * 00037 ****************************************************************/ 00038 extern void forward(float time) 00039 { 00040 /* Lmotor and Rmotor are set to 1.0 (i.e. the motors will 00041 operate at full speed). As both motors will move at the 00042 same speed, the RenBuggy will go directly forward. */ 00043 Lmotor = Rmotor = 1.0; 00044 /* the program will wait here for the length of time passed 00045 to the function before continuing. wait() is a function 00046 provided from mbed.h */ 00047 wait(time); 00048 stop(); 00049 } 00050 00051 /**************************************************************** 00052 * Function: left() * 00053 * * 00054 * Turns the RenBuggy to the left * 00055 * * 00056 * Inputs: A floating point value representing the length of * 00057 * time the buggy will turn for * 00058 * * 00059 * Returns: none * 00060 ****************************************************************/ 00061 extern void left(float time) 00062 { 00063 Rmotor = 1.0; 00064 Lmotor = 0.2; 00065 wait(time); 00066 stop(); 00067 } 00068 00069 /**************************************************************** 00070 * Function: right() * 00071 * * 00072 * Turns the RenBuggy to the right * 00073 * * 00074 * Inputs: A floating point value representing the length of * 00075 * time the buggy will turn for * 00076 * * 00077 * Returns: none * 00078 ****************************************************************/ 00079 extern void right(float time) 00080 { 00081 Lmotor = 1.0; 00082 Rmotor = 0.2; 00083 wait(time); 00084 stop(); 00085 } 00086 00087 /**************************************************************** 00088 * Function: stop() * 00089 * * 00090 * Brings the RenBuggy to a complete stop * 00091 * * 00092 * Inputs: none * 00093 * * 00094 * Returns: none * 00095 ****************************************************************/ 00096 void stop() 00097 { 00098 Lmotor = Rmotor = 0; 00099 } 00100 00101 #endif // TIMEDMOVEMENT_C
Generated on Sat Jul 16 2022 20:54:35 by
1.7.2