40
41 double analogMaxValue = 65536;
42 double currentVelocity = 0;
43 double analogCurrentValue = 0;
44 double analogValuePrecentage = 0;
45 double velocityAbsoluteSum = 0;
46
47
48 const int AXIS_NUMBER = 0;
49 const int NODE_NUMBER = 0;
50 const int ANALOG_INPUT_0 = 0;
51 const int MIN_VEL = -10;
52 const int MAX_VEL = 10;
53 const int ACC = 100;
54 const int USER_UNITS = 1048576;
55
56
60
63
64 IO ioNode = controller.
IOGet(NODE_NUMBER);
66
67 try
68 {
69
70 Console.WriteLine("Velocity Move Initialized.");
71 Console.WriteLine("Max Speed = " + MAX_VEL);
72 Console.WriteLine("Min Speed = " + MIN_VEL);
73 Console.WriteLine("\nPress SPACEBAR to exit.");
74
75
84
85 do
86 {
87 while (!Console.KeyAvailable)
88 {
89 velocityAbsoluteSum = Math.Abs(MIN_VEL) + Math.Abs(MAX_VEL);
90 analogCurrentValue = (double)ioNode.AnalogInGet(ANALOG_INPUT_0);
91 analogValuePrecentage = analogCurrentValue / analogMaxValue;
92
93
94
95
96
97
98
99
100 if (analogValuePrecentage * 100 > 99 || analogValuePrecentage * 100 < 1)
101 currentVelocity = 0;
102
103 else if (analogValuePrecentage * 100 < 50)
104 currentVelocity = velocityAbsoluteSum * analogValuePrecentage;
105
106 else
107 currentVelocity = -velocityAbsoluteSum + (velocityAbsoluteSum * analogValuePrecentage);
108
110
111 }
112 } while (Console.ReadKey(true).Key != ConsoleKey.Spacebar);
113
115 }
116 catch (Exception e)
117 {
118 Console.WriteLine(e.Message);
119 }