Shop OBEX P1 Docs P2 Docs Learn Events
Trouble with acceleration formula — Parallax Forums

Trouble with acceleration formula

lardomlardom Posts: 1,659
edited 2012-01-18 09:40 in Propeller 1
Speed = distance / time. When I express that formula in a waitcnt statement my two steppers spinning at different speeds will stop at the same time. The problem is I cannot figure out a way to ramp two steppers and get them to stop at the same time. One motor always runs a bit longer. Part of the problem is integer math. Is there a solution without resorting to a float math object?

Comments

  • ErNaErNa Posts: 1,752
    edited 2012-01-12 00:02
    Hallo Larry,
    to give an answer the question must be more precise:
    Do you want the steppers to stop at the same time or do you want to stop them in a given place?
    As you said: you have to ramp the steppers. That is: you are somehow running a speed/acceleration controlled mode, not just stepping.
    If you just want to stop both motors at the same time, the question is: can you determine the ramp (linear?), in this case you can start ramping down at different rate according to actual speed. If you have a fixed ramp, you ramp down the fastest first, start ramp down the second when the first reached the speed of the second.

    But you should describe the task more in detail (don't look for a solution this moment) First be aware what to do. Are you following a line, are you reaching a coordinate, are you just stopping two motors.
    ErNa
  • JavalinJavalin Posts: 892
    edited 2012-01-12 03:46
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-12 05:17
    .... you should also have a look at the bresnham algorithm for drawing lines. The basic idea is that you simply split up the number in an integer-part and a fractional part. You sum up both and if the fractional part has a overflow you correct the integer part. This way you stay with simple integer math.

    It's just another way of doing the fixed-point math.
  • lardomlardom Posts: 1,659
    edited 2012-01-12 06:58
    erna, both motors must start and stop together. I'm designing a robot that uses differential steering. For the testing stage I program a 90 degree arc at a given radius. I subtract 13 inches from the radius to account for the inner wheel and it works correctly if there is no ramping. I want to eliminate the jerkiness in starting and stopping.
    MagIO2, the bresenham algorithm sounds promising. I'll study it. The other thing I want try is making 0.5 a constant and seeing if there is a way to use it in run-time calculations.
    I wanted to try to implement a formula for linear or constant acceleration but the integer problem was still there.
  • T ChapT Chap Posts: 4,223
    edited 2012-01-12 07:54
    I would find a way to get away from decimals all together, and get to a system of 1 step = 1(Prop integer value) because you cannot have less than 1 step pulse(regardless of using microstepping driver)

    Can you describe more in detail how this needs to work? Do you have 2 steppers with separate code to drive each ( step and dir ), and both steppers need to accelerate and decelerate in a manner that allows both to complete the motion at the same exact time after a move, yet both steppers may have moved a different number of steps since steering would require it. If that is the case, then are the moves being controlled in real time and not predetermined? Like a joystick for example, where you begin a move, both steppers accel, then as some method tells one stepper to speed up or slow down to allow steering, then both need to then decel and stop at the same time after some unknown distance traveled. It is not clear the context of 'stopping at the same time', as you would not stop at the end of the accel but rather the decel, so using the term ramp needs to be refined to indicate if accel or decel.

    Acceleration is the easy part, just adjust the waitcnt per stepper to achieve the speeds and steering direction. But, on decel, you need to think in terms of a fixed decel distance and decel code block that handles the decel + stop. Determine the minimum speed the steppers will run at under normal conditions(MINRUNSPEED), then below that speed the system considers that you want to stop everything. At that point the decel code block takes over, takes the current leftspeed and rightspeed, determines a distance in steps for each stepper to run to complete stop, then adjust the waitcnt for each stepper by a ratio based on the distance for each, with the goal to have each stepper at its MINDECELSPEED value just prior to the last step pulse.

    This may require scaling all the formulas up ( ie *10 or *100), then scale back down to arrive at the actual step pulses.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-01-12 08:51
    Javalin wrote: »

    I recall a variation of this I believe was refered to as "scaled interger". On an 8 bit machine, the values were scaled to 255, and everything done with intergers. It turned out to be more precsie than float when done correctly, and much faster.

    The numbers all look funky till you get used to the scaling, but after that it totally rocks (to use the technical term).
  • lardomlardom Posts: 1,659
    edited 2012-01-12 09:34
    @T chap, I think you have caused me to see my error.:thumb: I use a floatmath object to do the 'speed' calculations which get converted to integers and passed the stepper object. The same could be done for the ramping values.
    I have two steppers running in separate cogs. For the outer wheel the math is 2pi * radius (inches) * distance(in steps)/ time(seconds) . I subtract 13 inches from that equation for the inner wheel. I divide by 360 and multiply by 90. This works correctly. Ramping makes the robot hook at the end.
    The bresenham algorithm also seems to hold a solution since 'constant acceleration/deceleration' could be represented as a vector but I'll have to get back to it later today. At any rate I think I now have two workable solutions. Thank you.
    @prof_braino, A technique that's faster and more precise than float will become my preferred technique.
  • ErNaErNa Posts: 1,752
    edited 2012-01-12 12:17
    Hi,
    now I understand a little better. Let's assume there is a maximum acceleration and a maximum speed. As the outer wheel must run faster, calculations are done for the outer wheel. First determine the distance for to router wheel: O-Dist. Second determine the time to reach maximum speed: v=a*t: time = velocity/acc. The distance to reach the speed is vmax / 2 * time. The track consists of three parts: accel, const, decel. Now we know the three time stamps: accel finished, const movement finished, decel finished.
    The inner wheel will run the distance of the outer wheel multiplied by radius of inner wheel divided by radius of outer wheel. Now it's easy: acceleration and maximal speed of the inner motor must be calculated with the same factor.
    And: always multiply first and divide second. after you took care of overflow! ;-)
    ErNa
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-01-13 17:13
    Thanks ErNa. I think I even understand now.
  • lardomlardom Posts: 1,659
    edited 2012-01-14 09:12
    This is an illustration of what I'm after. The wheels on my mock-up robot are 13" apart. I'm designing it to move along a circumference. I program the radius in inches and the arc in degrees. It moves correctly as long as the velocity is constant. When I ramp the time/step-rate goes out of sync. I'm getting closer by trying the techniques described in this thread but synchronizing the time/step-rate while ramping is still an issue.
    439 x 456 - 14K
  • lardomlardom Posts: 1,659
    edited 2012-01-18 09:40
    Thanks to everyone that contributed to this thread and Rayman.
    It took four days but I got the steppers to synchronize. :smile: I had to apply principles from the Bresenham algorithm, integer scaling and a modified stepper object written by Rayman. (Rayman's object eliminated the DAT block and the need to calculate steps in multiples of 4.)
    The key to making it work was
    [B]UnusedVariable += TimeInterval [/B] 'eliminate execution overhead
    
Sign In or Register to comment.