A program that allows control of the RenBuggy by altering the relative speeds of the wheels.

Dependencies:   mbed-renbed

Committer:
RenBuggy
Date:
Fri Mar 11 10:36:38 2016 +0000
Revision:
0:9870f526ddd1
Child:
1:dd956fbd7e95
version 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RenBuggy 0:9870f526ddd1 1 /*********************************************************
RenBuggy 0:9870f526ddd1 2 *TimedMovement.cpp *
RenBuggy 0:9870f526ddd1 3 *Author: Elijah Orr *
RenBuggy 0:9870f526ddd1 4 * *
RenBuggy 0:9870f526ddd1 5 *A library of functions that can be used to control the *
RenBuggy 0:9870f526ddd1 6 *RenBuggy. *
RenBuggy 0:9870f526ddd1 7 *********************************************************/
RenBuggy 0:9870f526ddd1 8
RenBuggy 0:9870f526ddd1 9 #ifndef TIMEDMOVEMENT_C
RenBuggy 0:9870f526ddd1 10 #define TIMEDMOVEMENT_C
RenBuggy 0:9870f526ddd1 11
RenBuggy 0:9870f526ddd1 12 /* necessary includes */
RenBuggy 0:9870f526ddd1 13 #include "mbed.h"
RenBuggy 0:9870f526ddd1 14 #include "TimedMovement.h"
RenBuggy 0:9870f526ddd1 15
RenBuggy 0:9870f526ddd1 16 /* PwmOut is a class included in the mbed.h library that allows
RenBuggy 0:9870f526ddd1 17 a pin to be configured as a PWM output. This is used to control
RenBuggy 0:9870f526ddd1 18 the speed of the motors. Lmotor and Rmotor are chosen names for
RenBuggy 0:9870f526ddd1 19 the pins, LeftMotorPin and RightMotorPin (see TimedMovement.h)
RenBuggy 0:9870f526ddd1 20 specify the physical pins to be used. */
RenBuggy 0:9870f526ddd1 21 PwmOut Lmotor(LeftMotorPin);
RenBuggy 0:9870f526ddd1 22 PwmOut Rmotor(RightMotorPin);
RenBuggy 0:9870f526ddd1 23
RenBuggy 0:9870f526ddd1 24 /* Function definitions contain the code that will execute when
RenBuggy 0:9870f526ddd1 25 the function is called. These must have the same return type
RenBuggy 0:9870f526ddd1 26 and parameters as the function declarations. */
RenBuggy 0:9870f526ddd1 27
RenBuggy 0:9870f526ddd1 28 /****************************************************************
RenBuggy 0:9870f526ddd1 29 * Function: forward() *
RenBuggy 0:9870f526ddd1 30 * *
RenBuggy 0:9870f526ddd1 31 * Moves the RenBuggy directly forwards *
RenBuggy 0:9870f526ddd1 32 * *
RenBuggy 0:9870f526ddd1 33 * Inputs: A floating point value representing the length of *
RenBuggy 0:9870f526ddd1 34 * time the buggy will move for *
RenBuggy 0:9870f526ddd1 35 * *
RenBuggy 0:9870f526ddd1 36 * Returns: none *
RenBuggy 0:9870f526ddd1 37 ****************************************************************/
RenBuggy 0:9870f526ddd1 38 extern void forward(float time)
RenBuggy 0:9870f526ddd1 39 {
RenBuggy 0:9870f526ddd1 40 /* Lmotor and Rmotor are set to 1.0 (i.e. the motors will
RenBuggy 0:9870f526ddd1 41 operate at full speed). As both motors will move at the
RenBuggy 0:9870f526ddd1 42 same speed, the RenBuggy will go directly forward. */
RenBuggy 0:9870f526ddd1 43 Lmotor = Rmotor = 1.0;
RenBuggy 0:9870f526ddd1 44 /* the program will wait here for the length of time passed
RenBuggy 0:9870f526ddd1 45 to the function before continuing. wait() is a function
RenBuggy 0:9870f526ddd1 46 provided from mbed.h; a loop could be used instead. */
RenBuggy 0:9870f526ddd1 47 wait(time);
RenBuggy 0:9870f526ddd1 48 }
RenBuggy 0:9870f526ddd1 49
RenBuggy 0:9870f526ddd1 50 /****************************************************************
RenBuggy 0:9870f526ddd1 51 * Function: left() *
RenBuggy 0:9870f526ddd1 52 * *
RenBuggy 0:9870f526ddd1 53 * Turns the RenBuggy to the left *
RenBuggy 0:9870f526ddd1 54 * *
RenBuggy 0:9870f526ddd1 55 * Inputs: A floating point value representing the length of *
RenBuggy 0:9870f526ddd1 56 * time the buggy will turn for *
RenBuggy 0:9870f526ddd1 57 * *
RenBuggy 0:9870f526ddd1 58 * Returns: none *
RenBuggy 0:9870f526ddd1 59 ****************************************************************/
RenBuggy 0:9870f526ddd1 60 extern void left(float time)
RenBuggy 0:9870f526ddd1 61 {
RenBuggy 0:9870f526ddd1 62 Rmotor = 1.0;
RenBuggy 0:9870f526ddd1 63 Lmotor = 0.2;
RenBuggy 0:9870f526ddd1 64 wait(time);
RenBuggy 0:9870f526ddd1 65 }
RenBuggy 0:9870f526ddd1 66
RenBuggy 0:9870f526ddd1 67 /****************************************************************
RenBuggy 0:9870f526ddd1 68 * Function: right() *
RenBuggy 0:9870f526ddd1 69 * *
RenBuggy 0:9870f526ddd1 70 * Turns the RenBuggy to the right *
RenBuggy 0:9870f526ddd1 71 * *
RenBuggy 0:9870f526ddd1 72 * Inputs: A floating point value representing the length of *
RenBuggy 0:9870f526ddd1 73 * time the buggy will turn for *
RenBuggy 0:9870f526ddd1 74 * *
RenBuggy 0:9870f526ddd1 75 * Returns: none *
RenBuggy 0:9870f526ddd1 76 ****************************************************************/
RenBuggy 0:9870f526ddd1 77 extern void right(float time)
RenBuggy 0:9870f526ddd1 78 {
RenBuggy 0:9870f526ddd1 79 Lmotor = 1.0;
RenBuggy 0:9870f526ddd1 80 Rmotor = 0.2;
RenBuggy 0:9870f526ddd1 81 wait(time);
RenBuggy 0:9870f526ddd1 82 }
RenBuggy 0:9870f526ddd1 83
RenBuggy 0:9870f526ddd1 84 /****************************************************************
RenBuggy 0:9870f526ddd1 85 * Function: stop() *
RenBuggy 0:9870f526ddd1 86 * *
RenBuggy 0:9870f526ddd1 87 * Brings the RenBuggy to a complete stop *
RenBuggy 0:9870f526ddd1 88 * *
RenBuggy 0:9870f526ddd1 89 * Inputs: none *
RenBuggy 0:9870f526ddd1 90 * *
RenBuggy 0:9870f526ddd1 91 * Returns: none *
RenBuggy 0:9870f526ddd1 92 ****************************************************************/
RenBuggy 0:9870f526ddd1 93 extern void stop()
RenBuggy 0:9870f526ddd1 94 {
RenBuggy 0:9870f526ddd1 95 Lmotor = Rmotor = 0;
RenBuggy 0:9870f526ddd1 96 }
RenBuggy 0:9870f526ddd1 97
RenBuggy 0:9870f526ddd1 98 #endif // TIMEDMOVEMENT_C