![](/media/cache/group/BRNLIVSMED_logo-01.png.50x50_q85.png)
마스터 로봇 조종기(EsmaCAT EtherCAT Shield 이용)
Dependencies: EsmacatShield
Revision 1:9a05b0a731f3, committed 2020-12-01
- Comitter:
- Jangikjae
- Date:
- Tue Dec 01 01:42:01 2020 +0000
- Parent:
- 0:76a0d29416ee
- Commit message:
Changed in this revision
diff -r 76a0d29416ee -r 9a05b0a731f3 KeypadLib.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KeypadLib.lib Tue Dec 01 01:42:01 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/LIVS-Studio/code/f401_EASE_7axis_controller/#c33f8b2136b4
diff -r 76a0d29416ee -r 9a05b0a731f3 main.cpp --- a/main.cpp Tue Nov 03 12:51:15 2020 +0000 +++ b/main.cpp Tue Dec 01 01:42:01 2020 +0000 @@ -31,15 +31,23 @@ ******************************************************************************* * @file EsmacatShield.h ******************************************************************************* + LIVSMED + @brief 마스터 로봇 조종기로부터 7개의 절대 엔코더의 값을 SSI통신으로 읽는다. + 4개의 입력이 있는 풋 페달장치로부터 입력 값을 받는다. + 총 8가지의 정보(7개의 엔코더 값 + 선택된 1개의 풋 페달값)를 EtherCAT IC + 로 전달한다. + +******************************************************************************* + */ #include "mbed.h" #include <EsmacatShield.h> //Include EsmacatShield Library - +#include "keypad.h" int counter; int16_t v[8]; //an array of integer is declared for reading the //data packet of EtherCAT from EASE 8 registers -Serial pc(USBTX, USBRX); // Configuring the serial port to host PC +BufferedSerial pc(USBTX, USBRX); // Configuring the serial port to host PC Ticker tick1; @@ -54,11 +62,16 @@ DigitalOut CS2(PA_8); DigitalOut CS3(PA_9); DigitalOut CS4(PC_7); -DigitalOut CS5(PB_6); +DigitalOut CS5(PB_8); DigitalOut CS6(PC_1); DigitalOut CS7(PC_0); + DigitalOut greenLED(PB_0); +////////////////////////// + + +////////////////////////// uint8_t Hbyte_enc1 = 0; uint8_t Lbyte_enc1 = 0; uint8_t Hbyte_enc2 = 0; @@ -86,6 +99,15 @@ uint32_t previousT = 0; uint32_t DeltaT = 0; +uint8_t TxdataBuffer[20]; +uint8_t KeypadBuffer[4]; +uint8_t keydata = 0; +uint32_t keypush = 0; +uint32_t pre_keypush = 0; +uint8_t keystate = 0; +uint8_t pushIndex = 0; +uint16_t Keypad_data = 0; + uint16_t TestData = 0; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -95,6 +117,7 @@ spi.frequency(500000); //500 kHz } + void ReadEncoder(SPI&spi, uint8_t &low, uint8_t &high, DigitalOut& CS, uint16_t &angle) { CS = 0; @@ -105,11 +128,14 @@ uint16_t Data = ((uint16_t)high << 2) + ((uint16_t)low >>6); high = Data >> 8; low = Data & 0xff; - angle = (float)Data * (360.0 / 1024.0); - angle = (uint16_t) angle * 1; + + angle = Data; + //angle = (float)Data * (360.0 / 1024.0); + //angle = (uint16_t)(angle * 1000); } + //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// int main() @@ -125,21 +151,80 @@ greenLED = 0; //tick1.attach(MeasureEncoder, 0.01); + Keypad keypad(PC_3, PC_2, NC, NC, PA_14, PA_13, NC, NC); + keypad.enablePullUp(); + char key; + + while(1) { TestData++; if(TestData == 5) { TestData = 0; - greenLED = !greenLED; + greenLED = !greenLED; + } + + key = keypad.getKey(); + if(key != KEY_RELEASED) + { + keydata = key; + + if(keydata == '1'){KeypadBuffer[1]= 0xC1;} + else if(keydata == '4'){KeypadBuffer[1]=0xC2;} + else if(keydata == '2'){KeypadBuffer[1]=0xC3;} + else if(keydata == '5'){keypush++;} + + } + + if (keypush == pre_keypush){ + keypush = 0; + } + + if((keypush > 2)&&(keystate == 0x00)){ + KeypadBuffer[2] = 0x00; + keystate = 0x00; + pushIndex = 1; } + else if((keypush > 2)&&(keystate == 0x01)){ + KeypadBuffer[2] = 0x01; + keystate = 0x01; + pushIndex = 1; + } + else if ((keypush == 0)&&(keystate == 0x00)){ + if(pushIndex == 0){ + KeypadBuffer[2] = 0x00; + keystate = 0x00; + } + if(pushIndex == 1){ + KeypadBuffer[2] = 0x01; + keystate = 0x01; + pushIndex = 0; + } + } + else if ((keypush == 0)&&(keystate == 0x01)){ + if(pushIndex == 0){ + KeypadBuffer[2] = 0x01; + keystate = 0x01; + } + if(pushIndex == 1){ + KeypadBuffer[2] = 0x00; + keystate = 0x00; + pushIndex = 0; + } + } + + pre_keypush = keypush; + + Keypad_data = (uint16_t)(KeypadBuffer[1] << 8) | KeypadBuffer[2]; ReadEncoder(spi3, Lbyte_enc4, Hbyte_enc4, CS4, Angle_encoder4); + ReadEncoder(spi3, Lbyte_enc5, Hbyte_enc5, CS5, Angle_encoder5); + ReadEncoder(spi3, Lbyte_enc6, Hbyte_enc6, CS6, Angle_encoder6); + ReadEncoder(spi3, Lbyte_enc7, Hbyte_enc7, CS7, Angle_encoder7); ReadEncoder(spi2, Lbyte_enc1, Hbyte_enc1, CS1, Angle_encoder1); - ReadEncoder(spi3, Lbyte_enc5, Hbyte_enc5, CS5, Angle_encoder5); ReadEncoder(spi2, Lbyte_enc2, Hbyte_enc2, CS2, Angle_encoder2); - ReadEncoder(spi3, Lbyte_enc6, Hbyte_enc6, CS6, Angle_encoder6); ReadEncoder(spi2, Lbyte_enc3, Hbyte_enc3, CS3, Angle_encoder3); - ReadEncoder(spi3, Lbyte_enc7, Hbyte_enc7, CS7, Angle_encoder7); + slave.write_reg_value(0,Angle_encoder1, true); slave.write_reg_value(1,Angle_encoder2, true); @@ -148,23 +233,12 @@ slave.write_reg_value(4,Angle_encoder5, true); slave.write_reg_value(5,Angle_encoder6, true); slave.write_reg_value(6,Angle_encoder7, true); - /* - pc.printf("enc1: %d", Angle_encoder1); - pc.printf("\n"); - pc.printf("enc2: %d", Angle_encoder2); - pc.printf("\n"); - pc.printf("enc3: %d", Angle_encoder3); - pc.printf("\n"); - pc.printf("enc4: %d", Angle_encoder4); - pc.printf("\n"); - pc.printf("enc5: %d", Angle_encoder5); - pc.printf("\n"); - pc.printf("enc6: %d", Angle_encoder6); - pc.printf("\n"); - pc.printf("enc7: %d", Angle_encoder7); - pc.printf("\n"); - */ - wait_us(10000); + slave.write_reg_value(7,Keypad_data, true); + + + printf("ENC1: %d, ENC2: %d, ENC3: %d, ENC4: %d,ENC5: %d, ENC6: %d, ENC7: %d\n", Angle_encoder1, Angle_encoder2, Angle_encoder3, Angle_encoder4,Angle_encoder5, Angle_encoder6, Angle_encoder7); + + wait_us(100000); }
diff -r 76a0d29416ee -r 9a05b0a731f3 mbed-os.lib --- a/mbed-os.lib Tue Nov 03 12:51:15 2020 +0000 +++ b/mbed-os.lib Tue Dec 01 01:42:01 2020 +0000 @@ -1,1 +1,1 @@ -https://github.com/armmbed/mbed-os/#430e64fce8098fd5e54f6de32f3f029f35dc705f +https://github.com/armmbed/mbed-os/#c6d65fe5082aeef6bf0d7043b4cbf0a9cc9a9d5e