A motor control class for driving two DC motors as part of RenBuggy
MotorController.h@3:2c9ebe06b127, 2014-01-21 (annotated)
- Committer:
- jf1452
- Date:
- Tue Jan 21 13:31:11 2014 +0000
- Revision:
- 3:2c9ebe06b127
- Parent:
- 2:2e59abd4b6b9
- Parent:
- 1:548ee2d0bb89
Update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1452 | 0:4aa0a6b134ea | 1 | /******************************************************************************* |
jf1452 | 0:4aa0a6b134ea | 2 | * RenBED DC Motor Drive for RenBuggy * |
jf1452 | 0:4aa0a6b134ea | 3 | * Copyright (c) 2014 Jon Fuge * |
jf1452 | 0:4aa0a6b134ea | 4 | * * |
jf1452 | 0:4aa0a6b134ea | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * |
jf1452 | 0:4aa0a6b134ea | 6 | * of this software and associated documentation files (the "Software"), to deal* |
jf1452 | 0:4aa0a6b134ea | 7 | * in the Software without restriction, including without limitation the rights * |
jf1452 | 0:4aa0a6b134ea | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * |
jf1452 | 0:4aa0a6b134ea | 9 | * copies of the Software, and to permit persons to whom the Software is * |
jf1452 | 0:4aa0a6b134ea | 10 | * furnished to do so, subject to the following conditions: * |
jf1452 | 0:4aa0a6b134ea | 11 | * * |
jf1452 | 0:4aa0a6b134ea | 12 | * The above copyright notice and this permission notice shall be included in * |
jf1452 | 0:4aa0a6b134ea | 13 | * all copies or substantial portions of the Software. * |
jf1452 | 0:4aa0a6b134ea | 14 | * * |
jf1452 | 0:4aa0a6b134ea | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * |
jf1452 | 0:4aa0a6b134ea | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * |
jf1452 | 0:4aa0a6b134ea | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * |
jf1452 | 0:4aa0a6b134ea | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * |
jf1452 | 0:4aa0a6b134ea | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* |
jf1452 | 0:4aa0a6b134ea | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * |
jf1452 | 0:4aa0a6b134ea | 21 | * THE SOFTWARE. * |
jf1452 | 0:4aa0a6b134ea | 22 | * * |
jf1452 | 0:4aa0a6b134ea | 23 | * DCMotorDrive.h * |
jf1452 | 0:4aa0a6b134ea | 24 | * * |
jf1452 | 0:4aa0a6b134ea | 25 | * V1.0 06/01/2014 First issue of code Jon Fuge * |
jf1452 | 0:4aa0a6b134ea | 26 | *******************************************************************************/ |
jf1452 | 0:4aa0a6b134ea | 27 | |
jf1452 | 0:4aa0a6b134ea | 28 | #ifndef _DCMOTORCONTROLLER_H |
jf1452 | 0:4aa0a6b134ea | 29 | #define _DCMOTORCONTROLLER_H |
jf1452 | 0:4aa0a6b134ea | 30 | |
jf1452 | 0:4aa0a6b134ea | 31 | #include "mbed.h" |
jf1452 | 0:4aa0a6b134ea | 32 | #include "DCMotorDrive.h" |
jf1452 | 0:4aa0a6b134ea | 33 | |
jf1452 | 0:4aa0a6b134ea | 34 | #define WHEEL_CIRCUMFERENCE 114.4 |
jf1452 | 0:4aa0a6b134ea | 35 | #define COUNTS_PER_ROTATION 64 |
jf1452 | 0:4aa0a6b134ea | 36 | #define PWM_SPEED_ADJUST 20 |
jf1452 | 0:4aa0a6b134ea | 37 | #define ROTATION_LIMIT 20 |
jf1452 | 0:4aa0a6b134ea | 38 | |
jf1452 | 0:4aa0a6b134ea | 39 | class MotorController |
jf1452 | 0:4aa0a6b134ea | 40 | { |
jf1452 | 0:4aa0a6b134ea | 41 | public: |
jf1452 | 1:548ee2d0bb89 | 42 | MotorController(PinName LMotorOut, PinName LBrakeOut, PinName LSensorIn, PinName LMotorOut, PinName RBrakeOut, PinName LSensorIn); |
jf1452 | 1:548ee2d0bb89 | 43 | void Forwards(int ForwardCount); |
jf1452 | 1:548ee2d0bb89 | 44 | void ResetOdometer(void); |
jf1452 | 1:548ee2d0bb89 | 45 | int ReadOdometer(void); |
jf1452 | 1:548ee2d0bb89 | 46 | int ReadLeftOdometer(void); |
jf1452 | 1:548ee2d0bb89 | 47 | int ReadRightOdometer(void); |
jf1452 | 0:4aa0a6b134ea | 48 | private: |
jf1452 | 1:548ee2d0bb89 | 49 | DCMotorDrive _LeftMotor; |
jf1452 | 1:548ee2d0bb89 | 50 | DCMotorDrive _RightMotor; |
jf1452 | 1:548ee2d0bb89 | 51 | int LeftMotorSpeed; |
jf1452 | 1:548ee2d0bb89 | 52 | int RightMotorSpeed; |
jf1452 | 1:548ee2d0bb89 | 53 | int LeftToRightRatio; |
jf1452 | 1:548ee2d0bb89 | 54 | int DistanceToTravel; |
jf1452 | 1:548ee2d0bb89 | 55 | Ticker trackomatic; |
jf1452 | 1:548ee2d0bb89 | 56 | |
jf1452 | 1:548ee2d0bb89 | 57 | void MatchSpeeds(void); |
jf1452 | 1:548ee2d0bb89 | 58 | void UpdatePwms(void); |
jf1452 | 0:4aa0a6b134ea | 59 | }; |
jf1452 | 0:4aa0a6b134ea | 60 | |
jf1452 | 2:2e59abd4b6b9 | 61 | #endif // _DCMOTORCONTROLLER_H |