| gclib 1.34.15 Communications API for Galil controllers and PLCs |

motion_complete.cs
Go to the documentation of this file.
1
10 using System;
11
12 namespace examples
13 {
14 public static partial class Examples
15 {
25
26 public static int Motion_Complete(gclib gclib)
27 {
28 Console.WriteLine("*************************************************************");
29 Console.WriteLine("Example GInterrupt() usage");
30 Console.WriteLine("*************************************************************");
31
32 //Simple check for appropriate communication bus
33 //EI will fail below if interrupts are not supported at all
34 bool ei_support = false;
35
36 if (gclib.GCommand("WH").Contains("IH"))
37 ei_support = true;
38
39 if (!ei_support)
40 {
41 Console.WriteLine("No support on this bus");
42 return GALIL_EXAMPLE_ERROR;
43 }
44
45 //Flush interrupts
46 gclib.GCommand("EI0,0"); //Turn off interrupts
47 gclib.GTimeout(0); //Zero timeout
48
49 //Flush interrupts, status will be zero when queue is empty
50 while (gclib.GInterrupt() > 0) ;
51
52 gclib.GTimeout(-1); //Restore timeout
53
54 //Independent Motion
55 gclib.GCommand("DP 0,0"); //define position zero on A and B
56 Console.WriteLine("Position: " + gclib.GCommand("RP")); //Print reference position
57
58 gclib.GCommand("SP 4000,4000"); //Set up speed
59 gclib.GCommand("AC 1280000, 1280000"); //acceleration
60 gclib.GCommand("DC 1280000, 1280000"); //deceleration
61 gclib.GCommand("PR 8000, 10000"); //Position Relative. B will take longer to make its move.
62 gclib.GCommand("SH AB"); //Servo Here
63
64 Console.WriteLine("Beginning independent motion...");
65 gclib.GCommand("BG AB"); //Begin motion
66 Check_Interrupts(gclib, "AB"); //Block until motion is complete on axes A and B
67 Console.WriteLine("Motion Complete on A and B");
68 Console.WriteLine("Position: " + gclib.GCommand("RP")); //Print reference position
69
70 return GALIL_EXAMPLE_OK;
71 }
72
73 private static void Check_Interrupts(gclib gclib, string axes)
74 {
75 //bit mask of running axes, axes arg is trusted to provide running axes.
76 //Low bit indicates running.
77 byte axis_mask = 0xFF;
78
79 //iterate through all chars in axes to make the axis mask
80 for (int i = 0; i < axes.Length; i++)
81 {
82 //support just A-H
83 switch (axes[i])
84 {
85 case 'A':
86 axis_mask &= 0xFE;
87 break;
88 case 'B':
89 axis_mask &= 0xFD;
90 break;
91 case 'C':
92 axis_mask &= 0xFB;
93 break;
94 case 'D':
95 axis_mask &= 0xF7;
96 break;
97 case 'E':
98 axis_mask &= 0xEF;
99 break;
100 case 'F':
101 axis_mask &= 0xDF;
102 break;
103 case 'G':
104 axis_mask &= 0xBF;
105 break;
106 case 'H':
107 axis_mask &= 0x7F;
108 break;
109 }
110 }
111
112 //send EI axis mask to set up interrupt events.
113 gclib.GCommand("EI " + ~axis_mask);
114
115 byte status;
116
117 while (axis_mask != 0xFF) //wait for all interrupts to come in
118 {
119 switch (status = gclib.GInterrupt())
120 {
121 case 0xD0: //Axis A complete
122 axis_mask |= 0x01;
123 break;
124 case 0xD1: //Axis B complete
125 axis_mask |= 0x02;
126 break;
127 case 0xD2: //Axis C complete
128 axis_mask |= 0x04;
129 break;
130 case 0xD3: //Axis D complete
131 axis_mask |= 0x08;
132 break;
133 case 0xD4: //Axis E complete
134 axis_mask |= 0x10;
135 break;
136 case 0xD5: //Axis F complete
137 axis_mask |= 0x20;
138 break;
139 case 0xD6: //Axis G complete
140 axis_mask |= 0x40;
141 break;
142 case 0xD7: //Axis H complete
143 axis_mask |= 0x80;
144 break;
145 }
146 }
147 }
149 }
150 }
examples.Examples.GALIL_EXAMPLE_OK
const int GALIL_EXAMPLE_OK
Examples success code.
Definition: examples.cs:29
examples.Examples.GALIL_EXAMPLE_ERROR
const int GALIL_EXAMPLE_ERROR
Examples error code.
Definition: examples.cs:30
examples.Examples.Motion_Complete
static int Motion_Complete(gclib gclib)
Uses interrupts to track when the motion of controller is completed.
Definition: motion_complete.cs:26
examples
Definition: commands.cs:14