35
36 double analogMaxValue = 65536;
37 double currentVelocity = 0;
38 double analogCurrentValue = 0;
39 double analogValuePrecentage = 0;
40 double velocityAbsoluteSum = 0;
41
42
43 const int AXIS_NUMBER = 0;
44 const int NODE_NUMBER = 0;
45 const int ANALOG_INPUT_0 = 0;
46 const int MIN_VEL = -10;
47 const int MAX_VEL = 10;
48 const int ACC = 100;
49 const int USER_UNITS = 1048576;
50
51
55
58
59 IO ioNode = controller.
IOGet(NODE_NUMBER);
61
62 try
63 {
64
65 Console.WriteLine("Velocity Move Initialized.");
66 Console.WriteLine("Max Speed = " + MAX_VEL);
67 Console.WriteLine("Min Speed = " + MIN_VEL);
68 Console.WriteLine("\nPress SPACEBAR to exit.");
69
70
79
80 do
81 {
82 while (!Console.KeyAvailable)
83 {
84 velocityAbsoluteSum = Math.Abs(MIN_VEL) + Math.Abs(MAX_VEL);
85 analogCurrentValue = (double)ioNode.AnalogInGet(ANALOG_INPUT_0);
86 analogValuePrecentage = analogCurrentValue / analogMaxValue;
87
88
89
90
91
92
93
94
95 if (analogValuePrecentage * 100 > 99 || analogValuePrecentage * 100 < 1)
96 currentVelocity = 0;
97
98 else if (analogValuePrecentage * 100 < 50)
99 currentVelocity = velocityAbsoluteSum * analogValuePrecentage;
100
101 else
102 currentVelocity = -velocityAbsoluteSum + (velocityAbsoluteSum * analogValuePrecentage);
103
105
106 }
107 } while (Console.ReadKey(true).Key != ConsoleKey.Spacebar);
108
110 }
111 catch (Exception e)
112 {
113 Console.WriteLine(e.Message);
114 }