RevolutionPi & fischertechnik パンチングマシン パート2

ンチングマシンをプログラミングで動かす!

う動かすか

パンチングマシンのスクールバージョン

パンチングマシンの詳しい説明はYoutubeをご覧ください!

パンチングマシンYoutube動画

まず、プログラミングする前に動作の流れを確認します。

1. スイッチを押すとコンベアーが正転駆動

2. パンチングマシンの手前のフォトトランジスタ (明るさセンサー)の入力を受けてコンベアー停 止

3. パンチングマシンが降下

4. パンチングマシンの下にあるスイッチで降下

5. パンチングマシンが上昇

6. パンチングマシンの上にあるスイッチで停止

7 .コンベアー逆転駆動

8. フォトトランジスタの前でコンベアー停止

モノの位置を知るための光電管センサー
役割別のモーター
昇降のストップに使用するスイッチ
コンベアーの駆動開始用のスイッチ

イメージがしやすい様に先に完成した動作を!

https://twitter.com/inFT37207295/status/1437569749181894661
レボパイを使ったパンチングマシンの動作

ログラムをパンチングマシン用に変更

いよいよパンチングマシンをプログラミングで動かします!

今回はパンチングマシンの入力・出力に合わせて

入力 ×7 出力 ×7  とします。

パート1と同様に1~7までの入力出力に対応するプログラムを作成します。

  1. #include <piControlIf.h>
  2. #include <piControl.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. // === 1 ===
  7.     int i = 0;
  8.     int iLastInputValue = 0;
  9.     char *pchInput = NULL;
  10.     char *pchOutput = NULL;
  11.     // structures containing variable information: Name, Offset, Bit, Length
  12.     SPIVariable spiVariableIn = {"", 0, 0, 0};
  13.     SPIVariable spiVariableOut = {"", 0, 0, 0};
  14.     // structures containing variable value: Offset, Bit, Value
  15.     SPIValue sValueIn = {0, 0, 0};
  16.     SPIValue sValueOut = {0, 0, 0};
  17. // === 2 ===
  18.     int i2 = 0;
  19.     int iLastInputValue2 = 0;
  20.     char *pchInput2 = NULL;
  21.     char *pchOutput2 = NULL;
  22.     // structures containing variable information: Name, Offset, Bit, Length
  23.     SPIVariable spiVariableIn2 = {"", 0, 0, 0};
  24.     SPIVariable spiVariableOut2 = {"", 0, 0, 0};
  25.     // structures containing variable value: Offset, Bit, Value
  26.     SPIValue sValueIn2 = {0, 0, 0};
  27.     SPIValue sValueOut2 = {0, 0, 0};
  28. //=== 3 ===
  29.     int i3 = 0;
  30.     int iLastInputValue3 = 0;
  31.     char *pchInput3 = NULL;
  32.     char *pchOutput3 = NULL;
  33.     // structures containing variable information: Name, Offset, Bit, Length
  34.     SPIVariable spiVariableIn3 = {"", 0, 0, 0};
  35.     SPIVariable spiVariableOut3 = {"", 0, 0, 0};
  36.     // structures containing variable value: Offset, Bit, Value
  37.     SPIValue sValueIn3 = {0, 0, 0};
  38.     SPIValue sValueOut3 = {0, 0, 0};
  39. // === 4 ===
  40.     int i4 = 0;
  41.     int iLastInputValue4 = 0;
  42.     char *pchInput4 = NULL;
  43.     char *pchOutput4 = NULL;
  44.     // structures containing variable information: Name, Offset, Bit, Length
  45.     SPIVariable spiVariableIn4 = {"", 0, 0, 0};
  46.     SPIVariable spiVariableOut4 = {"", 0, 0, 0};
  47.     // structures containing variable value: Offset, Bit, Value
  48.     SPIValue sValueIn4 = {0, 0, 0};
  49.     SPIValue sValueOut4 = {0, 0, 0};
  50. // === 5 ===
  51.     int i5 = 0;
  52.     int iLastInputValue5 = 0;
  53.     char *pchInput5 = NULL;
  54.     char *pchOutput5 = NULL;
  55.     // structures containing variable information: Name, Offset, Bit, Length
  56.     SPIVariable spiVariableIn5 = {"", 0, 0, 0};
  57.     SPIVariable spiVariableOut5 = {"", 0, 0, 0};
  58.     // structures containing variable value: Offset, Bit, Value
  59.     SPIValue sValueIn5 = {0, 0, 0};
  60.     SPIValue sValueOut5 = {0, 0, 0};
  61. //=== 6 ===
  62.     int i6 = 0;
  63.     int iLastInputValue6 = 0;
  64.     char *pchInput6 = NULL;
  65.     char *pchOutput6 = NULL;
  66.     // structures containing variable information: Name, Offset, Bit, Length
  67.     SPIVariable spiVariableIn6 = {"", 0, 0, 0};
  68.     SPIVariable spiVariableOut6 = {"", 0, 0, 0};
  69.     // structures containing variable value: Offset, Bit, Value
  70.     SPIValue sValueIn6 = {0, 0, 0};
  71.     SPIValue sValueOut6 = {0, 0, 0};
  72. // === 7 ===
  73.     int i7 = 0;
  74.     int iLastInputValue7 = 0;
  75.     char *pchInput7 = NULL;
  76.     char *pchOutput7 = NULL;
  77.     // structures containing variable information: Name, Offset, Bit, Length
  78.     SPIVariable spiVariableIn7 = {"", 0, 0, 0};
  79.     SPIVariable spiVariableOut7 = {"", 0, 0, 0};
  80.     // structures containing variable value: Offset, Bit, Value
  81.     SPIValue sValueIn7 = {0, 0, 0};
  82.     SPIValue sValueOut7 = {0, 0, 0};

