Hi,
I'm trying to write a motion control program. I wrote some code to generate XY coordinates starting from beginning to the end of the arc. The code works very well but it is extremely slow. The code was originally written in VB6 but I decided to try C++ to evaluate the performance compared to VB6. Circles handles an arc with more than a 360 arcsweep. I'm breaking the arc length into pieces .0001" in arc length and then using the number of pieces to drive the process. I'm also using the number of pieces to generate incremental arc angle increase. Please bear in mind that I'm not a C++ programmer.
As always your assistance is appreciated,
C4C
I'm trying to write a motion control program. I wrote some code to generate XY coordinates starting from beginning to the end of the arc. The code works very well but it is extremely slow. The code was originally written in VB6 but I decided to try C++ to evaluate the performance compared to VB6. Circles handles an arc with more than a 360 arcsweep. I'm breaking the arc length into pieces .0001" in arc length and then using the number of pieces to drive the process. I'm also using the number of pieces to generate incremental arc angle increase. Please bear in mind that I'm not a C++ programmer.
As always your assistance is appreciated,
C4C
Code:
/*
CppTest.cpp : Defines the entry point for the console application.
*/
#include "stdafx.h"
#include <math.h>
#include <stdio.h>
#include <windows.h>
#define and &&
double Angle = 0;
double ArcLen = 0;
double ArcStart = 0;
double ArcSweep = 360;
double Circles = 0;
double CurX = 0;
double CurY = 0;
double CurZ = 0;
double EndAngle = 0;
double Inc = 0;
long n = 0;
double NewX = 0;
double NewY = 0;
long p = 0;
double pi = 3.14159265358979;
double Radius = 5.0;
double Segment =.0001;
long Speed = 0;
long SpeedX = 0;
long SpeedY = 0;
int Test = 0;
char XY_POS[32] = "";
long nx = 0;
int main(int argc, char* argv[])
{
Circles = ((ArcSweep) / 360);
if (Circles < 0)
{
Circles = (0 - Circles);
}
ArcLen = (((Radius * 2) * pi) * Circles);
Inc = (ArcSweep / (ArcLen / Segment));
if (ArcSweep > 360)
{
EndAngle = (ArcStart + (360 * ((ArcSweep / 360) - int(ArcSweep / 360))));
}
else
{
EndAngle = (ArcStart + ArcSweep);
}
if (EndAngle < 0)
{
EndAngle = EndAngle + 360;
}
if (EndAngle > 360)
{
EndAngle = EndAngle - 360;
}
p = int(ArcLen / Segment);
nx = p;
for(n = 1; n < p; n++)
{
Angle = Angle + Inc;
nx = nx - 1;
//printf("%d\n", n);
if (ArcSweep > 0)
{
if (Angle > 360)
{
Angle = Angle - 360;
}
}
if (ArcSweep < 0)
{
if (Angle < 360)
{
Angle = Angle + 360;
}
}
if (nx == 0)
{
Angle = EndAngle;
}
NewY = (sin(Angle) * Radius);
NewX = sqrt((Radius * Radius) - (NewY * NewY));
if (Angle > 90 && Angle < 270)
{
NewX = (0 - NewX);
}
printf("%.4f", NewX);
printf("%s", "/");
printf("%.4f\n", NewY);
}
return 0;
}