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.
MotorController.cpp@0:4aa0a6b134ea, 2014-01-15 (annotated)
- Committer:
- jf1452
- Date:
- Wed Jan 15 11:48:41 2014 +0000
- Revision:
- 0:4aa0a6b134ea
- Child:
- 1:548ee2d0bb89
Simplified class for DC motor drive using PWM
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_C |
| jf1452 | 0:4aa0a6b134ea | 29 | #define _DCMOTORCONTROLLER_C |
| jf1452 | 0:4aa0a6b134ea | 30 | |
| jf1452 | 0:4aa0a6b134ea | 31 | #include "mbed.h" |
| jf1452 | 0:4aa0a6b134ea | 32 | #include "MotorController.h" |
| jf1452 | 0:4aa0a6b134ea | 33 | |
| jf1452 | 0:4aa0a6b134ea | 34 | MotorController::MotorController(PinName LMotorOut, PinName LSensorIn, PinName RMotorOut, PinName RSensorIn): |
| jf1452 | 0:4aa0a6b134ea | 35 | _LeftMotor(p5, p7), _RightMotor(p6, p8) |
| jf1452 | 0:4aa0a6b134ea | 36 | { |
| jf1452 | 0:4aa0a6b134ea | 37 | _LeftMotor.SetMotorPwmAndRevolutions(18000,32); |
| jf1452 | 0:4aa0a6b134ea | 38 | _RightMotor.SetMotorPwmAndRevolutions(18000,32); |
| jf1452 | 0:4aa0a6b134ea | 39 | } |
| jf1452 | 0:4aa0a6b134ea | 40 | |
| jf1452 | 0:4aa0a6b134ea | 41 | void MotorController::LeftResetOdometer(void) |
| jf1452 | 0:4aa0a6b134ea | 42 | { |
| jf1452 | 0:4aa0a6b134ea | 43 | _LeftMotor.ResetOdometer(); |
| jf1452 | 0:4aa0a6b134ea | 44 | } |
| jf1452 | 0:4aa0a6b134ea | 45 | |
| jf1452 | 0:4aa0a6b134ea | 46 | int MotorController::LeftReadOdometer(void) |
| jf1452 | 0:4aa0a6b134ea | 47 | { |
| jf1452 | 0:4aa0a6b134ea | 48 | return(_LeftMotor.ReadOdometer()); |
| jf1452 | 0:4aa0a6b134ea | 49 | } |
| jf1452 | 0:4aa0a6b134ea | 50 | |
| jf1452 | 0:4aa0a6b134ea | 51 | int MotorController::LeftReadCaptureTime(void) |
| jf1452 | 0:4aa0a6b134ea | 52 | { |
| jf1452 | 0:4aa0a6b134ea | 53 | return(_LeftMotor.ReadCaptureTime()); |
| jf1452 | 0:4aa0a6b134ea | 54 | } |
| jf1452 | 0:4aa0a6b134ea | 55 | |
| jf1452 | 0:4aa0a6b134ea | 56 | int MotorController::LeftReadLastTime(void) |
| jf1452 | 0:4aa0a6b134ea | 57 | { |
| jf1452 | 0:4aa0a6b134ea | 58 | return(_LeftMotor.GetLastPulseTime()); |
| jf1452 | 0:4aa0a6b134ea | 59 | } |
| jf1452 | 0:4aa0a6b134ea | 60 | |
| jf1452 | 0:4aa0a6b134ea | 61 | void MotorController::RightResetOdometer(void) |
| jf1452 | 0:4aa0a6b134ea | 62 | { |
| jf1452 | 0:4aa0a6b134ea | 63 | _RightMotor.ResetOdometer(); |
| jf1452 | 0:4aa0a6b134ea | 64 | } |
| jf1452 | 0:4aa0a6b134ea | 65 | |
| jf1452 | 0:4aa0a6b134ea | 66 | int MotorController::RightReadOdometer(void) |
| jf1452 | 0:4aa0a6b134ea | 67 | { |
| jf1452 | 0:4aa0a6b134ea | 68 | return(_RightMotor.ReadOdometer()); |
| jf1452 | 0:4aa0a6b134ea | 69 | } |
| jf1452 | 0:4aa0a6b134ea | 70 | |
| jf1452 | 0:4aa0a6b134ea | 71 | int MotorController::RightReadCaptureTime(void) |
| jf1452 | 0:4aa0a6b134ea | 72 | { |
| jf1452 | 0:4aa0a6b134ea | 73 | return(_RightMotor.ReadCaptureTime()); |
| jf1452 | 0:4aa0a6b134ea | 74 | } |
| jf1452 | 0:4aa0a6b134ea | 75 | |
| jf1452 | 0:4aa0a6b134ea | 76 | int MotorController::RightReadLastTime(void) |
| jf1452 | 0:4aa0a6b134ea | 77 | { |
| jf1452 | 0:4aa0a6b134ea | 78 | return(_RightMotor.GetLastPulseTime()); |
| jf1452 | 0:4aa0a6b134ea | 79 | } |
| jf1452 | 0:4aa0a6b134ea | 80 | #endif |