gclib  1.36.3
Communications API for Galil controllers and PLCs
contour.cs
Go to the documentation of this file.
1 
10 using System;
11 using System.Collections.Generic;
12 using System.Linq;
13 using System.IO;
14 using System.Threading;
15 
16 namespace examples
17 {
18  public static partial class Examples
19  {
31 
32  public static int Contour(gclib gclib, string fileA, string fileB)
33  {
34  Record_Position(gclib, fileA, fileB); //Record positional data on Axis A and B
35 
36  List<string> positions_A = File.ReadAllText(fileA).Split(',').ToList();
37  List<string> positions_B = File.ReadAllText(fileB).Split(',').ToList();
38 
39  gclib.GCommand("SH AB"); //Set servo here
40  gclib.GCommand("PA 0, 0"); //Set current position to 0
41  gclib.GMotionComplete("AB"); //Wait for motion to complete
42  gclib.GCommand("CM AB"); //Put axis A & B in contour mode
43  gclib.GCommand("DT -1"); //Pauses contour mode to pre-load buffer
44  gclib.GCommand("CD 0,0"); //Pre load buffer with zeros to prevent under buffering
45  gclib.GCommand("CD 0,0"); //Pre load buffer with zeros to prevent under buffering
46  gclib.GCommand("CD 0,0"); //Pre load buffer with zeros to prevent under buffering
47  gclib.GCommand("DT 1"); //Sets the time interval for contour mode to be 2 samples
48 
49  int capacity = 0; //Holds the capacity of the contour buffer
50  int cmd = 0; //Holds the counter for which position to send next
51 
52  if (positions_A.Count() != positions_B.Count())
53  {
54  Console.WriteLine("Error: The two datasets are not the same size");
56  }
57 
58  do
59  {
60  //Sleep while buffer is emptying
61  Thread.Sleep(400);
62 
63  //Stores the available space of the contour buffer in the capacity variable
64  capacity = gclib.GCmdI("CM?");
65  } while (Load_Buffer(gclib, positions_A, positions_B, capacity, ref cmd));
66 
67  gclib.GCommand("CD 0,0=0"); //End contour mode
68 
70  }
71 
72  private static bool Load_Buffer(gclib gclib, List<string> positions_A, List<string> positions_B,
73  int capacity, ref int cmd)
74  {
75  for (; capacity > 0; capacity--) //Fully load contour buffer
76  {
77  if (cmd + 1 < positions_A.Count())
78  {
79  //Subtract previous position from new position to get how far of a move to make
80  double cdA = double.Parse(positions_A[cmd + 1]) - double.Parse(positions_A[cmd]);
81 
82  //Subtract previous position from new position to get how far of a move to make
83  double cdB = double.Parse(positions_B[cmd + 1]) - double.Parse(positions_B[cmd]);
84 
85  gclib.GCommand($"CD {cdA},{cdB}");
86 
87  cmd++;
88  }
89  else
90  return false;
91  }
92  return true;
93  }
95  }
96 }
Provides a class of shared constants and methods for gclib's example projects.
Definition: commands.cs:16
const int GALIL_EXAMPLE_OK
Examples success code.
Definition: examples.cs:29
const int GALIL_EXAMPLE_ERROR
Examples error code.
Definition: examples.cs:30
static int Record_Position(gclib gclib, string fileA, string fileB)
Record user's training and saves to a text file.
static int Contour(gclib gclib, string fileA, string fileB)
Record user's training and plays back training through contour mode.
Definition: contour.cs:32