DC motor harmonic motion

Hello, I would like my dc motor to have a harmonic motion with specified amplitude and frequency (by harmonic motion I mean that the angular position of the motor is a sine function of the time). So I'm stuck at that point : I know how to implement a simple PID control loop to control the speed of the motor, but I don't know how to tell to the motor that I want the speed to be a sine function of the time. Any ideas ? I know several very expensive controllers that allow that kind of motion but I don't know exactly how they work. Also another problem that arises is that the serial communication of the arduino is limited in speed (for instance when I read an optical encoder, the position can be seen every 5ms), so it should be a problem for harmonic motion with let's say a 5Hz frequency, no ?

The PID algorithm requires a setpoint, which is up to you. So, you can have that setpoint vary as a function of time (as in a sine wave).

Okay, I agree with that, but practically how do you implement that using arduino ? At which frequency do you actualize the setpoint ? It should let the speed go to the specified setpoint but if you wait too long it will affect the sine curve

The rate at which you can change the setpoint depends very strongly on your implementation of the PID algorithm (that is, how frequently the PID loop runs), the response time of the motor/controller/encoder and, as you point out, the speed of communications between the Arduino and the encoder/controller. You can do some calculations to estimate that rate of change, or you can experiment. There is not enough information in your post for readers to judge.

This is normally by cascading several regulators

position regulator->rpm regulator->torque regulator

Not a simple problem and that is the reason why the exsisting solutions are costly.
It can probably be done with an arduino to an extent, especially regarding max angular velocity. But you should expect to invest a large amount of time

I'm aware of that XD I've been on the topic for a couple of weeks and still haven't found the solution... I've got one with a stepper motor but not smooth enough for what I want to do.

Nevertheless I stumbled into this scilab toolbox which communicates with the Arduino Uno (https://atoms.scilab.org/toolboxes/arduino) and that might do the trick. But I've had a lot of problems making my encoder working (most codes weirdly can't get anything of it) and I still got the same problem with this toolbox. If anyone could try it with his own encoder and see if it works it would be great.

Have you considered a mechanical solution? A disk rotating at constant angular velocity, with a link to an offset pin, generates harmonic motion.

void loop ()
{
  if (millis () - timestamp > TIMESTEP)
  {
    timestamp += TIMESTEP ;
    setpoint = SCALEFACTOR * sin (OMEGA * millis()) ;
  }
  pid_loop () ;
}

MarkT:

void loop ()

{
  if (millis () - timestamp > TIMESTEP)
  {
    timestamp += TIMESTEP ;
    setpoint = SCALEFACTOR * sin (OMEGA * millis()) ;
  }
  pid_loop () ;
}

Well as expected it doesn't work, the motor starts and stay at the first speed setpoint.

Well its a snippet - perhaps post the code you actually used in its entirety?

What if you your solution with a stepper motor and replaced the stepper and the driver with a servo that accepts step and direction pulses?

Is there a purpose to the solution or is it just a challenge?

Hi nilton61 I've assigned to very similar to this above-mentioned project and still on a research mode.
" a motor to have a harmonic motion with specified amplitude and frequency by harmonic motion I mean that the angular position of the motor is a sine function of the time"

Just looking out what type of option that I can select to succeed in my project?
At this stage, I don't have limited to any budget or if use Arduino or Dc motor?
More than happy to check what's your opinion on this type of project with the updated knowledge.
also, can you kindly explain to me the what do you mean "cascading several regulators"

thanks in advance!!
cheers

Are you sure this is what you mean? I wonder if it's even what the OP meant, 5 years ago:

by harmonic motion I mean that the angular position of the motor is a sine function of the time

Normally it's the y distance that's a sine function of time:

y = a sin (wt + phi)

.... and that's what #6 was getting at.

(w (the angular velocity in rad/s) is the constant speed of the motor.)

You're saying you want the angle itself as a sine function of time?

meltDown there is absolutely no ambiguity in the specification: " a motor to have a harmonic motion with specified amplitude and frequency by harmonic motion I mean that the angular position of the motor is a sine function of the time"

Angular position means angle, just as angular velocity is rotations or radians per second

MarkT:
meltDown there is absolutely no ambiguity...

Angular position means angle, just as angular velocity is rotations or radians per second

I didn't say it was ambiguous, and you're right it's not; I was just asking k7 to confirm that was actually what he meant.

"I'm want to go to the zoo" is unambiguous; but if I mean to go to the planetarium, it's wrong in spite of being unambiguous.

so what I'm trying to do is making rheometer which measures the rheological properties of a material. Basically, there are two measuring methods available: Rotational tests and oscillatory tests. With rotational measurements, the measuring bob turns in one direction. In an oscillatory test, the measuring bob “oscillates” around the axis.

Image: rheometer hosted at ImgBB — ImgBB

what my focus is to with oscillatory tests with set sinusoidal oscillation.
The basic principle of an oscillatory rheometer is to induce a sinusoidal shear deformation in the sample and measure the resultant stress response; the time scale probed is determined by the frequency of oscillation, ω, of the shear deformation. In a typical experiment, the sample is placed between two plates, as shown in the image2 below While the top plate remains stationary, a motor rotates the bottom plate, thereby imposing a time-dependent strain γ(t)=γ ·sin(ωt) on the sample. Simultaneously, the time-dependent stress σ (t) is quantified by measuring the torque that the sample imposes on the top plate.

image2: rheo-2 hosted at ImgBB — ImgBB

So to able to do above testing I need to run the motor with sinusoidal oscillation with exact angle.Hope you get it what im trying to say? does anyone know any motor controllers that allow that kind of motion ? or any hints how do i wet my feet? cheers!!