BacaMotor

Dependencies:   mbed Motornew millis

Committer:
tamamfirdaus
Date:
Mon Mar 18 15:15:43 2019 +0000
Revision:
0:b6f3a4e90aff
BacaMotor;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tamamfirdaus 0:b6f3a4e90aff 1 //Library
tamamfirdaus 0:b6f3a4e90aff 2 #include "mbed.h"
tamamfirdaus 0:b6f3a4e90aff 3 #include "encoderKRAI.h"
tamamfirdaus 0:b6f3a4e90aff 4 #include "millis.h"
tamamfirdaus 0:b6f3a4e90aff 5 #include "Motor.h"
tamamfirdaus 0:b6f3a4e90aff 6
tamamfirdaus 0:b6f3a4e90aff 7 //Konstanta
tamamfirdaus 0:b6f3a4e90aff 8 #define PULSE_TO_JARAK 0.61313625
tamamfirdaus 0:b6f3a4e90aff 9 #define Pressed 0
tamamfirdaus 0:b6f3a4e90aff 10 #define NotPressed 1
tamamfirdaus 0:b6f3a4e90aff 11
tamamfirdaus 0:b6f3a4e90aff 12 encoderKRAI encoderMotorA (PC_11, PC_12, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 13 encoderKRAI encoderMotorB (PC_2, PC_3, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 14 encoderKRAI encoderMotorC (PC_14, PC_15, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 15 encoderKRAI encoderMotorD (PC_10,PC_13, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 16
tamamfirdaus 0:b6f3a4e90aff 17 encoderKRAI encoder1 (PB_7,PB_6, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 18 encoderKRAI encoder2 (PB_4,PB_5, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 19 encoderKRAI encoder3 (PB_8,PB_9, 538, encoderKRAI::X4_ENCODING);
tamamfirdaus 0:b6f3a4e90aff 20
tamamfirdaus 0:b6f3a4e90aff 21 /*Motor motorA(PA_7, PA_5, PA_6);
tamamfirdaus 0:b6f3a4e90aff 22 Motor motorB(PB_0, PC_1, PC_0);
tamamfirdaus 0:b6f3a4e90aff 23 Motor motorC(PB_1, PB_15, PB_14);
tamamfirdaus 0:b6f3a4e90aff 24 Motor motorD(PA_11, PA_12, PB_12);*/
tamamfirdaus 0:b6f3a4e90aff 25 DigitalIn BlueButton(USER_BUTTON);
tamamfirdaus 0:b6f3a4e90aff 26
tamamfirdaus 0:b6f3a4e90aff 27
tamamfirdaus 0:b6f3a4e90aff 28 Serial pc(USBTX, USBRX);
tamamfirdaus 0:b6f3a4e90aff 29
tamamfirdaus 0:b6f3a4e90aff 30 //Variable Global
tamamfirdaus 0:b6f3a4e90aff 31 float timeSampling;
tamamfirdaus 0:b6f3a4e90aff 32 double pulseA;
tamamfirdaus 0:b6f3a4e90aff 33 double pulseB;
tamamfirdaus 0:b6f3a4e90aff 34 double pulseC;
tamamfirdaus 0:b6f3a4e90aff 35 double pulseD;
tamamfirdaus 0:b6f3a4e90aff 36 double pulse1;
tamamfirdaus 0:b6f3a4e90aff 37 double pulse2;
tamamfirdaus 0:b6f3a4e90aff 38 double pulse3;
tamamfirdaus 0:b6f3a4e90aff 39 long lastMillis;
tamamfirdaus 0:b6f3a4e90aff 40
tamamfirdaus 0:b6f3a4e90aff 41 //Baca Encoder
tamamfirdaus 0:b6f3a4e90aff 42 int main(){
tamamfirdaus 0:b6f3a4e90aff 43 /* motorA.speed(0.4);
tamamfirdaus 0:b6f3a4e90aff 44 motorB.speed(0.4);
tamamfirdaus 0:b6f3a4e90aff 45 motorC.speed(0.4);
tamamfirdaus 0:b6f3a4e90aff 46 motorD.speed(0.4);
tamamfirdaus 0:b6f3a4e90aff 47 wait(5);
tamamfirdaus 0:b6f3a4e90aff 48 motorA.speed(0.0);
tamamfirdaus 0:b6f3a4e90aff 49 motorB.speed(0.0);
tamamfirdaus 0:b6f3a4e90aff 50 motorC.speed(0.0);
tamamfirdaus 0:b6f3a4e90aff 51 motorD.speed(0.0);*/
tamamfirdaus 0:b6f3a4e90aff 52 pc.baud(115200);
tamamfirdaus 0:b6f3a4e90aff 53 while(1){
tamamfirdaus 0:b6f3a4e90aff 54 /*if(BlueButton==Pressed){
tamamfirdaus 0:b6f3a4e90aff 55 encoderMotorA.reset();
tamamfirdaus 0:b6f3a4e90aff 56 }*/
tamamfirdaus 0:b6f3a4e90aff 57
tamamfirdaus 0:b6f3a4e90aff 58 pulseA = (double)encoderMotorA.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 59 pulseB = (double)encoderMotorB.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 60 pulseC = (double)encoderMotorC.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 61 pulseD = (double)encoderMotorD.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 62
tamamfirdaus 0:b6f3a4e90aff 63 //pulse1 = (double)encoder1.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 64 //pulse2 = (double)encoder2.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 65 pulse3 = (double)encoder3.getPulses()*PULSE_TO_JARAK;
tamamfirdaus 0:b6f3a4e90aff 66 //pc.printf("A: %lf\t B: %lf\t C: %lf\t D: %lf\t \n", pulseA, pulseB, pulseC, pulseD);
tamamfirdaus 0:b6f3a4e90aff 67 pc.printf("Enc_1: %lf\n", pulse3);
tamamfirdaus 0:b6f3a4e90aff 68
tamamfirdaus 0:b6f3a4e90aff 69 wait(0.2);
tamamfirdaus 0:b6f3a4e90aff 70 }
tamamfirdaus 0:b6f3a4e90aff 71 }