Go Down

### Topic: DC motor harmonic motion (Read 1 time)previous topic - next topic

#### Herr_Spaetzle

##### Sep 02, 2014, 05:13 pm
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 ?

#### jremington

#1
##### Sep 02, 2014, 05:21 pm
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).

#### Herr_Spaetzle

#2
##### Sep 02, 2014, 05:58 pm
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

#### jremington

#3
##### Sep 02, 2014, 06:04 pm
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.

#### nilton61

#4
##### Sep 03, 2014, 05:49 am
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

#### Herr_Spaetzle

#5
##### Sep 03, 2014, 06:01 pm
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.

#### jremington

#6
##### Sep 03, 2014, 07:28 pm
Have you considered a mechanical solution? A disk rotating at constant angular velocity, with a link to an offset pin, generates harmonic motion.

#### MarkT

#7
##### Sep 03, 2014, 07:55 pm
Code: [Select]
`void loop (){  if (millis () - timestamp > TIMESTEP)  {    timestamp += TIMESTEP ;    setpoint = SCALEFACTOR * sin (OMEGA * millis()) ;  }  pid_loop () ;}`
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### Herr_Spaetzle

#8
##### Sep 05, 2014, 10:03 am

Code: [Select]
`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.

#### MarkT

#9
##### Sep 05, 2014, 11:50 am
Well its a snippet - perhaps post the code you actually used in its entirety?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### nilton61

#10
##### Sep 05, 2014, 08:45 pm
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?

#### kevin0007

#11
##### Aug 14, 2019, 02:09 am
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"

cheers

#### meltDown

#12
##### Aug 14, 2019, 06:49 amLast Edit: Aug 14, 2019, 06:50 am by meltDown
Are you sure this is what you mean? I wonder if it's even what the OP meant, 5 years ago:

Quote
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:

Code: [Select]
`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?

#### MarkT

#13
##### Aug 14, 2019, 12:56 pm
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
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### meltDown

#14
##### Aug 14, 2019, 01:24 pm
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.

Go Up