Driving Servo Sinusoidally

I'm hoping to be able to drive a motor sinusoidally, or more generally, I hope to be able to put some input mathematical function (sine, sawtooth wave, square wave) and have a motor reproduce that motion. I'm wondering if this is possible with a servo motor and Arduino. I need this to be quite accurate and was just curious if Arduino had the capabilities to produce these motions accurately with a servo motor.

Sorry if this has previously been asked I couldn't find a suitable answer searching.

Thanks in advance!

R/C servos can only rotate - can you explain what you mean by "sinusoidally"?

hmm....

Well, I want the rotation to be sinusoidal. Similar to the sweep example given with the Arduino but I want to accurately define the position/velocity of the rotation by varying the signal sent to the servo.

Basically I want to make a rigid panel rotate back and forth (think of a fish fin swimming, it oscillates back and forth to propel the fish forward), and want the servo to provide this motion. I want the motion of this oscillation to be accurately defined by mathematical functions to mimic things like sine, sawtooth, and square waves.

That help?

FWIW
If the servo was providing the up and down motion of the "fin" - say the Y axis, wouldn't the wave shape depend on speed that the "fish" was moving? (say the X axis).
I'd guess it's quite possible to control a servo to generate the Y axis for an expected, or measured X axis.

Yes, I'm effectively trying to dictate the y-axis in your example BroHogan, I'm just not sure how accurate Arduino would be in being able to do this with a servo motor. Thanks!

From what I know about servos, they have varying increments that they are rated for, the more increments the more accurate the servo. The arduino should be able to provide very accurate signals with the right hardware/ software but the accuracy will only be as good as your servo. Out of curiosity, what exactly is this for? You mentioned fish, are you making a robot fish or was that just an example?

In principle any linear servo could be used to generate any waveform one desired for a X vs time chart type application. Limits to resolution and speed would have to be researched if they would meet the applications requirements.

Lefty

Here's a small function I use to generate a sine wave with a digital to analog converter (DAC).

uint16_t sin_wave[128];

void setup()
{
  for (int16_t i = 0; i < 128; i++)
  {
    float angle = TWO_PI * i / 128;
    int16_t val = sin(angle) * (2048 - 1);
    val += 2048;
    sin_wave[i] = val;
  }
}

128 is the number of steps (the granularity of your sine wave). 2048 is the waveform zero point offset.

The next step is to pass these values in a sweep from 0 to 127 to the output with an appropriate delay between each step. You could use a similar technique for just about any waveform. Either pre compute the steps or just compute and feed the values directly to your output as you go.