using RSI.RapidCode.dotNET;
using System;
{
class VelocitySetByAnalogInputValue
{
static void Main(string[] args)
{
double analogMaxValue = 65536;
double currentVelocity = 0;
double analogCurrentValue = 0;
double analogValuePrecentage = 0;
double velocityAbsoluteSum = 0;
const int AXIS_NUMBER = 0;
const int NODE_NUMBER = 0;
const int ANALOG_INPUT_0 = 0;
const int MIN_VEL = -10;
const int MAX_VEL = 10;
const int ACC = 100;
const int USER_UNITS = 1048576;
IO ioNode = controller.
IOGet(NODE_NUMBER);
try
{
Console.WriteLine("Velocity Move Initialized.");
Console.WriteLine("Max Speed = " + MAX_VEL);
Console.WriteLine("Min Speed = " + MIN_VEL);
Console.WriteLine("\nPress SPACEBAR to exit.");
do
{
while (!Console.KeyAvailable)
{
velocityAbsoluteSum = Math.Abs(MIN_VEL) + Math.Abs(MAX_VEL);
analogCurrentValue = (double)ioNode.
AnalogInGet(ANALOG_INPUT_0);
analogValuePrecentage = analogCurrentValue / analogMaxValue;
if (analogValuePrecentage * 100 > 99 || analogValuePrecentage * 100 < 1)
currentVelocity = 0;
else if (analogValuePrecentage * 100 < 50)
currentVelocity = velocityAbsoluteSum * analogValuePrecentage;
else
currentVelocity = -velocityAbsoluteSum + (velocityAbsoluteSum * analogValuePrecentage);
}
} while (Console.ReadKey(true).Key != ConsoleKey.Spacebar);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}