Automating Rotary Table

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

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();
}
 
If you're declaring 'using namespace std;' then you don't need to reference the std:: in your input/outputs. However, best practice is not to declare namespace std so you would need to include the references to std:: each time you use them. As it stands now, you have the worst of both worlds (extra typing along with the risks and memory demands of namespace std).
 
If you're declaring 'using namespace std;' then you don't need to reference the std:: in your input/outputs. However, best practice is not to declare namespace std so you would need to include the references to std:: each time you use them. As it stands now, you have the worst of both worlds (extra typing along with the risks and memory demands of namespace std).

That bit of code is my first whack at C++ so your advice is greatly appreciated. First thing this morning it dawned on me that there was no need for the second conditional statement because if the first condition failed then 'else' it had to be the default. The if and else could be eliminated if I could figure out why 'round' is an undeclared identifier. I was told to include math.h and that didn't resolve the error.

Ron
 
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 )

In this description of the logic, I think you've got your understanding of the ratio upside down. There are 14400 seconds per revolution of the table input, and the servo + gear reduction requires 6144 pulses per revolution. 14400 sec per rev / 6144 pulses per rev = 2.34375 seconds per pulse - not the other way around. Likewise, it does not take 2.34375 pulses to achieve 1 second; 1 pulse gives a movement of 2.34375 seconds.

Note that in the code, however, it looks like you are applying the ratio correctly, dividing the number of seconds by 2.34375 seconds per pulse.
 
First thing this morning it dawned on me that there was no need for the second conditional statement because if the first condition failed then 'else' it had to be the default. The if and else could be eliminated if I could figure out why 'round' is an undeclared identifier. I was told to include math.h and that didn't resolve the error.

You don't need the second conditional but it doesn't hurt anything. Try #include <cmath> and round() should work (for C++ 11 onwards).
 
awake

I thought that I had that nailed down. It's amazing how another person questioning your logic can so easily cast doubt over confidence. I'll have to go back to the drawing board.

Ron
 
Last edited:
It's the next to last line that is problematic. Look at where the units are:

552960 pulses
-----------------
1 revolution

and

1296000 seconds
--------------------
1 revolution

Your goal is pulses per second:

pulses
----------
1 second

But what you are actually producing is

Seconds pulses
---------- / ----------
revolution revolution

which equals

Seconds revolution
---------- * ---------------
revolution pulses

Cancel out the units in common, and what you are left with is

Seconds
----------
pulse

Which is the inverse of what you saying. You are calling that next to last line "Pulses per Degree (Second)", but actually you have calculated Seconds per Pulse. Your math is correct, and as I noted, your code is correct as well; it is your units in this description that are upside down.

To put it another way, the resolution of your control is 2.34375 seconds - that is the minimum movement you can achieve with each pulse.
 
awake,

/*
Rotary Table

Resolution: Degree(Seconds) * 360 = 1296000 per table (revolution)
Gear Ratio: 90:1 (4º per Input Rotation)
4º(Seconds) = 14400

Servo MOtor/Drive
Motor Pulses per Revolution: 2048
Gear Reduction: 3:1
1 Revolution @ Final Drive: 6144 motor pulses

6144 motor pulses rotated the table 14400 seconds.
1 motor pulse would rotate the table: 2.34375 seconds (14400 / 6144)
*/

Based on that I don't see an error in my logic.
( (15º * 3600) / 2.34375) = 23040 pulses

Ron
 
I think it's just your descriptions that are problematic but you're using the resulting figures correctly in your code. From your logic section in post #1:
Pulses per Degree(Second): 14400 / 6144 = 2.34375
Table Resolution: 1 Second: (2.34375 Pulses )


Here you are calling it 2.34375 pulses per second whereas it's actually 2.34375 seconds per pulse (your description indicates pulses/seconds but your math is seconds/pulses). Similarly, your table resolution should be 2.34375 seconds (table movement for 1 motor pulse).
 
Yes, what Cogsy said. As I said above, your code is correct.

I'm sorry for making this a big deal ... It's just that I have written a lot of software, and this is the sort of thing that can bite you later, and take forever to debug. Better to get it all straight now, both in the code AND in your comments or descriptions.
 
...
Based on that I don't see an error in my logic.
( (15º * 3600) / 2.34375) = 23040 pulses

Ron[/QUOTE]
Hi Ron,
am interested in what U are designing re this divider.. Any chance of an overview, micro type, Display type, objectives etc?
Sorry but cant seem to find the beginning of the story!
cheers,
 
Yes, what Cogsy said. As I said above, your code is correct.

I'm sorry for making this a big deal ... It's just that I have written a lot of software, and this is the sort of thing that can bite you later, and take forever to debug. Better to get it all straight now, both in the code AND in your comments or descriptions.

You have no reason to apologize. Discussion is enlightening.

Ron
 
Last edited:
Ron
Hi Ron,
am interested in what U are designing re this divider.. Any chance of an overview, micro type, Display type, objectives etc?
Sorry but cant seem to find the beginning of the story!
cheers,