そして次にそれぞれの関数の作成とプロトタイプ宣言をします。

  1. int IO_1(void);
  2. int IO_2(void);
  3. int IO_3(void);
  4. int IO_4(void);
  5. int IO_5(void);
  6. int IO_6(void);
  7. int IO_7(void);
  8. // --- 1 ---
  9. int IO_1(void) {
  10.         i5 = piControlGetBitValue(&sValueIn5); // PiBridge - read input pin
  11.         if(iLastInputValue5 != sValueIn5.i8uValue)        // if button state changed
  12.         {    // show the change
  13.             printf("%-32s : %d \n", pchInput, sValueIn.i8uValue)
  14.                 if(0 == iLastInputValue5)        // and was pressed before
  15.                 {    // switch light
  16.                     sValueOut.i8uValue = ~sValueOut.i8uValue;
  17.                 // PiBridge - set output pin
  18.                     i5 = piControlSetBitValue(&sValueOut);
  19.                     printf("%-32s : %s \n", pchOutput, sValueOut.i8uValue ? "On" : "Off");
  20.                     if(0 != i5)
  21.                     {
  22.                         fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i5);
  23.                         return -1;
  24.                     }
  25.                 }
  26.         }
  27.         iLastInputValue5 = sValueIn5.i8uValue;    // remember last input value
  28.     return 0;
  29. }
  30. // --- 2 ---
  31. int IO_2(void) {
  32.         i2 = piControlGetBitValue(&sValueIn2); // PiBridge - read input pin
  33.         if(iLastInputValue2 != sValueIn2.i8uValue)        // if button state changed
  34.         {        // show the change
  35.             printf("%-32s : %d \n", pchInput2, sValueIn2.i8uValue);
  36.             if(0 == sValueIn2.i8uValue)        // if button is released
  37.             {
  38.                 if(1 == iLastInputValue2)    // and was pressed before
  39.                 {        // switch light
  40.                     sValueOut.i8uValue = ~sValueOut.i8uValue;
  41.                 // PiBridge - set output pin
  42.                     i2 = piControlSetBitValue(&sValueOut);
  43.                     printf("%-32s : %s \n", pchOutput,sValueOut.i8uValue ? "On" : "Off");
  44.                     sleep(0.1);                
  45.                     i2 = piControlGetBitValue(&sValueIn2);            // PiBridge - read input pin
  46.                     if(iLastInputValue2 != sValueIn2.i8uValue)        // if button state changed
  47.                     {                
  48.                         if(0 == sValueIn2.i8uValue)        // if button is released
  49.                         {    // show the change
  50.                         printf("%-32s : %d \n", pchInput, sValueIn2.i8uValue);
  51.                             if(1 == iLastInputValue2)    // and was pressed before
  52.                             // switch light
  53.             sValueOut3.i8uValue = ~sValueOut3.i8uValue;                                                                // PiBridge - set output pi
  54.                                 i2 = piControlSetBitValue(&sValueOut3);
  55.                                 printf("%-32s : %s \n", pchOutput3, sValueOut3.i8uValue ? "On" : "Off");
  56.                                 if(0 != i2)
  57.                                 {
  58.                                     fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i2);
  59.                                     return -1;
  60.                                 }
  61.                             }
  62.                         }
  63.                     }                
  64.                     IO_4();
  65.                 }
  66.             }
  67.         }
  68.         iLastInputValue2 = sValueIn2.i8uValue;    // remember last input value    
  69.         //printf("=== OK 2 ====");
  70.         return 0;
  71. // --- 3---
  72. int IO_3(void) {
  73.         i3 = piControlGetBitValue(&sValueIn3);    // PiBridge - read input pin
  74.         if(iLastInputValue3 != sValueIn3.i8uValue)        // if button state changed
  75.         {                                                // show the change
  76.             printf("%-32s : %d \n", pchInput3, sValueIn3.i8uValue);
  77.                 if(0 == iLastInputValue3)                // and was pressed before
  78.                 {    // switch light
  79.                     sValueOut4.i8uValue = ~sValueOut4.i8uValue;
  80.                         // PiBridge - set output pin
  81.                     i3 = piControlSetBitValue(&sValueOut4);
  82.                     printf("%-32s : %s \n", pchOutput4, sValueOut4.i8uValue ? "On" : "Off");
  83.                     sleep(0.5);    
  84.                     // -----                
  85.                     i3 = piControlGetBitValue(&sValueIn3);            // PiBridge - read input pin
  86.                     if(iLastInputValue3 != sValueIn3.i8uValue)        // if button state changed
  87.                     {    // show the change
  88.                         printf("%-32s : %d \n", pchInput2, sValueIn2.i8uValue);
  89.                             if(0 == iLastInputValue3)                // and was pressed before
  90.                             {                                        // switch light
  91.                     sValueOut2.i8uValue = ~sValueOut2.i8uValue;
  92.                                                                     // PiBridge - set output pin
  93.                     i3 = piControlSetBitValue(&sValueOut2);
  94.         printf("%-32s : %s \n", pchOutput2, sValueOut2.i8uValue ? "On" : "Off");
  95.                                 if(0 != i3)
  96.                                 {
  97.                                 fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i3);
  98.                                     return -1;
  99.                                 }
  100.                             }
  101.                         }
  102.                     }                    
  103.                     iLastInputValue4 = sValueIn4.i8uValue;            // remember last input value    
  104.                     iLastInputValue3 = sValueIn3.i8uValue;            // remember last input value    
  105.                     IO_5();
  106.             }
  107.         //printf("=== OK 2 ====");
  108. return 0;
  109. }
  110. // --- 4 ---
  111. int IO_4(void) {
  112.         i4 = piControlGetBitValue(&sValueIn4);            // PiBridge - read input pin
  113.         if(iLastInputValue4 != sValueIn4.i8uValue)        // if button state changed
  114.         {    // show the change
  115.             printf("%-32s : %d \n", pchInput4, sValueIn4.i8uValue);
  116.                 if(0 == iLastInputValue4)                // and was pressed before
  117.                 {    // switch light
  118.                     sValueOut3.i8uValue = ~sValueOut3.i8uValue;
  119.                     // PiBridge - set output pin
  120.                     i4 = piControlSetBitValue(&sValueOut3);
  121.                     printf("%-32s : %s \n", pchOutput3, sValueOut3.i8uValue ? "On" : "Off");
  122.                     sleep(0.1);        
  123.                     i4 = piControlGetBitValue(&sValueIn4);            // PiBridge - read input pin
  124.                     if(iLastInputValue4 != sValueIn4.i8uValue)        // if button state changed
  125.                     {    // show the change
  126.                         printf("%-32s : %d \n", pchInput4, sValueIn4.i8uValue);
  127.                             if(0 == iLastInputValue4)                // and was pressed before
  128.                             {                                        // switch light
  129.                                 sValueOut4.i8uValue = ~sValueOut4.i8uValue;
  130.             // PiBridge - set output pin
  131.                                 i4 = piControlSetBitValue(&sValueOut4);
  132.                                 printf("%-32s : %s \n", pchOutput4, sValueOut4.i8uValue ? "On" : "Off");
  133.                                 if(0 != i4)
  134.                                 {
  135.                                     fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i4);
  136.                                     return -1;
  137.                                 }
  138.                             }
  139.                         }
  140.                     }                
  141.                     IO_3();
  142.             }
  143.         iLastInputValue4 = sValueIn4.i8uValue;            // remember last input value    
  144. return 0;
  145. }
  146. // --- 5---
  147. int IO_5(void) {
  148.         i = piControlGetBitValue(&sValueIn);            // PiBridge - read input pin
  149.         if(0 != i)            // handle error
  150.         {
  151.             fprintf(stderr, "Error: piControlGetBitValue() returned %d\n", i);
  152.             return -1;
  153.         }
  154.         if(iLastInputValue != sValueIn.i8uValue)        // if button state changed
  155.         {    // show the change
  156.             printf("%-32s : %d \n", pchInput, sValueIn.i8uValue);
  157.             if(0 == sValueIn.i8uValue)                    // if button is released
  158.             {
  159.                 if(1 == iLastInputValue)                // and was pressed before
  160.                 {            // switch light
  161.                     sValueOut2.i8uValue = ~sValueOut2.i8uValue;
  162.                 // PiBridge - set output pin
  163.                     i = piControlSetBitValue(&sValueOut2);
  164.                     printf("%-32s : %s \n", pchOutput2, sValueOut2.i8uValue ? "On" : "Off");
  165.                     if(0 != i2)
  166.                     {
  167.                         fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i2);
  168.                         return -1;
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.         iLastInputValue = sValueIn.i8uValue;            // remember last input value        
  174. }
  175. // --- 6 ---
  176. int IO_6(void) {
  177.         i6 = piControlGetBitValue(&sValueIn6);            // PiBridge - read input pin
  178.         if(0 != i6)        // handle error
  179.         {
  180.             fprintf(stderr, "Error: piControlGetBitValue() returned %d\n", i6);
  181.             return -1;
  182.         }
  183.         if(iLastInputValue6 != sValueIn6.i8uValue)        // if button state changed
  184.         {            // show the change
  185.             printf("%-32s : %d \n", pchInput6, sValueIn6.i8uValue);
  186.             if(0 == sValueIn6.i8uValue)                    // if button is released
  187.             {
  188.                 if(1 == iLastInputValue6)                // and was pressed before
  189.                 {    // switch light
  190.                     sValueOut6.i8uValue = ~sValueOut6.i8uValue;
  191.                     // PiBridge - set output pin
  192.                     i6 = piControlSetBitValue(&sValueOut6);
  193.                     printf("%-32s : %s \n", pchOutput6, sValueOut6.i8uValue ? "On" : "Off");
  194.                     if(0 != i6)
  195.                     {
  196.                         fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i6);
  197.                         return -1;
  198.                     }
  199.                 }
  200.             }
  201.         }
  202.         iLastInputValue6 = sValueIn6.i8uValue;            // remember last input value
  203. }
  204. // --- 7 ---
  205. int IO_7(void) {
  206.         i7 = piControlGetBitValue(&sValueIn7);            // PiBridge - read input pin
  207.         if(0 != i7)        // handle error
  208.         {
  209.             fprintf(stderr, "Error: piControlGetBitValue() returned %d\n", i7);
  210.             return -1;
  211.         }
  212.         if(iLastInputValue7 != sValueIn7.i8uValue)        // if button state changed
  213.         {                // show the change
  214.             printf("%-32s : %d \n", pchInput7, sValueIn7.i8uValue);
  215.             if(0 == sValueIn7.i8uValue)                    // if button is released
  216.             {
  217.                 if(1 == iLastInputValue7)                // and was pressed before
  218.                 {        // switch light
  219.                     sValueOut7.i8uValue = ~sValueOut7.i8uValue;
  220.                     // PiBridge - set output pin
  221.                     i7 = piControlSetBitValue(&sValueOut7);
  222.                     printf("%-32s : %s \n", pchOutput7, sValueOut7.i8uValue ? "On" : "Off");
  223.                     if(0 != i7)
  224.                     {
  225.                         fprintf(stderr, "Error: piControlSetBitValue() returned %d\n", i7);
  226.                         return -1;
  227.                     }
  228.                 }
  229.             }
  230.         }
  231.         iLastInputValue7 = sValueIn7.i8uValue;            // remember last input value    
  232. }

以下はメインプログラムです。

  1. int main(int argc, char ** argv)
  2. {    
  3.     pchInput = argv[1];    // PiCtory input pin for Switch
  4.     pchOutput = argv[2];    // PiCtory output pin for Light
  5.     pchInput2 = argv[3];    // PiCtory input pin for Switch
  6.     pchOutput2 = argv[4];    // PiCtory output pin for Light
  7.     pchInput3 = argv[5];    // PiCtory input pin for Switch
  8.     pchOutput3 = argv[6];    // PiCtory output pin for Light
  9.     pchInput4 = argv[7];    // PiCtory input pin for Switch
  10.     pchOutput4 = argv[8];    // PiCtory output pin for Light
  11.     pchInput5 = argv[9];    // PiCtory input pin for Switch
  12.     pchOutput5 = argv[10];    // PiCtory output pin for Light
  13.     pchInput6 = argv[11];    // PiCtory input pin for Switch
  14.     pchOutput6 = argv[12];    // PiCtory output pin for Light
  15.     pchInput7 = argv[13];    // PiCtory input pin for Switch
  16.     pchOutput7 = argv[14];    // PiCtory output pin for Light
  17.     strncpy(spiVariableIn.strVarName, pchInput, sizeof(spiVariableIn.strVarName));
  18.     strncpy(spiVariableOut.strVarName, pchOutput, sizeof(spiVariableOut.strVarName));
  19.     strncpy(spiVariableIn2.strVarName, pchInput2, sizeof(spiVariableIn2.strVarName));
  20.     strncpy(spiVariableOut2.strVarName, pchOutput2, sizeof(spiVariableOut2.strVarName));
  21.     strncpy(spiVariableIn3.strVarName, pchInput3, sizeof(spiVariableIn3.strVarName));
  22.     strncpy(spiVariableOut3.strVarName, pchOutput3, sizeof(spiVariableOut3.strVarName));
  23.     strncpy(spiVariableIn4.strVarName, pchInput4, sizeof(spiVariableIn4.strVarName));
  24.     strncpy(spiVariableOut4.strVarName, pchOutput4, sizeof(spiVariableOut4.strVarName));
  25.     strncpy(spiVariableIn5.strVarName, pchInput5, sizeof(spiVariableIn5.strVarName));
  26.     strncpy(spiVariableOut5.strVarName, pchOutput5, sizeof(spiVariableOut5.strVarName));
  27.     strncpy(spiVariableIn6.strVarName, pchInput6, sizeof(spiVariableIn6.strVarName));
  28.     strncpy(spiVariableOut6.strVarName, pchOutput6, sizeof(spiVariableOut6.strVarName));
  29.     strncpy(spiVariableIn7.strVarName, pchInput7, sizeof(spiVariableIn7.strVarName));
  30.     strncpy(spiVariableOut7.strVarName, pchOutput7, sizeof(spiVariableOut7.strVarName));    
  31.     
  32.     i = piControlGetVariableInfo(&spiVariableIn);        // PiBridge - get variable info
  33.     if(0 != i)            // handle error
  34.     {
  35.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  36.             i, spiVariableIn.strVarName);
  37.         return -1;
  38.     }
  39.     
  40.     i2 = piControlGetVariableInfo(&spiVariableIn2);        // PiBridge - get variable info
  41.     if(0 != i2)            // handle error
  42.     {
  43.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  44.             i2, spiVariableIn2.strVarName);
  45.         return -1;
  46.     }
  47.     
  48.     i3 = piControlGetVariableInfo(&spiVariableIn3);        // PiBridge - get variable info
  49.     if(0 != i3)            // handle error
  50.     {
  51.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  52.             i3, spiVariableIn3.strVarName);
  53.         return -1;
  54.     }    
  55.     
  56.     i4 = piControlGetVariableInfo(&spiVariableIn4);        // PiBridge - get variable info
  57.     if(0 != i4)        // handle error
  58.     {
  59.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  60.             i4, spiVariableIn4.strVarName);
  61.         return -1;
  62.     }    
  63.     
  64.     i5 = piControlGetVariableInfo(&spiVariableIn5);        // PiBridge - get variable info
  65.     if(0 != i5)            // handle error
  66.     {
  67.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  68.             i5, spiVariableIn5.strVarName);
  69.         return -1;
  70.     }    
  71.     
  72.     i6 = piControlGetVariableInfo(&spiVariableIn6);        // PiBridge - get variable info
  73.     if(0 != i6)            // handle error
  74.     {
  75.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  76.             i6, spiVariableIn6.strVarName);
  77.         return -1;
  78. }    
  79.     
  80.     i7 = piControlGetVariableInfo(&spiVariableIn7);        // PiBridge - get variable info
  81.     if(0 != i7)            // handle error
  82.     {
  83.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  84.             i7, spiVariableIn7.strVarName);
  85.         return -1;
  86.     }    
  87.     // =============================
  88.     i = piControlGetVariableInfo(&spiVariableOut);        // PiBridge - get variable info
  89.     if(0 != i)                // handle error
  90.     {
  91.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  92.             i, spiVariableOut.strVarName);
  93.         return -1;
  94.     }
  95.     
  96.     i2 = piControlGetVariableInfo(&spiVariableOut2);        // PiBridge - get variable info
  97.     if(0 != i2)                // handle error
  98.     {
  99.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  100.             i2, spiVariableOut2.strVarName);
  101.         return -1;
  102.     }
  103.     
  104.     i3 = piControlGetVariableInfo(&spiVariableOut3);        // PiBridge - get variable info
  105.     if(0 != i3)            // handle error
  106.     {
  107.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  108.             i3, spiVariableOut3.strVarName);
  109.         return -1;
  110.     }
  111.     i4 = piControlGetVariableInfo(&spiVariableOut4);        // PiBridge - get variable info
  112.     if(0 != i4)        // handle error
  113.     {
  114.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  115.             i4, spiVariableOut4.strVarName);
  116.         return -1;
  117.     }
  118.     
  119.     i5 = piControlGetVariableInfo(&spiVariableOut5);        // PiBridge - get variable info
  120.     if(0 != i5)            // handle error
  121.     {
  122.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  123.             i5, spiVariableOut.strVarName);
  124.         return -1;
  125.     }
  126.     
  127.     i6 = piControlGetVariableInfo(&spiVariableOut6);        // PiBridge - get variable info
  128.     if(0 != i6)            // handle error
  129.     {
  130.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  131.             i6, spiVariableOut.strVarName);
  132.         return -1;
  133.     }    
  134.     i7 = piControlGetVariableInfo(&spiVariableOut7);        // PiBridge - get variable info
  135.     if(0 != i7)        // handle error
  136.     {
  137.         fprintf(stderr, "Error: piControlGetVariableInfo() returned %d for variable '%s' \n",
  138.             i7, spiVariableOut.strVarName);
  139.         return -1;
  140.     }    
  141.     // =============================
  142.     sValueIn.i16uAddress = spiVariableIn.i16uAddress;
  143.     sValueIn.i8uBit = spiVariableIn.i8uBit;
  144.     sValueIn.i8uValue = 0;
  145.     sValueOut.i16uAddress = spiVariableOut.i16uAddress;
  146.     sValueOut.i8uBit = spiVariableOut.i8uBit;
  147.     sValueOut.i8uValue = 0;
  148.     // --------------- 2
  149.     sValueIn2.i16uAddress = spiVariableIn2.i16uAddress;
  150.     sValueIn2.i8uBit = spiVariableIn2.i8uBit;
  151.     sValueIn2.i8uValue = 0;
  152.     sValueOut2.i16uAddress = spiVariableOut2.i16uAddress;
  153.     sValueOut2.i8uBit = spiVariableOut2.i8uBit;
  154.     sValueOut2.i8uValue = 0;
  155.     // ----------------- 3
  156.     sValueIn3.i16uAddress = spiVariableIn3.i16uAddress;
  157.     sValueIn3.i8uBit = spiVariableIn3.i8uBit;
  158.     sValueIn3.i8uValue = 0;
  159.     sValueOut3.i16uAddress = spiVariableOut3.i16uAddress;
  160.     sValueOut3.i8uBit = spiVariableOut3.i8uBit;
  161.     sValueOut3.i8uValue = 0;
  162.     // ------------------- 4
  163.     sValueIn4.i16uAddress = spiVariableIn4.i16uAddress;
  164.     sValueIn4.i8uBit = spiVariableIn4.i8uBit;
  165.     sValueIn4.i8uValue = 0;
  166.     sValueOut4.i16uAddress = spiVariableOut4.i16uAddress;
  167.     sValueOut4.i8uBit = spiVariableOut4.i8uBit;
  168.     sValueOut4.i8uValue = 0;
  169.     // ------------------- 5
  170.     sValueIn5.i16uAddress = spiVariableIn5.i16uAddress;
  171.     sValueIn5.i8uBit = spiVariableIn5.i8uBit;
  172.     sValueIn5.i8uValue = 0;
  173.     sValueOut5.i16uAddress = spiVariableOut5.i16uAddress;
  174.     sValueOut5.i8uBit = spiVariableOut5.i8uBit;
  175.     sValueOut5.i8uValue = 0;
  176.     // ------------------- 6
  177.     sValueIn6.i16uAddress = spiVariableIn6.i16uAddress;
  178.     sValueIn6.i8uBit = spiVariableIn6.i8uBit;
  179.     sValueIn6.i8uValue = 0;
  180.     sValueOut6.i16uAddress = spiVariableOut6.i16uAddress;
  181.     sValueOut6.i8uBit = spiVariableOut6.i8uBit;
  182.     sValueOut6.i8uValue = 0;
  183.     // ------------------- 7
  184.     sValueIn7.i16uAddress = spiVariableIn7.i16uAddress;
  185.     sValueIn7.i8uBit = spiVariableIn7.i8uBit;
  186.     sValueIn7.i8uValue = 0;
  187.     sValueOut7.i16uAddress = spiVariableOut7.i16uAddress;
  188.     sValueOut7.i8uBit = spiVariableOut7.i8uBit;
  189.     sValueOut7.i8uValue = 0;
  190.     // -----------------
  191.     printf("%s is running waiting for switch '%s' \n", argv[0], pchInput);
  192.     printf("%s is running waiting for switch '%s' \n", argv[1], pchInput2);
  193.     printf("%s is running waiting for switch '%s' \n", argv[2], pchInput3);
  194.     printf("%s is running waiting for switch '%s' \n", argv[3], pchInput4);
  195.     printf("%s is running waiting for switch '%s' \n", argv[4], pchInput5);
  196.     printf("%s is running waiting for switch '%s' \n", argv[5], pchInput6);
  197.     printf("%s is running waiting for switch '%s' \n\n\n", argv[6], pchInput7);
  198.     while(1)
  199.     {
  200.         IO_1();
  201.         IO_2();
  202.         IO_3();
  203.         IO_4();
  204.         IO_5();
  205.         IO_6();
  206.         IO_7();
  207.     }
  208.     return 0;
  209. }

マンドラインからプログラムの実行

デスクトップ画面からコマンドライン

demoフォルダへ移動

cd demo

piTest.c をコンパイルします。

make

プログラムを実行します!

./piTest I_1 O_1 I_2 O_2 I_3 O_3 I_4 O_4 I_5 O_5 I_6 O_6 I_7 O_7
実行時のコマンドライン
https://twitter.com/inFT37207295/status/1438057437991292929
完成プログラム実行動画のツイート

パンチングマシンをレボリューションパイで動作させることができました!

ご覧いただきありがとうございました!

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です