2022Aのエンコーダを読んでとばす(サブ2基盤)

Dependencies:   QEI SerialMultiByte mbed

Committer:
nagix
Date:
Sun Oct 09 09:02:22 2022 +0000
Revision:
0:c5e201f4e5d8
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nagix 0:c5e201f4e5d8 1 #include "mbed.h"
nagix 0:c5e201f4e5d8 2 #include "QEI.h"
nagix 0:c5e201f4e5d8 3 #include "SerialMultiByte.h"
nagix 0:c5e201f4e5d8 4
nagix 0:c5e201f4e5d8 5 QEI enc1(PB_6,PB_3,NC,100, QEI::X4_ENCODING);
nagix 0:c5e201f4e5d8 6 QEI enc2(PA_8,PA_9,NC,100, QEI::X4_ENCODING);
nagix 0:c5e201f4e5d8 7 QEI enc3(PB_6,PB_7,NC,100, QEI::X4_ENCODING);
nagix 0:c5e201f4e5d8 8 QEI enc4(PA_0,PA_1,NC,100, QEI::X4_ENCODING);
nagix 0:c5e201f4e5d8 9
nagix 0:c5e201f4e5d8 10
nagix 0:c5e201f4e5d8 11 Serial pc(USBTX,USBRX,115200);
nagix 0:c5e201f4e5d8 12 SerialMultiByte send(PC_12,PD_2);
nagix 0:c5e201f4e5d8 13
nagix 0:c5e201f4e5d8 14 //int Revol1;
nagix 0:c5e201f4e5d8 15 //int Current;
nagix 0:c5e201f4e5d8 16 //double GetAngle;
nagix 0:c5e201f4e5d8 17 //int Angle_rev;
nagix 0:c5e201f4e5d8 18 //double SumAngle;
nagix 0:c5e201f4e5d8 19
nagix 0:c5e201f4e5d8 20 Timer t;
nagix 0:c5e201f4e5d8 21
nagix 0:c5e201f4e5d8 22 int main()
nagix 0:c5e201f4e5d8 23 {
nagix 0:c5e201f4e5d8 24 // stop = 1;
nagix 0:c5e201f4e5d8 25 // uint8_t test[4] = {1,2,3,4};
nagix 0:c5e201f4e5d8 26 int16_t Angle[4] = {0};
nagix 0:c5e201f4e5d8 27 uint8_t Pulse[8] = {0};
nagix 0:c5e201f4e5d8 28 t.start();
nagix 0:c5e201f4e5d8 29 send.setHeaders(0xff,0xff);
nagix 0:c5e201f4e5d8 30
nagix 0:c5e201f4e5d8 31 while(1)
nagix 0:c5e201f4e5d8 32 {
nagix 0:c5e201f4e5d8 33 Angle[0] = enc1.getPulses();
nagix 0:c5e201f4e5d8 34 Angle[1] = enc2.getPulses();
nagix 0:c5e201f4e5d8 35 Angle[2] = enc3.getPulses();
nagix 0:c5e201f4e5d8 36 Angle[3] = enc4.getPulses();
nagix 0:c5e201f4e5d8 37 for(int i=0, j=0;i<8;i+=2,j++){
nagix 0:c5e201f4e5d8 38 Pulse[i] = Angle[j] >> 8;
nagix 0:c5e201f4e5d8 39 Pulse[i+1] = Angle[j] & 255;
nagix 0:c5e201f4e5d8 40 }
nagix 0:c5e201f4e5d8 41 // Pulse[0] = Angle[0] >> 8;
nagix 0:c5e201f4e5d8 42 // Pulse[1] = Angle[0] & 255;
nagix 0:c5e201f4e5d8 43
nagix 0:c5e201f4e5d8 44 // Revol1 = enc1.getRevolutions();
nagix 0:c5e201f4e5d8 45 // Current = enc1.getCurrentState();
nagix 0:c5e201f4e5d8 46 // GetAngle = enc1.getAngle();
nagix 0:c5e201f4e5d8 47 // Angle_rev = enc1.getAng_rev();
nagix 0:c5e201f4e5d8 48 // SumAngle = enc1.getSumangle();
nagix 0:c5e201f4e5d8 49
nagix 0:c5e201f4e5d8 50
nagix 0:c5e201f4e5d8 51 // pc.printf("t:%.2f | ENC0:%d | REV0:%d | Cur:%d | GetAngle:%.2f | Angle_rev:%d | SumAngle:%.2f", t.read(),Angle1,Revol1,Current,GetAngle,Angle_rev,SumAngle);
nagix 0:c5e201f4e5d8 52 pc.printf("t:%.2f | ENC1:%.2d | ENC2:%.2d | ENC3:%.2d | ENC4:%.2d |", t.read(),Angle[0],Angle[1],Angle[2],Angle[3]);
nagix 0:c5e201f4e5d8 53 pc.printf("\r\n");
nagix 0:c5e201f4e5d8 54 send.sendData(Pulse,8);
nagix 0:c5e201f4e5d8 55
nagix 0:c5e201f4e5d8 56 // pc.printf("t:%.2f | test1:%.2d | test2:%.2d | test3:%.2d | test4:%.2d |", t.read(),test[0],test[1],test[2],test[3]);
nagix 0:c5e201f4e5d8 57 // pc.printf("\r\n");
nagix 0:c5e201f4e5d8 58 // send.sendData(test,4);
nagix 0:c5e201f4e5d8 59
nagix 0:c5e201f4e5d8 60 }
nagix 0:c5e201f4e5d8 61 }