The man that sponsor all of the information in this thread delivered a very thorough review of how he built his indexer. It's hard for me to wrap my head around another mans logic so I have to start from ground zero and develop my own logic and engineering. I have the rotary table, the servo motor and the drive amplifier along with the key components shown in this thread. When I grow tired of looking at the motor sitting on the rotary table then when able I'll make some chips and mount the motor. At this time I'm enjoying a gout attack so I'm doing the paper work. I would suggest that chose the type of motor for the project and then make yourself knowledgeable of the motor and drive. There's no shortage of help for those that make an effort but there's very little help for those that want a finished solution. Dive in.
 
Last edited:
awake, Cogsy,

I want to thank both of you for your input and insight. When a person 'knows' that they are right then it's difficult to show them that they are wrong. My logic was on both sides of the argument (discussion). First it was 2.34375 pulses and mid way through the discussion I unwittingly flipped to 2.34375 seconds. I started to concede the argument last night but once again I wavered. Below is my last conclusion and if it's not right then the world is going to have to change.

In the interest of resolution I switched from a 3:1 gearhead to a 5:1 gearhead. I don't need to rotate 360º in 9 seconds.

/*
Given:
Degree * Minutes * Seconds = 3600 Seconds
Rotary Table gear ratio: 90:1
Motor ppr: 2048
Motor Gearhead ratio: 5:1

Logic:
One revolution @ 5:1 Gearhead final drive = 10240 Motor ppr (2048 * 5)
One revolution of Rotary Table hand crank = 4º * 3600 = 14400 Seconds
Therefore, 1 Motor ppr rotates the Rotary Table 1.40625 Seconds (Indexer Resolution)
Formula: ((Degrees * Seconds) / Indexer Resolution) = pulses
Seconds) / Indexer Resolution will be a constant
*/
 
Last edited:
Your math is fine but your pseudo-code formulas are a little confusing to me (but that might just be your own personal short-hand). In your first formula, Degree * Minutes * Seconds = 3600 Seconds, I think this should be : (Degrees * 3600) + (Minutes * 60) + (Seconds) = Total Seconds (this is really being pedantic as I can see what you were trying to do).

For your final formula, I don't really get what you're aiming at (that equals sign inside the brackets confuses me). You seem to be saying that your ratio "Total seconds/resolution" equals your motor speed * time "Pulses per second * seconds" (which would be true) which is all then divided by your resolution to achieve a constant (which I don't believe to be true). The first half of the equation can be simplified to "required pulses = pulse speed * time" which is always going to be true but is going to vary depending on how far you want to move the indexer so this value over the indexer resolution will vary. I'm sure you were aiming for something different here but I've missed the point.
 
Your math is fine but your pseudo-code formulas are a little confusing to me (but that might just be your own personal short-hand). In your first formula, Degree * Minutes * Seconds = 3600 Seconds, I think this should be : (Degrees * 3600) + (Minutes * 60) + (Seconds) = Total Seconds (this is really being pedantic as I can see what you were trying to do).

For your final formula, I don't really get what you're aiming at (that equals sign inside the brackets confuses me). You seem to be saying that your ratio "Total seconds/resolution" equals your motor speed * time "Pulses per second * seconds" (which would be true) which is all then divided by your resolution to achieve a constant (which I don't believe to be true). The first half of the equation can be simplified to "required pulses = pulse speed * time" which is always going to be true but is going to vary depending on how far you want to move the indexer so this value over the indexer resolution will vary. I'm sure you were aiming for something different here but I've missed the point.
Hi,
am interested in this divider..
where do i find an overview, micro type, Display type, objectives etc?
Sorry but cant seem to find the beginning of the story!
cheers,
 
Hi,
am interested in this divider..
where do i find an overview, micro type, Display type, objectives etc?
Sorry but cant seem to find the beginning of the story!
cheers,
I think this project is just starting so this thread is the beginning...
 
The man that sponsor all of the information in this thread delivered a very thorough review of how he built his indexer. It's hard for me to wrap my head around another mans logic so I have to start from ground zero and develop my own logic and engineering. I have the rotary table, the servo motor and the drive amplifier along with the key components shown in this thread. When I grow tired of looking at the motor sitting on the rotary table then when able I'll make some chips and mount the motor. At this time I'm enjoying a gout attack so I'm doing the paper work. I would suggest that chose the type of motor for the project and then make yourself knowledgeable of the motor and drive. There's no shortage of help for those that make an effort but there's very little help for those that want a finished solution. Dive in.
At mercy of others, cant write code. Could learn, but would ages, & take away from remaining health. (Oedema)
 
The man that sponsor all of the information in this thread delivered a very thorough review of how he built his indexer. It's hard for me to wrap my head around another mans logic...in.
Hi Ron
Which thread are you referring to? There are quite a few different indexer/dividing threads.

I have a version of the one described in”Rotary Table for Dummies” thread hooked up to a spin index. I’ve thought about mounting it to my rotary table as well. As designed it does not provide power feed. Does the one you’re working on do that?

The only comment I have on the code is; why on earth are you working in seconds? It’s bad enough that there are 360 degrees to a circle without making it any worse. LOL

John
 

Latest posts

Back
Top