OldRon
Well-Known Member
- Joined
- Oct 17, 2012
- Messages
- 45
- Reaction score
- 3
Below is the start of the code for automating my rotary table. The code calculates the number of pulses required for the Yaskawa servo motor which will be running at 3:1 reduction. The fractional part of the pulses is fed back into the process. That basically eliminates accumulated error. The code below is a console program that loops from 359º to 360º and outputs the Commanded Position, Output Position, Number of Pulses and the Error in Seconds.
L O G I C:
Table gear ratio: 90:1
Degrees per Table Revolution: 4
Degree(Seconds) per Table Revolution: 14400 (((1 x 60) x 60) x 4)
Motor Pulses per Revolution: 2048
Pulses x Gear Ratio: 6144
Pulses per Degree(Second): 14400 / 6144 = 2.34375
Table Resolution: 1 Second: (2.34375 Pulses )
That logic will work with any Step & Direction motor but table resolution increment goes up as motor pulses go down. With low motor pulses positioning speed also increase the resolution increment.
The Code:
// Get Pulses
#include <stdafx.h>
#include <iostream>
using namespace std;
void main()
{
double degrees=360;
double poserr=0;
double pulses=0;
for (degrees=359; degrees<360
{
pulses=(((degrees*3600)/2.34375)+poserr); // Eat the previous Error.
if ((pulses-int(pulses))>=.5)
{
poserr=(pulses-int(pulses+1));
pulses=int(pulses+1);
}
else if (pulses-int(pulses)<.5)
{
poserr=(pulses-int(pulses));
pulses=int(pulses);
}
std::cout << "Command: " << degrees;
std::cout << " - Output: " << ((pulses/3600)*2.34375);
std::cout << " - Pulses: " << pulses;
std::cout << " - Error: " << ((poserr/3600)*2.34375);
std::cout << "\n";
std::cout << "\n";
degrees=(degrees+.01);
}
std::cin.get();
}
L O G I C:
Table gear ratio: 90:1
Degrees per Table Revolution: 4
Degree(Seconds) per Table Revolution: 14400 (((1 x 60) x 60) x 4)
Motor Pulses per Revolution: 2048
Pulses x Gear Ratio: 6144
Pulses per Degree(Second): 14400 / 6144 = 2.34375
Table Resolution: 1 Second: (2.34375 Pulses )
That logic will work with any Step & Direction motor but table resolution increment goes up as motor pulses go down. With low motor pulses positioning speed also increase the resolution increment.
The Code:
// Get Pulses
#include <stdafx.h>
#include <iostream>
using namespace std;
void main()
{
double degrees=360;
double poserr=0;
double pulses=0;
for (degrees=359; degrees<360
{
pulses=(((degrees*3600)/2.34375)+poserr); // Eat the previous Error.
if ((pulses-int(pulses))>=.5)
{
poserr=(pulses-int(pulses+1));
pulses=int(pulses+1);
}
else if (pulses-int(pulses)<.5)
{
poserr=(pulses-int(pulses));
pulses=int(pulses);
}
std::cout << "Command: " << degrees;
std::cout << " - Output: " << ((pulses/3600)*2.34375);
std::cout << " - Pulses: " << pulses;
std::cout << " - Error: " << ((poserr/3600)*2.34375);
std::cout << "\n";
std::cout << "\n";
degrees=(degrees+.01);
}
std::cin.get();
}