2022Aのエンコーダを読んでとばす(サブ2基盤)
Dependencies: QEI SerialMultiByte mbed
main.cpp
- Committer:
- nagix
- Date:
- 2022-10-09
- Revision:
- 0:c5e201f4e5d8
File content as of revision 0:c5e201f4e5d8:
#include "mbed.h" #include "QEI.h" #include "SerialMultiByte.h" QEI enc1(PB_6,PB_3,NC,100, QEI::X4_ENCODING); QEI enc2(PA_8,PA_9,NC,100, QEI::X4_ENCODING); QEI enc3(PB_6,PB_7,NC,100, QEI::X4_ENCODING); QEI enc4(PA_0,PA_1,NC,100, QEI::X4_ENCODING); Serial pc(USBTX,USBRX,115200); SerialMultiByte send(PC_12,PD_2); //int Revol1; //int Current; //double GetAngle; //int Angle_rev; //double SumAngle; Timer t; int main() { // stop = 1; // uint8_t test[4] = {1,2,3,4}; int16_t Angle[4] = {0}; uint8_t Pulse[8] = {0}; t.start(); send.setHeaders(0xff,0xff); while(1) { Angle[0] = enc1.getPulses(); Angle[1] = enc2.getPulses(); Angle[2] = enc3.getPulses(); Angle[3] = enc4.getPulses(); for(int i=0, j=0;i<8;i+=2,j++){ Pulse[i] = Angle[j] >> 8; Pulse[i+1] = Angle[j] & 255; } // Pulse[0] = Angle[0] >> 8; // Pulse[1] = Angle[0] & 255; // Revol1 = enc1.getRevolutions(); // Current = enc1.getCurrentState(); // GetAngle = enc1.getAngle(); // Angle_rev = enc1.getAng_rev(); // SumAngle = enc1.getSumangle(); // 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); pc.printf("t:%.2f | ENC1:%.2d | ENC2:%.2d | ENC3:%.2d | ENC4:%.2d |", t.read(),Angle[0],Angle[1],Angle[2],Angle[3]); pc.printf("\r\n"); send.sendData(Pulse,8); // pc.printf("t:%.2f | test1:%.2d | test2:%.2d | test3:%.2d | test4:%.2d |", t.read(),test[0],test[1],test[2],test[3]); // pc.printf("\r\n"); // send.sendData(test,4); } }