Motor2
Fork of Motor by
Motor.cpp@5:db97e97ac00a, 2016-08-07 (annotated)
- Committer:
- kikoaac
- Date:
- Sun Aug 07 12:47:01 2016 +0000
- Revision:
- 5:db97e97ac00a
- Parent:
- 4:56a1159c881c
motorIC;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kikoaac | 0:1252cd3b995f | 1 | /** |
kikoaac | 0:1252cd3b995f | 2 | * Includes |
kikoaac | 0:1252cd3b995f | 3 | */ |
kikoaac | 0:1252cd3b995f | 4 | #include "Motor.h" |
kikoaac | 3:dea2df71cb97 | 5 | Motor::Motor(const Motor& m): |
kikoaac | 5:db97e97ac00a | 6 | mode(m.Pin[0],m.Pin[1]),PwmPin(m.Pin[2]) |
kikoaac | 3:dea2df71cb97 | 7 | { |
kikoaac | 4:56a1159c881c | 8 | bias=0.0; |
kikoaac | 3:dea2df71cb97 | 9 | max=m.max; |
kikoaac | 3:dea2df71cb97 | 10 | //this |
kikoaac | 3:dea2df71cb97 | 11 | PwmPin.period_ms(20); |
kikoaac | 3:dea2df71cb97 | 12 | run(Stop,1); |
kikoaac | 3:dea2df71cb97 | 13 | } |
kikoaac | 0:1252cd3b995f | 14 | |
kikoaac | 5:db97e97ac00a | 15 | Motor::Motor(PinName _pin1, PinName _pin2,PinName _pwm) : |
kikoaac | 5:db97e97ac00a | 16 | mode(_pin1,_pin2),PwmPin(_pwm) |
kikoaac | 0:1252cd3b995f | 17 | { |
kikoaac | 5:db97e97ac00a | 18 | Pin[0] = _pin1; |
kikoaac | 5:db97e97ac00a | 19 | Pin[1] = _pin2; |
kikoaac | 5:db97e97ac00a | 20 | Pin[2] = _pwm; |
kikoaac | 3:dea2df71cb97 | 21 | max=1.0; |
kikoaac | 3:dea2df71cb97 | 22 | //this |
kikoaac | 2:ef4a9c047681 | 23 | PwmPin.period_ms(10); |
kikoaac | 0:1252cd3b995f | 24 | run(Stop,1); |
kikoaac | 0:1252cd3b995f | 25 | } |
kikoaac | 0:1252cd3b995f | 26 | void Motor::run(int i,float duty) |
kikoaac | 0:1252cd3b995f | 27 | { |
kikoaac | 3:dea2df71cb97 | 28 | //static int state; |
kikoaac | 4:56a1159c881c | 29 | Duty = (float)duty*max+bias; |
kikoaac | 1:4ab6e9768847 | 30 | //printf("Duty %f \n",(float)duty); |
kikoaac | 0:1252cd3b995f | 31 | //if(state==i)return; |
kikoaac | 4:56a1159c881c | 32 | PwmPin = Duty; |
kikoaac | 0:1252cd3b995f | 33 | if(state==i)return; |
kikoaac | 5:db97e97ac00a | 34 | mode=0; |
kikoaac | 5:db97e97ac00a | 35 | wait_us(20); |
kikoaac | 5:db97e97ac00a | 36 | if(i==Free) mode=0x00; |
kikoaac | 5:db97e97ac00a | 37 | else if(i==Back) mode=0x01|0x00; |
kikoaac | 5:db97e97ac00a | 38 | else if(i==Front) mode=0x00|0x02; |
kikoaac | 5:db97e97ac00a | 39 | else if(i==Stop) mode=0x01|0x02; |
kikoaac | 5:db97e97ac00a | 40 | else mode=0x00; |
kikoaac | 0:1252cd3b995f | 41 | state=i; |
kikoaac | 0:1252cd3b995f | 42 | } |
kikoaac | 0:1252cd3b995f | 43 | |
kikoaac | 1:4ab6e9768847 | 44 | |
kikoaac | 1:4ab6e9768847 | 45 | |
kikoaac | 3:dea2df71cb97 | 46 |