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.
Dependencies: GPS2 L3GD20 LSM303DLHC2 PID mbed SDFileSystem
Fork of GPSNavigation by
Actuator.h@12:273479524c71, 2015-04-29 (annotated)
- Committer:
- Spilly
- Date:
- Wed Apr 29 18:07:43 2015 +0000
- Revision:
- 12:273479524c71
- Parent:
- 8:c77ab7615b21
- Child:
- 14:fd20b7ac8de8
Updated comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Spilly | 8:c77ab7615b21 | 1 | /*************************************************************************************************************************************************************/ |
Spilly | 8:c77ab7615b21 | 2 | // Created by: Ryan Spillman |
Spilly | 8:c77ab7615b21 | 3 | // |
Spilly | 8:c77ab7615b21 | 4 | // Last updated 4/9/2015 |
Spilly | 8:c77ab7615b21 | 5 | // |
Spilly | 8:c77ab7615b21 | 6 | // Contains functions for controlling L298n H-bridge which controls the linear actuator |
Spilly | 8:c77ab7615b21 | 7 | /*************************************************************************************************************************************************************/ |
Spilly | 8:c77ab7615b21 | 8 | |
Spilly | 8:c77ab7615b21 | 9 | #define Actuator_h |
Spilly | 8:c77ab7615b21 | 10 | |
Spilly | 8:c77ab7615b21 | 11 | //L298n connections |
Spilly | 8:c77ab7615b21 | 12 | DigitalOut pinI1(D7); |
Spilly | 8:c77ab7615b21 | 13 | DigitalOut pinI2(PTC12); //D8 |
Spilly | 8:c77ab7615b21 | 14 | PwmOut ENA(D6); |
Spilly | 8:c77ab7615b21 | 15 | /*************************************************************************************************************************************************************/ |
Spilly | 8:c77ab7615b21 | 16 | // L298n (H-Bridge) Functions |
Spilly | 8:c77ab7615b21 | 17 | /*************************************************************************************************************************************************************/ |
Spilly | 8:c77ab7615b21 | 18 | |
Spilly | 8:c77ab7615b21 | 19 | void turnStop(float valueOne, float valueTwo) |
Spilly | 8:c77ab7615b21 | 20 | { |
Spilly | 8:c77ab7615b21 | 21 | pinI1 = 0; |
Spilly | 8:c77ab7615b21 | 22 | pinI2 = 0; |
Spilly | 8:c77ab7615b21 | 23 | ENA = valueOne; |
Spilly | 8:c77ab7615b21 | 24 | } |
Spilly | 8:c77ab7615b21 | 25 | |
Spilly | 8:c77ab7615b21 | 26 | void turnLeft(float valueOne, float valueTwo) |
Spilly | 8:c77ab7615b21 | 27 | { |
Spilly | 8:c77ab7615b21 | 28 | pinI1 = 0; |
Spilly | 8:c77ab7615b21 | 29 | pinI2 = 1; |
Spilly | 8:c77ab7615b21 | 30 | ENA = valueOne; |
Spilly | 8:c77ab7615b21 | 31 | } |
Spilly | 8:c77ab7615b21 | 32 | |
Spilly | 8:c77ab7615b21 | 33 | void turnRight(float valueOne, float valueTwo) |
Spilly | 8:c77ab7615b21 | 34 | { |
Spilly | 8:c77ab7615b21 | 35 | pinI1 = 1; |
Spilly | 8:c77ab7615b21 | 36 | pinI2 = 0; |
Spilly | 8:c77ab7615b21 | 37 | ENA = valueOne; |
Spilly | 8:c77ab7615b21 | 38 | } |
Spilly | 8:c77ab7615b21 | 39 | |
Spilly | 12:273479524c71 | 40 | //calculate an equal distance from acuator center point that the acutator can physically move to without hitting limit switch |
Spilly | 8:c77ab7615b21 | 41 | float calcEnds(float center, float max, float min) |
Spilly | 8:c77ab7615b21 | 42 | { |
Spilly | 8:c77ab7615b21 | 43 | float upperRange = max - center; |
Spilly | 8:c77ab7615b21 | 44 | float lowerRange = center - min; |
Spilly | 8:c77ab7615b21 | 45 | if(upperRange < lowerRange) |
Spilly | 8:c77ab7615b21 | 46 | { |
Spilly | 8:c77ab7615b21 | 47 | return upperRange; |
Spilly | 8:c77ab7615b21 | 48 | } |
Spilly | 8:c77ab7615b21 | 49 | else |
Spilly | 8:c77ab7615b21 | 50 | { |
Spilly | 8:c77ab7615b21 | 51 | return lowerRange; |
Spilly | 8:c77ab7615b21 | 52 | } |
Spilly | 8:c77ab7615b21 | 53 | } |