gclib  2.0.8
Communications API for Galil controllers and PLCs
Contour.vb
Go to the documentation of this file.
1 Partial Public Module Examples
2  Public Function Contour(gclib As Gclib, fileA As String, fileB As String) As Integer
3  Record_Position(gclib, fileA, fileB) 'Record positional data on Axis A and B
4 
5  Dim positions_A = System.IO.File.ReadAllText(fileA).Split(",").ToList()
6  Dim positions_B = System.IO.File.ReadAllText(fileB).Split(",").ToList()
7 
8  gclib.GCommand("SH AB") 'Set servo here
9  gclib.GCommand("PA 0, 0") 'Set current position To 0
10  gclib.GMotionComplete("AB") 'Wait For motion To complete
11  gclib.GCommand("CM AB") 'Put axis A & B In contour mode
12  gclib.GCommand("DT -1") 'Pauses contour mode To pre-load buffer
13  gclib.GCommand("CD 0,0") 'Pre load buffer With zeros To prevent under buffering
14  gclib.GCommand("CD 0,0") 'Pre load buffer With zeros To prevent under buffering
15  gclib.GCommand("CD 0,0") 'Pre load buffer With zeros To prevent under buffering
16  gclib.GCommand("DT 1") 'Sets the time interval For contour mode To be 2 samples
17 
18  Dim capacity = 0 'Holds the capacity of the contour buffer
19  Dim cmd = 0 'Holds the counter for which position to send next
20 
21  If positions_A.Count <> positions_B.Count() Then
22  Console.WriteLine("Error: The two datasets are not the same size")
23  Return Examples.GALIL_EXAMPLE_ERROR
24  End If
25 
26  Do
27  'Sleep while buffer is emptying
28  System.Threading.Thread.Sleep(400)
29 
30  'Stores the available space of the contour buffer in the capacity variable
31  capacity = gclib.GCmdI("CM?")
32  Loop While Load_Buffer(gclib, positions_A, positions_B, capacity, cmd)
33 
34  gclib.GCommand("CD 0,0=0") 'End contour mode
35 
36  Return Examples.GALIL_EXAMPLE_OK
37 
38  End Function
39 
40  Private Function Load_Buffer(gclib As Gclib, positions_A As List(Of String), positions_B As List(Of String),
41  capacity As Integer, ByRef cmd As Integer)
42  For i = capacity To 1 Step -1
43  If cmd + 1 < positions_A.Count() Then
44  'Subtract previous position from new position to get how for of a move to make
45  Dim cdA = Double.Parse(positions_A(cmd + 1)) - Double.Parse(positions_A(cmd))
46 
47  'Subtract previous position from new position to get how for of a move to make
48  Dim cdB = Double.Parse(positions_B(cmd + 1)) - Double.Parse(positions_B(cmd))
49 
50  gclib.GCommand($"CD {cdA},{cdB}")
51 
52  cmd = cmd + 1
53  Else
54  Return False
55  End If
56  Next
57  Return True
58  End Function
59 End Module
string GCommand(string Command, bool Trim=true)
Used for command-and-response transactions.
Definition: gclib.cs:257
Int16 GCmdI(string Command)
Used for command-and-response transactions.
Definition: gclib.cs:288
Provides a class that binds to gclib's unmanaged dll. Wraps each call and provides a more user-friend...
Definition: gclib.cs:68
GReturn contour(GCon g, char *fileA, char *fileB)
Record user's training and plays back training through contour mode.
Definition: contour.cpp:20
partial Module Examples
Definition: Commands.vb:4