Motion profile generator.


Closed Thread
Results 1 to 40 of 56

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Thanks Darrel!

    Actually, I don't think you should need to worry about the direction. Perhaps I misunderstood your earlier question and overcomplicated my explaination after all.

    How about this:
    * The "global position variable" is the expected motor position at any given time. The PID loop servos the motor to this position.
    * The "relative position variable" is the output of the profile generator, exactly as you shown earlier, always starting a new move at 0.
    * When a new move is commanded it is easy to calculate if the target position is positive or negative relative to the current "global position".
    * A profile, starting at 0 and ending at ABS(Target Position - Global Position) is then generated.
    * Depending on the direction or "polarity" the output of the profile generator is added or subtracted from the Global Position variable one "tick" at a time.
    * The PID loop makes the motor follow the Global Position variable very smoothly and everyone's happy, especially me :-)

    Does that make sense?

    /Henrik.

    EDIT: Put another way... Acceleration is added to Velocity. Velocity is added to RelativePosition. RelativePosition is added to OR subtracted from GlobalPosition.
    Last edited by HenrikOlsson; - 28th January 2013 at 19:08.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    H,
    Ditto on you always helping everyone. If this isn't too elementary relating to where your at.......

    on de-celleration when V_Max reaches to 0...zero, recalculate the ACC (will be de-celerate) val.
    if you want the same amount of iterations to de-cel as used to acelerate, at A=10 then 100/10 for 10 loops or A=15 for 100/15 for 6? or 7? loops..............
    then subtract present pos (@ V_MAX=0) from desired pos. Thats the actual steps to stopping ??
    now use sum of # loops...( sum=loops(loops+1)/2) is new ACC val to loop to 0 (zero) over that many loops (should be +- 1 or 2 from the starting ACC val)
    now there will be either 0 or some amount less than A as a final step to stop.
    should be a few more lines of code to test and calc.
    I think Darrel mentioned re-calc something.
    don
    Last edited by amgen; - 28th January 2013 at 22:06.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Maaaannnnn ... This is harder than it looks.

    Well, I have it going to the exact target position with zero error ... as long as it's able to reach the maximum velocity (the flat part of the profile).

    But if the target position isn't far enough away, and it doesn't reach V_Max before it has to decelerate ... it overshoots the center, and with the maximum deceleration (A_Max) ... the velocity can't reach 0 until it's past the target. Arrrrrggg.

    So on the shorter distances, I'll have to stop accelerating before it gets half way there, and calculate a new slope for the second half so that it stays under the maximum deceleration and gets the velocity to 0 before or at the target position. This way will make it decelerate slightly slower than it accelerates. Probably not noticable though.

    Need more time.
    DT

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Darrel,
    What, you need more time? Unacceptable, I need a working solution NOW ;-)
    Seriously, take all the time you need, I appreciate any and all help!

    I know, I found it quite a bit harder....

    Since I don't know how you're actually aproaching this I'm just thinking out loud:
    On the short moves I'm thinking how it would work out if the distance was simply cut in half and then the actual acceleration value tweaked to fit so we'd hit right on the centermark while accelerating. Then start decelerating at the same slope would make us end up at the target, right? I wonder what the worst case deviation from the set acceleration value would be... Code size and speed is obviosuly of interest as well...

    I'm looking forward to see what you come up with!

    Don,
    Perhaps Darrels aproach is exactly what you're trying to explain but I must I admit I don't quite follow what you're trying to explain.
    If an error at the end of the move of alwas less than A_Max is the best we can get then so be it but it sounds like Darrel is really onto something.

    Thank you both!
    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Henrik,
    While the professional is working up the best scheme.

    Question..... on the last itteration to stopping, can you subtract 'position now' from 'position desired' ?
    and if so, can you move exact steps of the difference with the A value?

    Don

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Hi Don,
    If it always ends up short of the actual target AND the remaining distance TO the actual target is always less than A_Max then I could probably live with that. It means that it would always reach the actual target within a single "tick" from optimal.
    However, I'd have to move it a speed equal to the actual distance to target, if moved at A_Max then it would overshoot in one tick - which in turn gives it a little bit of "S" at the end reducing the jerk. Might actually be good.

    Thanks!
    /Henrik.

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Surely I will say something obvious, but since I did not noticed it in the above post, let me say it.

    When the travel distance is less than twice the accelleration the trapezoidal profile become triangular and V max decrease, so that Vmax = tan(accelleration Slope) time the travel distance / 2

    Cheers

    Al.
    All progress began with an idea

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    Here's what I'm up against ...

    You can only adjust the acceleration.
    I don't see any way to know what acceleration is required to make the half-way point end up exactly at an interrupt period.
    It always ends up somewhere in the middle of a period.

    If I new what the velocity would be at the halfway point, I could adjust the acceleration so it reaches the half-way point at exactly an interrupt period.
    Except that since the acceleration changed, it won't be at that velocity at the half-way point anymore.
    So I don't see any way of predicting the half-way point in order to use the same deceleration slope it uses for acceleration (the yellow line).

    I can only change the acceleration at specific times, which coincide with the interrupt periods.
    So if I recalculate the deceleration slope at period 6 before it reaches the half-way point, it creates the green line, which should end up at the target perfectly.

    If I were to recalculate it after passing the half-way point, the deceleration rate would be higher, and violate the A_Max constraint.

    The blue line is the overshooting profile, with it's velocity using the left axis.
    The red line is the position, using the right axis.
    The parameters for that run were ... A_Max=10, V_Max=100, Target=475.



    I'm doing the green line.
    But since the green line is actually a slower velocity, it will take longer than shown in the chart to reach the target.
    But at least it is calculatable.
    DT

  9. #9
    Join Date
    Apr 2011
    Location
    Kent, UK
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    It is all relative to time. One thing not concidered yet is what to do if the servo has not achieved the demand. Do you run the servo faster/slower (velocity), harder/softer rate of change (acceleration & deceleration), longer/shorter (time) or forwards/back (position) to achieve the end target?

    I assume you are attempting to modulate the velocity to achieve an end target at xx time whilst keeping the rate of change and max velocity within the set limits.

    If you concider a velocity/time graph (trapezoid shape), with velocity as the height of the perpendicular at the current time, then the distance to travel is the area under the graph from the current position. (see graph in post #1)
    The math to extract the velocity demand (in QC's / time period), at any given time, according to end target, defined limitations and servo error, is what you are trying to calculate.

    Am I helping?

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    this works on the real servo motor. what a difference the qei module makes ,and 14 bit pwm seems much smoother
    pid rate now 1ms ramp rate 8ms with 49 steps , no attempt yet to handle short moves but long ones are good . fwd and backwards moves are good .
    pos counter 24bit / vmax and accel are fixed constants so far
    Attached Files Attached Files

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    the idea was easier to implement than I expected. when the setpoint to target distance is less than the ramp_length + the constant velocity increment , rather than any fancy math I just set the setpoint to the target-ramp_length value. I just let the pid work the mechanics out for its self. after that its just a matter or playing the array back backwards to arrive dead on target .
    I have included a poorly annotated sketch of my c routine,
    the motor I want to use can only achieve 300 counts/sec (accel 2000 counts /s/s) and needs to not have a count for at least 30mS to guarantee 0 vel , therefore the pid loop is run @40mS intervals and the profile input is applied on every second pid loop. this works pretty well (motor inertia gives smooth motion) and it stops on target _+ 1 count (pid might need better tuning).
    seems to me that motor/load characteristics really change the entire nature of the problem.
    I'm yet to try this on a real servo motor my pid loops are taking 50-300 uS to run so hopefully a 1mS pid rate is possible , I think I will get some pic18f2431's and have a play with thev qei module
    Attached Images Attached Images  

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Motion profile generator.

    I forgot to add that in my application the accel and max v will never change only the direction and distance therefore the ramp array will never need recalculating , for "short" moves i just reduce the number of elements played out. the pid tolerance seems pretty accommodating.
    I want no overshoot no stalling and no hunting +- 4 counts is accurate enough . its controlling the really stiff and jerky air slide on the pid controlled wood heater in the lounge (its a matter of principle)

Similar Threads

  1. Motion Capturing
    By koossa in forum Off Topic
    Replies: 0
    Last Post: - 30th June 2009, 12:05
  2. Suggest a motion sensor Please
    By sougata in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 4th March 2007, 14:22
  3. Wireless Motion Sensors.
    By koossa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th October 2006, 22:57
  4. Need low Profile LCDs
    By Foxx373 in forum General
    Replies: 8
    Last Post: - 26th October 2005, 18:33
  5. Motion Tracking
    By JEC in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th November 2004, 01:58

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts