mencari respon motor launcher dengan fungsi step
Dependencies: Motor mbed millis
Fork of transfer_function_motor by
main.cpp@1:3a234ff1442b, 2017-02-16 (annotated)
- Committer:
- Najib_irvani
- Date:
- Thu Feb 16 16:25:31 2017 +0000
- Revision:
- 1:3a234ff1442b
- Parent:
- 0:be14d75c8037
- Child:
- 2:8f1bb7191680
fungsi transfer motor dengan input fungsi step
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Najib_irvani | 0:be14d75c8037 | 1 | #include "mbed.h" |
Najib_irvani | 0:be14d75c8037 | 2 | #include "encoderKRAI.h" |
Najib_irvani | 0:be14d75c8037 | 3 | #include "Motor.h" |
Najib_irvani | 0:be14d75c8037 | 4 | #include "millis.h" |
Najib_irvani | 0:be14d75c8037 | 5 | |
Najib_irvani | 1:3a234ff1442b | 6 | encoderKRAI encoder( PB_13, PB_14, 14, encoderKRAI::X4_ENCODING); |
Najib_irvani | 0:be14d75c8037 | 7 | Serial pc(USBTX,USBRX); |
Najib_irvani | 0:be14d75c8037 | 8 | Motor motor(PA_8,PC_1,PC_2); |
Najib_irvani | 0:be14d75c8037 | 9 | |
Najib_irvani | 0:be14d75c8037 | 10 | unsigned long int previousMillis = 0; |
Najib_irvani | 0:be14d75c8037 | 11 | unsigned long int currentMillis; |
Najib_irvani | 0:be14d75c8037 | 12 | double rpm; |
Najib_irvani | 0:be14d75c8037 | 13 | |
Najib_irvani | 0:be14d75c8037 | 14 | |
Najib_irvani | 0:be14d75c8037 | 15 | |
Najib_irvani | 0:be14d75c8037 | 16 | int main() { |
Najib_irvani | 0:be14d75c8037 | 17 | |
Najib_irvani | 0:be14d75c8037 | 18 | startMillis(); |
Najib_irvani | 0:be14d75c8037 | 19 | motor.speed(0.5); |
Najib_irvani | 0:be14d75c8037 | 20 | |
Najib_irvani | 0:be14d75c8037 | 21 | while(1) { |
Najib_irvani | 0:be14d75c8037 | 22 | |
Najib_irvani | 0:be14d75c8037 | 23 | currentMillis = millis(); |
Najib_irvani | 0:be14d75c8037 | 24 | |
Najib_irvani | 0:be14d75c8037 | 25 | |
Najib_irvani | 1:3a234ff1442b | 26 | if (currentMillis-previousMillis>=10) |
Najib_irvani | 0:be14d75c8037 | 27 | { |
Najib_irvani | 0:be14d75c8037 | 28 | rpm = (double)encoder.getPulses(); |
Najib_irvani | 0:be14d75c8037 | 29 | |
Najib_irvani | 0:be14d75c8037 | 30 | |
Najib_irvani | 0:be14d75c8037 | 31 | |
Najib_irvani | 0:be14d75c8037 | 32 | |
Najib_irvani | 0:be14d75c8037 | 33 | encoder.reset(); |
Najib_irvani | 0:be14d75c8037 | 34 | pc.printf("%.04lf\n",rpm); |
Najib_irvani | 0:be14d75c8037 | 35 | |
Najib_irvani | 0:be14d75c8037 | 36 | previousMillis = currentMillis; |
Najib_irvani | 0:be14d75c8037 | 37 | |
Najib_irvani | 0:be14d75c8037 | 38 | } |
Najib_irvani | 0:be14d75c8037 | 39 | |
Najib_irvani | 0:be14d75c8037 | 40 | |
Najib_irvani | 0:be14d75c8037 | 41 | |
Najib_irvani | 0:be14d75c8037 | 42 | } |
Najib_irvani | 0:be14d75c8037 | 43 | } |