Analog linear motor

This is a discussion on Analog linear motor within the C Programming forums, part of the General Programming Boards category; Hello all, I'm new to C programming. And I have to control an analog linear motor. That ain't the problem ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    4

    Analog linear motor

    Hello all,

    I'm new to C programming.
    And I have to control an analog linear motor.
    That ain't the problem but.

    Problem description:
    The motor is moving an axis.
    So the distance he can travel is limited.
    The speed of the motor has to accelerate in the beginning and slow down at the end before stopping.
    He has to do this with the priniciple of a sine wave.

    The user is able to change the cycle time.

    Now my big problem is. When you use a sine wave and you can change cycle time the surface under the sine wave has to be same anytime (because the distance keeps the same).
    Probably you have to do this by using integration but I don't know how to do this in C.

    Thank you very much for even answering.

    If you don't have enough information, please ask.


    Thanks in advance,
    Koen

    English ain't my native language, so sorry for any grammatical errors

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Are you in the same class?
    How to write programs for PWM in C ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    Quote Originally Posted by Salem View Post
    Are you in the same class?
    How to write programs for PWM in C ?
    No, I don't know this person. But if you want the same information as you asked on his question.

    actuator: LINAK

    programming chip: PICF2580 from microchip.com (http://www.microchip.com/wwwproducts...cName=en020613)
    Last edited by Koen; 10-30-2012 at 09:53 AM. Reason: now with link

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    890
    Do you mean you have an analog linear positioning drive of some sort, and you want to control its position as a function of time as
    Code:
    x(t) = x0 + L sin (2 π  t / t0)
    where x0 is the center point, L is half the total travel, and t0 is the duration of each full cycle of movement?

    Or do you mean you want to find out how to calculate the required velocity to move the drive to a new position using a sine acceleration curve? In other words, for each stroke from x0 to x1 in time t = 0 .. t1:
    Code:
    x(t) = x0 + (x1 - x0) (1 - cos( π t / t1 ) ) / 2
    which has a velocity curve
    Code:
    v(t) = π (x1 - x0) / t1) sin( π t / t1 )
    (a single "hump" of a sine wave, a half wave from zero to max velocity back to zero).

    Since you have an analog linear positioning drive, the latter also gives you the PWM duty cycle you need to drive the analog motor:
    Code:
    duty(t) = dutymax / vmax |v(t)|
    and the sign of v(t) tells you the direction.
    _____________________________________

    In real life you cannot control the duty cycle continously, so you need to discretize the algorithm (which replaces a short interval of the curve with a fixed value of the same duration, that has the same effect). Instead of v(t) or duty(t), you need dutyi for i = 0 .. N-1 steps, N = round(t1·rate).

    The simplest option is to first do the calculations like I showed above to make sure the curve yields the desired velocity or acceleration profile, then set the duty cycle for each sampling period to the value that yields the desired movement. Assuming for a smooth movement from point x0 to x1 in N steps (t1 time duration), with initial and final velocities zero, you get
    Code:
    ti = i / N t1
    Δxi = x(ti+1) - x(ti) = (x1 - x0) ( cos(π i / N + π / N) - cos(π i / N) ) / 2
    dutyi = dutymax / vmax Δxi
    i.e.
    Code:
    dutyi = dutymax / vmax (x1 - x0) ( cos(π i / N + π / N) - cos(π i / N) ) / 2,  i = 0 .. N-1
    To compute the sine and cosine, use the CORDIC algorithm. If computation speed becomes an issue, you can try replacing cos(π i / N + π / N) - cos(π i / N) with the mathematically equivalent, but simpler
    Code:
    const1 cos(π i / N) - const2 sin(π i / N)
    where
    Code:
    const1 = cos(π / N) - 1
    const2 = sin(π / N)
    Last edited by Nominal Animal; 10-30-2012 at 10:20 AM.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    Thank you very much.

    I want to regulate the speed of the motor so it moves a bit like this (quick motion study, so no reference to it). motor assembly.avi - Speedy Share - upload your files here


    When we regulate the speed we have an output from 0-5v but we use a linear amplifier that will translate it into: 0V = -10V, 2.5V = 0V and 5V = 10V
    So its not necessary to use a hump.
    The acuator gives feedback at what position he is.

    By the way, thank you for giving me a solution for a problem were I didn't even asked for.

  6. #6
    Registered User
    Join Date
    Oct 2011
    Posts
    890
    Quote Originally Posted by Koen View Post
    I want to regulate the speed of the motor so it moves a bit like this (quick motion study, so no reference to it).
    Look into
    Code:
    x(t) = x0 + ( x1 - x0 ) ( 3 t2 - 2 t3 ),  t = 0 .. 1
    The overall feel of the movement is very similar, but the velocity and acceleration curves are
    Code:
    v(t) = d x(t) / d t = 6 ( x1 - x0) ( t - t2 )
    a(t) = d2 x(t) / d t2 = 6 ( x1 - x0 ) ( 1 - 2 t )
    which means that given just current position and desired position, and maximum velocity and maximum acceleration, you can determine the minimum time you need to do it, and how to do it.

    Using the same approach as in my previous post, (but this time t = 0 .. 1),
    Code:
    ti = i / N
    Δxi = x(ti+1) - x(ti) = (x1 - x0) / N3 ( -6 i2 + 6 (N - 1) i + 3 (N - 1) + 1 )
    where Δxi tells you how far the actuator must move in each time step i, and therefore the duty cycle needed to achieve that -- and in N timesteps, the desired movement using the above velocity and acceleration profile. (You almost always use a fixed-size steps, duration being fixed to some integer multiple of the PWM period you use.)

    Because this time you only need one division, and few multiplications, this is very lightweight to compute on a microcontroller. Just note that you need to work with integers up to N3 and (x1-x0)N2, whichever is larger, in magnitude.

    Finally, it is possible to incorporate the position feedback on a linear actuator, really turning it into a digitally controlled servo. It gets a bit more complicated, but basically you always use the current position as x0, with x1 being the desired position. Current velocity you know (since it is essentially the PWM duty cycle). In each time step, you simply pick a new velocity towards the target, just one that is within the allowed velocity and acceleration limits. (If you have time steps, acceleration is (new velocity - old velocity) / duration. If you specify acceleration limits by values multiplied by duration, you simply have the maximum speed change allowed per time step. Very simple!) You really only worry about being able to stop at the desired coordinates in time, without exceeding speed or acceleration limits. I think the OpenServo servos do something very similar to this.

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    Thank you very much.
    In the next couple of weeks I'll implant this in my program. (don't have that much time now)
    So when I've done it you will certainly hear something about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. .net analog of std::set?
    By m37h0d in forum C# Programming
    Replies: 3
    Last Post: 06-28-2010, 07:18 AM
  2. cd analog
    By prospb in forum C Programming
    Replies: 2
    Last Post: 04-25-2010, 07:27 AM
  3. Stellaris® Stepper Motor RDK
    By brconner in forum C++ Programming
    Replies: 1
    Last Post: 06-12-2007, 01:18 PM
  4. Analog IO
    By Downbound in forum C++ Programming
    Replies: 5
    Last Post: 04-29-2004, 03:12 AM
  5. Stepper Motor Control .......
    By svglolla in forum C Programming
    Replies: 1
    Last Post: 02-18-2002, 11:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21