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
remoteMotor.cpp@1:c28fac16a109, 2013-11-17 (annotated)
- Committer:
- soonerbot
- Date:
- Sun Nov 17 03:05:35 2013 +0000
- Revision:
- 1:c28fac16a109
- Child:
- 4:adc885f4ab75
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 "remoteMotor.h" |
soonerbot | 1:c28fac16a109 | 2 | #include "dbgprint.h" |
soonerbot | 1:c28fac16a109 | 3 | |
soonerbot | 1:c28fac16a109 | 4 | remoteMotor::remoteMotor(remoteEnc &remoteIn, int APin,int BPin, PinName PWMPin) : |
soonerbot | 1:c28fac16a109 | 5 | remote(remoteIn), OutPWM(PWMPin){ |
soonerbot | 1:c28fac16a109 | 6 | |
soonerbot | 1:c28fac16a109 | 7 | //blah |
soonerbot | 1:c28fac16a109 | 8 | remoteA=APin; |
soonerbot | 1:c28fac16a109 | 9 | remoteB=BPin; |
soonerbot | 1:c28fac16a109 | 10 | |
soonerbot | 1:c28fac16a109 | 11 | brake(); |
soonerbot | 1:c28fac16a109 | 12 | reversed=0; |
soonerbot | 1:c28fac16a109 | 13 | } |
soonerbot | 1:c28fac16a109 | 14 | |
soonerbot | 1:c28fac16a109 | 15 | int remoteMotor::brake(){ |
soonerbot | 1:c28fac16a109 | 16 | remote.setPin(remoteA,0); |
soonerbot | 1:c28fac16a109 | 17 | remote.setPin(remoteB,0); |
soonerbot | 1:c28fac16a109 | 18 | //OutA=OutB=0; |
soonerbot | 1:c28fac16a109 | 19 | OutPWM=1; |
soonerbot | 1:c28fac16a109 | 20 | return 1; |
soonerbot | 1:c28fac16a109 | 21 | } |
soonerbot | 1:c28fac16a109 | 22 | |
soonerbot | 1:c28fac16a109 | 23 | int remoteMotor::setPower( double power) { |
soonerbot | 1:c28fac16a109 | 24 | if((power>=0)^reversed){ |
soonerbot | 1:c28fac16a109 | 25 | remote.setPin(remoteA,1); |
soonerbot | 1:c28fac16a109 | 26 | remote.setPin(remoteB,0); |
soonerbot | 1:c28fac16a109 | 27 | //OutA=1; |
soonerbot | 1:c28fac16a109 | 28 | //OutB=0; |
soonerbot | 1:c28fac16a109 | 29 | } else { |
soonerbot | 1:c28fac16a109 | 30 | remote.setPin(remoteA,0); |
soonerbot | 1:c28fac16a109 | 31 | remote.setPin(remoteB,1); |
soonerbot | 1:c28fac16a109 | 32 | //OutA=0; |
soonerbot | 1:c28fac16a109 | 33 | //OutB=1; |
soonerbot | 1:c28fac16a109 | 34 | } |
soonerbot | 1:c28fac16a109 | 35 | OutPWM=abs(power); |
soonerbot | 1:c28fac16a109 | 36 | return 1; |
soonerbot | 1:c28fac16a109 | 37 | } |
soonerbot | 1:c28fac16a109 | 38 | |
soonerbot | 1:c28fac16a109 | 39 | int remoteMotor::setReversed(int state){ |
soonerbot | 1:c28fac16a109 | 40 | if(state!=0){ |
soonerbot | 1:c28fac16a109 | 41 | reversed=1; |
soonerbot | 1:c28fac16a109 | 42 | } else { |
soonerbot | 1:c28fac16a109 | 43 | reversed=0; |
soonerbot | 1:c28fac16a109 | 44 | } |
soonerbot | 1:c28fac16a109 | 45 | return 1; |
soonerbot | 1:c28fac16a109 | 46 | } |
soonerbot | 1:c28fac16a109 | 47 | |
soonerbot | 1:c28fac16a109 | 48 | |
soonerbot | 1:c28fac16a109 | 49 | simpleRemoteMotor::simpleRemoteMotor(remoteEnc &remotedev, int remotepinin, PinName PWMPin) : |
soonerbot | 1:c28fac16a109 | 50 | remote(remotedev), OutPWM(PWMPin){ |
soonerbot | 1:c28fac16a109 | 51 | |
soonerbot | 1:c28fac16a109 | 52 | DBGPRINT("bbbhal",1); |
soonerbot | 1:c28fac16a109 | 53 | remotepin=remotepinin; |
soonerbot | 1:c28fac16a109 | 54 | //blah |
soonerbot | 1:c28fac16a109 | 55 | setPower(0); |
soonerbot | 1:c28fac16a109 | 56 | reversed=0; |
soonerbot | 1:c28fac16a109 | 57 | } |
soonerbot | 1:c28fac16a109 | 58 | |
soonerbot | 1:c28fac16a109 | 59 | int simpleRemoteMotor::setPower( double power) { |
soonerbot | 1:c28fac16a109 | 60 | if((power>=0)^reversed){ |
soonerbot | 1:c28fac16a109 | 61 | remote.setPin(remotepin,1); |
soonerbot | 1:c28fac16a109 | 62 | } else { |
soonerbot | 1:c28fac16a109 | 63 | remote.setPin(remotepin,0); |
soonerbot | 1:c28fac16a109 | 64 | } |
soonerbot | 1:c28fac16a109 | 65 | OutPWM=abs(power); |
soonerbot | 1:c28fac16a109 | 66 | currPower=power; |
soonerbot | 1:c28fac16a109 | 67 | return 1; |
soonerbot | 1:c28fac16a109 | 68 | } |
soonerbot | 1:c28fac16a109 | 69 | |
soonerbot | 1:c28fac16a109 | 70 | int simpleRemoteMotor::setReversed(int state){ |
soonerbot | 1:c28fac16a109 | 71 | if(state!=0){ |
soonerbot | 1:c28fac16a109 | 72 | reversed=1; |
soonerbot | 1:c28fac16a109 | 73 | } else { |
soonerbot | 1:c28fac16a109 | 74 | reversed=0; |
soonerbot | 1:c28fac16a109 | 75 | } |
soonerbot | 1:c28fac16a109 | 76 | return 1; |
soonerbot | 1:c28fac16a109 | 77 | } |