#include "rsi.h"
#include "HelperFunctions.h"
#include <cmath>
void VelocitySetByAnalogInputValueMain()
{
using namespace RSI::RapidCode;
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;
char rmpPath[] = "C:\\RSI\\X.X.X\\";
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
try
{
SampleAppsCPP::HelperFunctions::StartTheNetwork(controller);
SampleAppsCPP::HelperFunctions::CheckErrors(axis);
printf("\nVelocity Move Initialized.");
printf("\nMax Speed = %d ", MAX_VEL);
printf("\nMin Speed = %d ", MIN_VEL);
printf("\n\nPress ENTER to update analog reading");
printf("\nPress SPACEBAR+ENTER to exit.");
char input = 0;
while (1) {
input = getchar();
velocityAbsoluteSum = std::abs(MIN_VEL) + std::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);
if (input == ' ') {
break;
}
}
}
{
printf(
"%s\n", err.
text);
}
system("pause");
}