How to output waveform to servo

Hi,

I am using a servo to control a plate that will move in a reciprocating motion. I am using a crank to convert the circular motion of the servo into the reciprocating motion.

I want the output to follow a waveform (close to sinusoidal), I have attached an image of the waveform.

I am unsure how to use that to output it to the servo?

Any suggestions would be appreciated.

Thank you!

Waveform.PNG

A servo will not go 360 degrees unless it is crippled, that is unless you screw up all positional capability of it.

When it is just set it going round and you should get the motion you want.

Ah yes, I should be more clear! I have it rotating 180 degrees. The 180degrees rotation distance is more than the max peak to peak amplitude of the waveform. So, with the 180 degrees, I would be able to move the plate to each point.

Does that make sense?

I would be able to move the plate to each point.

No because the servo has to stop to change direction and that will screw the waveform with a pause at direction reversal.

But why not just have a normal motor and just let physics do its thing?

Assuming your mechanism can do what you want with 180 degree rotation...

Is your program working to the point where you can position the motor where you want it? If so, it's just a matter of synchronizing the position with time...

The Arduino can calculate sine and cosine, but it's common to use a table. All you need is a 0-90 degree table and you can reverse & invert to get the remaining 270 degrees.

I guess the trick is to realize you're in the digital domain and everything (time and position) is quantized. That means you'll be moving the servo in steps. They can be very-small steps, but you have to program discrete positions at a specific time.

Grumpy_Mike:
No because the servo has to stop to change direction and that will screw the waveform with a pause at direction reversal.

But why not just have a normal motor and just let physics do its thing?

yes, the changing of direction will have to occur at the peaks. Are you saying that a servo cannot change direction fast enough to give a reasonable approximation of a waveform?
The reason I am using a servo is that it is a closed loop system so I am sure It is following the waveform I want it to.

DVDdoug:
Assuming your mechanism can do what you want with 180 degree rotation...

Is your program working to the point where you can position the motor where you want it? If so, it's just a matter of synchronizing the position with time...

The Arduino can calculate sine and cosine, but it's common to use a table. All you need is a 0-90 degree table and you can reverse & invert to get the remaining 270 degrees.

I guess the trick is to realize you're in the digital domain and everything (time and position) is quantized. That means you'll be moving the servo in steps. They can be very-small steps, but you have to program discrete positions at a specific time.

I have the servo set up so that I can control the distance yes, as I know the microseconds per degree of turning and can calculate the linear distance moved with trigonometry.

Okay, so I can use a table, the best way to this is to have it as an array in the code with the data points from the table?

Thanks again guys!

John-Smith:
The reason I am using a servo is that it is a closed loop system so I am sure It is following the waveform I want it to.

Closed loop systems can apply to discrete time and analog systems... or a combination of them.

You probably need to consider things like timing... and what speeds do these parts need to move at .... etc. And how precise the movement needs to be. Things like that.

Agree with SouthPark...
It sounds like OP may eventually paint themselves into a corner.
Design the hardware mechanism that does everything you need now PLUS 20%
Then code for that.
Not the other way around.

The problem with this idea is that a servo does not move at a constant rate. The whole point of a servo is that it starts off fast and as it approaches the required point it slows down. Therefore it will not do what you want, unless you want to move the plate very much slower than the servo can respond. It that is the case then just move the servo at a constant rate of degrees per unit time. No need to calculate anything else.

Hi,
If you go back to the geometry of how a sinewave is generated.
If you keep a DC motor at constant speed you will find a point on the circumference will scribe out a sinewave.

If you need to know position you will need to put an encoder on the disk shaft.

Tom... :slight_smile: