gclib 2.0.9
Communications API for Galil controllers and PLCs
 
Loading...
Searching...
No Matches
position_tracking.cs
Go to the documentation of this file.
1
10using System;
11
12namespace examples
13{
14 public static partial class Examples
15 {
27
28 public static int Position_Tracking(gclib gclib, int speed)
29 {
30 int acc = 100 * speed; // Set acceleration/deceleration to 100 times speed
31
32 gclib.GCommand("STA"); // Stop motor
33 gclib.GMotionComplete("A"); // Wait for motion to complete
34 gclib.GCommand("SHA"); // Set servo here
35 gclib.GCommand("DPA=0"); // Start position at absolute zero
36 gclib.GCommand("PTA=1"); // Start position tracking mode on A axis
37
38 gclib.GCommand("SPA=" + speed); // Set speed
39 gclib.GCommand("ACA=" + acc); // Set acceleration
40 gclib.GCommand("DCA=" + acc); // Set deceleration
41
42 Console.WriteLine("Begin Position Tracking with speed " + speed +
43 ". Enter a non-number to exit.\n");
44 int position;
45
46 //Loop asking user for new position. End loop when user enters a non-number
47 while (true)
48 {
49 Console.WriteLine("Enter a new position:");
50 bool ok = int.TryParse(Console.ReadLine(), out position);
51
52 if (ok) //A valid position was provided
53 {
54 gclib.GCommand("PAA=" + position); // Go to new position
55 }
56 else //A non-number was entered
57 {
58 Console.WriteLine("Position Tracking has exited");
59 break;
60 }
61 }
62
63 gclib.GCommand("STA"); //stop motor
64 gclib.GMotionComplete("A"); //Wait for motion to complete
65
66 return GALIL_EXAMPLE_OK;
67 }
69 }
70}
const int GALIL_EXAMPLE_OK
Examples success code.
Definition examples.cs:29
string GCommand(string Command, bool Trim=true)
Used for command-and-response transactions.
Definition gclib.cs:257
void GMotionComplete(string axes)
Blocking call that returns once all axes specified have completed their motion.
Definition gclib.cs:428
Provides a class that binds to gclib's unmanaged dll. Wraps each call and provides a more user-friend...
Definition gclib.cs:68
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.
Definition vector.cpp:36
static int Position_Tracking(gclib gclib, int speed)
Puts controller into Position Tracking Mode and accepts user-entered positions.
partial Module Examples
Definition Commands.vb:4