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.
Fork of IEEE_14_Freescale by
motor.cpp@1:c28fac16a109, 2013-11-17 (annotated)
- Committer:
- soonerbot
- Date:
- Sun Nov 17 03:05:35 2013 +0000
- Revision:
- 1:c28fac16a109
Added encoder direction settings and setup motors and encoders
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soonerbot | 1:c28fac16a109 | 1 | #include "motor.h" |
soonerbot | 1:c28fac16a109 | 2 | |
soonerbot | 1:c28fac16a109 | 3 | motor::motor(PinName APin,PinName BPin, PinName PWMPin) : |
soonerbot | 1:c28fac16a109 | 4 | OutA(APin), OutB(BPin), OutPWM(PWMPin){ |
soonerbot | 1:c28fac16a109 | 5 | |
soonerbot | 1:c28fac16a109 | 6 | //blah |
soonerbot | 1:c28fac16a109 | 7 | brake(); |
soonerbot | 1:c28fac16a109 | 8 | reversed=0; |
soonerbot | 1:c28fac16a109 | 9 | } |
soonerbot | 1:c28fac16a109 | 10 | |
soonerbot | 1:c28fac16a109 | 11 | int motor::brake(){ |
soonerbot | 1:c28fac16a109 | 12 | OutA=OutB=0; |
soonerbot | 1:c28fac16a109 | 13 | OutPWM=1; |
soonerbot | 1:c28fac16a109 | 14 | return 1; |
soonerbot | 1:c28fac16a109 | 15 | } |
soonerbot | 1:c28fac16a109 | 16 | |
soonerbot | 1:c28fac16a109 | 17 | int motor::setPower( double power) { |
soonerbot | 1:c28fac16a109 | 18 | if((power>=0)^reversed){ |
soonerbot | 1:c28fac16a109 | 19 | OutA=1; |
soonerbot | 1:c28fac16a109 | 20 | OutB=0; |
soonerbot | 1:c28fac16a109 | 21 | } else { |
soonerbot | 1:c28fac16a109 | 22 | OutA=0; |
soonerbot | 1:c28fac16a109 | 23 | OutB=1; |
soonerbot | 1:c28fac16a109 | 24 | } |
soonerbot | 1:c28fac16a109 | 25 | OutPWM=abs(power); |
soonerbot | 1:c28fac16a109 | 26 | return 1; |
soonerbot | 1:c28fac16a109 | 27 | } |
soonerbot | 1:c28fac16a109 | 28 | |
soonerbot | 1:c28fac16a109 | 29 | int motor::setReversed(int state){ |
soonerbot | 1:c28fac16a109 | 30 | if(state!=0){ |
soonerbot | 1:c28fac16a109 | 31 | reversed=1; |
soonerbot | 1:c28fac16a109 | 32 | } else { |
soonerbot | 1:c28fac16a109 | 33 | reversed=0; |
soonerbot | 1:c28fac16a109 | 34 | } |
soonerbot | 1:c28fac16a109 | 35 | return 1; |
soonerbot | 1:c28fac16a109 | 36 | } |
soonerbot | 1:c28fac16a109 | 37 | |
soonerbot | 1:c28fac16a109 | 38 | |
soonerbot | 1:c28fac16a109 | 39 | simpleMotor::simpleMotor(PinName APin, PinName PWMPin) : |
soonerbot | 1:c28fac16a109 | 40 | OutA(APin), OutPWM(PWMPin){ |
soonerbot | 1:c28fac16a109 | 41 | |
soonerbot | 1:c28fac16a109 | 42 | //blah |
soonerbot | 1:c28fac16a109 | 43 | setPower(0); |
soonerbot | 1:c28fac16a109 | 44 | reversed=0; |
soonerbot | 1:c28fac16a109 | 45 | } |
soonerbot | 1:c28fac16a109 | 46 | |
soonerbot | 1:c28fac16a109 | 47 | int simpleMotor::setPower( double power) { |
soonerbot | 1:c28fac16a109 | 48 | if((power>=0)^reversed){ |
soonerbot | 1:c28fac16a109 | 49 | OutA=1; |
soonerbot | 1:c28fac16a109 | 50 | } else { |
soonerbot | 1:c28fac16a109 | 51 | OutA=0; |
soonerbot | 1:c28fac16a109 | 52 | } |
soonerbot | 1:c28fac16a109 | 53 | OutPWM=abs(power); |
soonerbot | 1:c28fac16a109 | 54 | currPower=power; |
soonerbot | 1:c28fac16a109 | 55 | return 1; |
soonerbot | 1:c28fac16a109 | 56 | } |
soonerbot | 1:c28fac16a109 | 57 | |
soonerbot | 1:c28fac16a109 | 58 | int simpleMotor::setReversed(int state){ |
soonerbot | 1:c28fac16a109 | 59 | if(state!=0){ |
soonerbot | 1:c28fac16a109 | 60 | reversed=1; |
soonerbot | 1:c28fac16a109 | 61 | } else { |
soonerbot | 1:c28fac16a109 | 62 | reversed=0; |
soonerbot | 1:c28fac16a109 | 63 | } |
soonerbot | 1:c28fac16a109 | 64 | return 1; |
soonerbot | 1:c28fac16a109 | 65 | } |