Shop OBEX P1 Docs P2 Docs Learn Events
Bresenham's line algorithm - ( Stepper motor pre-requisite ) - Page 2 — Parallax Forums

Bresenham's line algorithm - ( Stepper motor pre-requisite )

2

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2013-01-24 08:51
    Gareth wrote: »
    Tnx erco.....(ahha..from the Swiss institute NY)

    Heres my first attempt at Circles......

    All that friction/backlash - perhaps the mechanics of the E-a-Sketch need upgrading... Is that possible? (fear they are welded/glued shut)
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-01-24 08:57
    Nicely done! Doing that by hand would take utmost patience and hand control. Epicycloids and hypocycloids cannot be far behind! Luckily at Chaco, they could not shake to erase.

    FWIW, I added a wrapper to the alternative straight line algorithm in edited post #12.
  • GarethGareth Posts: 278
    edited 2013-01-24 09:00
    This is here for my reference so i know where it is when i want it....
    lissajous.jpg



    x(t) = a sin(ωt + δ)
    y(t) = b sin(t)

    lissajous1.jpg
    400 x 317 - 29K
    259 x 141 - 15K
  • GarethGareth Posts: 278
    edited 2013-01-24 09:01
    I added a wrapper to the alternative straight line algorithm in edited post #12.
    Tnx for update.... will check ASAP
  • ercoerco Posts: 20,256
    edited 2013-01-24 10:48
    I thought the metric system used tau, not pi... :)http://tauday.com

    This is an awesome thread. A beautiful mix of clean, theoretical math/geometry with a healthy dose of reality (EAS friction, backlash etc) thrown in to keep everyone (OK, Gareth) honest. Nothing is ever as simple as it seems. As someone said previously, "everything works in a simulation".
  • ercoerco Posts: 20,256
    edited 2013-01-24 11:02
    Luckily at Chaco, they could not shake to erase.

    Unfortunately the Sun Dagger has been shaken and erased. The stones have settled & shifted (likely due to erosion caused by visitor traffic) and no longer cast the correct light patterns, and has been off-limits to park visitors since the 1980's. What a pity. It functioned perfectly for a thousand years until it was "rediscovered" in 1977 and then ruined within a single decade. At least it was studied and thoroughly documented. It lives on in an interactive digital exhibit in an Albuquerque museum. I wish they would put that model online. It is still a mystery how the Anasazi built it.

    http://accad.osu.edu/~aprice/works/sundagger/index.html
  • Heater.Heater. Posts: 21,230
    edited 2013-01-24 11:06
    This is an amazing thread.

    The last time I held an Etch A Sketch in my hands could easily be 45 years ago.
    That toy has won a lot of praise, even awards, for being a brilliant toy.
    But, as a kid at the time, whilst being fascinated by it's operation, I wrote it off as being essentially useless.
    OK drawing verical and horizontal lines is great and all but anything else was better done with a pencil and paper. I thought it was basically a stupid idea.

    Little did I realize that a few years later I could have automated it with a 8 bit computer and basically had a plotter on the cheap before anyone else. What an imagination failure.

    The idea of a Pocket Etch A Sketch is amazing in itself. I mean, as if one would have a desperate urge to draw some vertical or horizontal lines whilst on the move.

    Seems they had some Etch A Sketches with LCD later in the day, gack.
  • Heater.Heater. Posts: 21,230
    edited 2013-01-24 11:11
    Erco,
    I thought the metric system used tau, not pi.

    Over here in metric land I had never heard of Tau until very recently. Although my young mind had rebelled at Pi for reasons it did not quite understand.

    There is no mention of metric in that Tau link.
  • ercoerco Posts: 20,256
    edited 2013-01-24 11:11
    This guy cleverly used a full-sized EAS as a data logger for temperature. Using a frosty Guiness for a "cold" reference makes me appreciate it even more. :)

    http://ijprojects.blogspot.com/2012/06/etch-sketch-turned-temperature-data.html
  • Heater.Heater. Posts: 21,230
    edited 2013-01-24 11:26
    Erco,

    I love it.

    But Guiness should never be "frosty".

    Something like 55-63 F is quite OK.

    Like any real beer, or anything actually, the colder it gets the less it smells and tastes.

    Why spend your money on flavour if you are going to waste it? Might as well suck another Bud.
  • ercoerco Posts: 20,256
    edited 2013-01-24 13:06
    @Heater: You're right. On a bicycle tour through the UK, I stayed at http://theoldbarninnglooston.com/. Didn't know a soul there, but at the end of the evening, I was everyone's chum in the pub downstairs. They liked that I was cycling through and running the London marathon later that week. Bartender "Charles at the bar" was the coolest guy around and kept the Guinness flowing. He showed me his specialized tap that the Guiness company had to actually install there. And yes, it was temperature regulated, because there is such thing as "too cold".
  • GarethGareth Posts: 278
    edited 2013-01-25 08:31
    JUST TO BrinG tHe Blog back on track (tsktsk to falling down water adverts)
    Spirals.....I got spirals.. and things I cant describe ....yet
    Main blog has been updated above...
    336.JPG
    338.JPG
    640 x 480 - 212K
    640 x 480 - 93K
    336.JPG 212.1K
    338.JPG 93.5K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-01-25 13:11
    How about meeting of the toys, etch-a-sketch as spirograph?

    Two frequencies, like the lissajous curves above, but with sine and cosine components combined as follows. Amplitudes A and B, frequencies Fa and Fb. Simple spirograph patterns with A:B and Fa:Fb as ratios of small integers. Keep A+B constant to maintain a constant overall size.

    epicycloids
    y = A * sin(2 * pi * Fa * t) + B * sin(2 * pi *Fb * t)
    x = A * cos(2 * pi * Fa * t) + B * cos(2 * pi *Fb * t)

    or
    hypocycloids
    y = A * sin(2 * pi * Fa * t) + B * cos(2 * pi * Fb * t)
    x = A * cos(2 * pi * Fa * t) + B * sin(2 * pi *Fb * t)

    In terms of Erco's robot arm from post #14, two links and two pivots, epipcycles have the links rotating in the same direction at two different rates, while hypocycloids have the links rotating in opposite directions. Why trouble with a straight line?
  • GarethGareth Posts: 278
    edited 2013-01-25 15:01
    How about meeting of the toys, etch-a-sketch as spirograph?

    The good news is your code works much better (way faster) than mine sooo i am migrating to your method.
    Below are some direct LCD plots from your code using various sin cos pi values and joining the dots.
    This goes to show how easy it is to create "tool path" stepper motor data for not only for EAS or SG.
    IMG_0978[1].JPG
    IMG_0977[1].JPG
    IMG_0976[1].JPG

    I am in the process of shoehorning your method to suit my stepper controls.....then i cant wait to try out those formulars.
    640 x 480 - 142K
    640 x 480 - 129K
    640 x 480 - 132K
  • ercoerco Posts: 20,256
    edited 2013-01-25 17:30
    Gareth wrote: »
    then i cant wait to try out those formulars.

    Gareth: Don't you mean "maths", as you Brits are wont to say? :)
  • HumanoidoHumanoido Posts: 5,770
    edited 2013-01-25 23:19
    erco wrote: »
    ...Don't you mean "maths"...? :)
    Erco, speaking as a translator "it's all English," but did you cheque and wonder about the programme catalogue, i.e. behaviour of the centre colour flavour of the labour tyre appearing plotte?

    http://en.wikipedia.org/wiki/American_and_British_English_spelling_differences
  • GarethGareth Posts: 278
    edited 2013-01-27 08:56
    This is a very "Grey" - (EU) or should i say "Gray" - USA .... area ...... seems in Europe there is also the ultimate blue print "Queens English" and the close partner "Business English"

    Once again lets get this blog on track again........

    Need to get my display - sin-cos-radians-pi in order to attempt Tracy's epicycloids and hypocycloids.
    First Etappe (Fr) is to plot simple circle (yes i know i have done it on countless occasions .... so here it is in code for reference)
    AcircleSize := 50
    
      repeat circumference from -180 to 180  step 5                    ' Integer PI step values
            
          fx := f32.FFloat( circumference )                            ' convert integer circumference to FloatingPoint
          fAcircleSize := f32.FFloat(AcircleSize)                      ' convert integer circle to FloatingPoint circle
          fy := fx                                                     ' duplicate value for Cos bit
          
          fx := f32.FMul( f32.sin( f32.Radians(fx)),fAcircleSize )     ' calculate Sin(fx in Radians)* circle size
          fy := f32.FMul( f32.cos( f32.Radians(fy)),fAcircleSize )     ' calculate Cos(fy in Radians)* circle size
          
          x0:=f32.FTrunc(fx)                                           ' Convert back to an integer
          y0:=f32.FTrunc(fy)
    
       gr.plot(x0+100,y0+100)                                          ' position point on screen
        
      gr.copy(display_base)                                            ' Transfer bitmap to Visual screen
    
    004.JPG


    By my reckoning i need just two of these routines and interplot one circle onto the other taking into account the size, frequency, phase of each cycloid part.
    y = A * sin(2 * pi * Fa * t) + B * sin(2 * pi *Fb * t)
    I am assuming that the "t" is the phase of the signal .hmmmm!!!!
    That's the theory.....
    640 x 480 - 149K
    004.JPG 149.3K
  • GarethGareth Posts: 278
    edited 2013-01-28 01:18
    Not quite a continuous line yet ..... however some neat graphics are appearing :-
    008.JPG
    001.JPG

    007.JPG

    002.JPG
    003.JPG

    009.JPG

    004.JPG
    006.JPG
    640 x 480 - 129K
    640 x 480 - 125K
    640 x 480 - 135K
    640 x 480 - 123K
    640 x 480 - 128K
    640 x 480 - 88K
    640 x 480 - 165K
    640 x 480 - 255K
    001.JPG 128.6K
    002.JPG 125.4K
    003.JPG 135.1K
    007.JPG 122.6K
    004.JPG 127.7K
    006.JPG 87.8K
    009.JPG 164.9K
    008.JPG 255.5K
  • HumanoidoHumanoido Posts: 5,770
    edited 2013-01-28 05:35
    Very good. The designs where you present complete SPIN code are particularly useful. For the next step: Do you have a 3D printer to attach to this and print out some of the more interesting figures? You could probably make a slinky or Magician's Rings but it would be more interesting to see some of the multidimensional Tesseracts that could perhaps represent spacial corridors in a multidimensional universe with techniques of overprinting and assembly.
  • Mark_TMark_T Posts: 1,981
    edited 2013-01-28 05:35
    Bressenham's circle algorithm would avoid using sine and cosine for some of these figures ;)
  • GarethGareth Posts: 278
    edited 2013-01-28 07:29
    Humanoido wrote: »
    Do you have a 3D printer....
    No i do not have one but i would need one like yesterday already......
    I see your point with the 3D printing........ i have seen wheels with this "tweel" or honeycomb like design.... maybe it worth one of 3D printer Paralaxians trying this out.
    Honeycomb.jpg
    270 x 269 - 16K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-01-28 08:54
    Looking good!

    I am assuming that the "t" is the phase of the signal .hmmmm!!!!
    That's the theory.....


    t is for time, and the whole (2*pi*F*t) is the instantaneous phase. There is no intrinsic time element in the curves. You can turn the gears on a Spirograph as fast or slow as you want. The time element comes in more with say an oscilloscope display or dynamical system like a compound pendulum. In a discrete time system t is the step you use to draw out the function as a dotted line. The more steps you use, the smoother the curve.

    You are right, is better to look at it as a pair of phase accumulators. At each time step, oscillator A accumulates angle Ωa and oscillator B accumulates angle Ωb.
    repeat
      y := A * sin(Ωa) + B * sin(Ωb)
          x := A * cos(Ωa) + B * cos(Ωb)
      plotToYX
      Ωa += deltaΩa    ' two angular frequencies.
      Ωb += deltaΩb    ' ratio Ωa/Ωb, and A/B determine shape
    
    The CORDIC rotation algorithm does exactly that, or the phase accumulator can be sized for lookup in the ROM sine table. The smaller the increment values, the truer and smoother the curve.
  • GarethGareth Posts: 278
    edited 2013-01-29 08:36
    First stab at the code .....a bit OTT but it appears to be ...almost working...(however i am not getting a dot2dot continous line - it plots one point an then the next point is 180° on the other side if you know what i mean - could be a floating point miss_understanding by me)
     OmegaA :=180
     OmegaB :=90
     DeltaA :=60
     DeltaB :=5
     A:=40
     B:=40
      
     floatvariables
    
      repeat
         'y := A * sin(Ωa) + B * sin(Ωb)
         fy1 := f32.FMul(fA,F32.sin(fOmegaA))
         fy2 := f32.FMul(fB,F32.sin(fOmegaB))
         fy  := F32.FAdd( fy1,fy2)
        
         'x := A * cos(Ωa) + B * cos(Ωb)
         fx1 := f32.FMul(fA,F32.cos(fOmegaA))
         fx2 := f32.FMul(fB,F32.cos(fOmegaB))
         fx  := F32.FAdd( fx1,fx2)
    
         x := F32.Ftrunc(fx)
         y := F32.Ftrunc(fy)
         gr.plot(100+x,100+y)
         gr.copy(display_base)
    
         fOmegaA := F32.Fadd( fOmegaA,fDeltaA)   'Ωa += deltaΩa    ' two angular frequencies.  
         fOmegaB := F32.Fadd( fOmegaB,fDeltaB)   'Ωb += deltaΩb    ' ratio Ωa/Ωb, and A/B determine shape   
    
                                   
    PUB FloatVariables    
      fx  := f32.FFloat(x)
      fx1 := f32.FFloat(fx1) 
      fx2 := f32.FFloat(fx2)
      fy  := f32.FFloat(y)
      fy1 := f32.FFloat(fy1)
      fy2 := f32.FFloat(fy2)
      fA:= f32.FFloat(A)
      fB:= f32.FFloat(B) 
      fOmegaA:= f32.FFloat(OmegaA)
      fOmegaB:= f32.FFloat(OmegaB)
      fDeltaA:= f32.FFloat(DeltaA)
      fDeltaB:= f32.FFloat(DeltaB)               
    
    Results :-

    20DollarPicaxe 059.jpg
    20DollarPicaxe 060.jpg

    20DollarPicaxe 061.jpg
    20DollarPicaxe 062.jpg

    20DollarPicaxe 063.jpg
    20DollarPicaxe 064.jpg

    20DollarPicaxe 057.jpg
    20DollarPicaxe 058.jpg

    20DollarPicaxe 065.jpg
    20DollarPicaxe 066.jpg
    640 x 480 - 88K
    640 x 480 - 251K
    640 x 480 - 74K
    640 x 480 - 196K
    640 x 480 - 66K
    640 x 480 - 217K
    640 x 480 - 71K
    640 x 480 - 108K
    640 x 480 - 152K
    640 x 480 - 220K
  • GarethGareth Posts: 278
    edited 2013-01-29 09:21
    Gareth wrote: »
    180° on the other side ...
    Duh...... forgot to convert to radians......... Bingo
    fy1 := f32.FMul(fA,F32.sin(F32.radians(fOmegaA)))
    fy2 := f32.FMul(fB,F32.sin(F32.radians(fOmegaB)))

    20DollarPicaxe 067.jpg


    Means that i can use the "Line Code" to fill in the spaces between the dots .... YAY another hurdle over....

    Revised code :-
    OmegaA :=180
     OmegaB :=180
     DeltaA :=9
     DeltaB :=1
     A:=30
     B:=60
      
     floatvariables
    
      repeat
         'y := A * sin(Ωa) + B * sin(Ωb)
         fy1 := f32.FMul(fA,F32.sin(F32.radians(fOmegaA)))
         fy2 := f32.FMul(fB,F32.sin(F32.radians(fOmegaB)))
         fy  := F32.FAdd( fy1,fy2)
        
         'x := A * cos(Ωa) + B * cos(Ωb)
         fx1 := f32.FMul(fA,F32.cos(F32.radians(fOmegaA)))
         fx2 := f32.FMul(fB,F32.cos(F32.radians(fOmegaB)))
         fx  := F32.FAdd( fx1,fx2)
    
         x := F32.Ftrunc(fx)
         y := F32.Ftrunc(fy)
         gr.plot(100+x,100+y)
          gr.copy(display_base)
          pause(100)
         fOmegaA := F32.Fadd( fOmegaA,fDeltaA)   'Ωa += deltaΩa    ' two angular frequencies.  
         fOmegaB := F32.Fadd( fOmegaB,fDeltaB)   'Ωb += deltaΩb    ' ratio Ωa/Ωb, and A/B determine shape   
      
                                   
    PUB FloatVariables    
      fx  := f32.FFloat(x)
      fx1 := f32.FFloat(fx1) 
      fx2 := f32.FFloat(fx2)
      fy  := f32.FFloat(y)
      fy1 := f32.FFloat(fy1)
      fy2 := f32.FFloat(fy2)
      fA:= f32.FFloat(A)
      fB:= f32.FFloat(B) 
      fOmegaA:= f32.FFloat(OmegaA)
      fOmegaB:= f32.FFloat(OmegaB)
      fDeltaA:= F32.FFloat(DeltaA)
      fDeltaB:= F32.FFloat(DeltaB)               
    
    
    640 x 480 - 78K
  • GarethGareth Posts: 278
    edited 2013-01-30 09:08
    Hypocycloids :-
    025.JPG
    024.JPG


    And Etch-A-Sketch Epicycloids using Line stepper code :-
    026.JPG
    028.JPG
    640 x 480 - 82K
    640 x 480 - 102K
    640 x 480 - 121K
    640 x 480 - 137K
    025.JPG 81.9K
    024.JPG 101.8K
    026.JPG 121.2K
    028.JPG 137.1K
  • ercoerco Posts: 20,256
    edited 2013-01-30 13:33
    Beautiful! Now you're barkin'...!
  • JasonDorieJasonDorie Posts: 1,930
    edited 2013-01-30 14:33
    I did this a while back, though with a bigger Etch-a-Sketch. That might have actually made it easier to control. I set up the motor control code to deal with backlash and got semi-decent curves out of it. It's possible that the bigger unit makes this easier (or the bigger screen makes the lash less visible).

    You can actually see the backlash compensation fairly well in the first video - when the gears change direction, they slow down first, then there's a little pop of speed to take up the lash, then they ramp back up again. It's a fun hack to play with.

    [video=youtube_share;8omfh-s9EPA]

    [video=youtube_share;-MNqW1GT4nc]
  • HumanoidoHumanoido Posts: 5,770
    edited 2013-02-01 08:48
    I think you could use this to design a stellar performance engine simulation with on paper with results that show a space time nozzle with particular shapes to control flow. Any other current ideas for use?
  • Mark_TMark_T Posts: 1,981
    edited 2013-02-03 05:09
    By a sad coincidence it appears the EaS inventor has passed away recently. http://www.bbc.co.uk/news/world-us-canada-21311866
  • GarethGareth Posts: 278
    edited 2013-02-03 12:35
    JasonDorie wrote: »
    I did this a while back, though with a bigger Etch-a-Sketch.

    I like it.... I have already ordered a larger one from the UK it was not an easy job to track it down.
    I am not to worried about the speed with the mini one i have, however i will need to upgrade the steppers for the larger one i guess.
    Its neat to see your code and in many areas its simular to yours (even down to the stepper motor outputs !!)
    The back lash code i have not installed yet, the line routines are higher priority......the EAS is anyhow only a quick output devise to test software.
    The smiley and spanner video at first reminded me of Jaimie Mantze logo ......
Sign In or Register to comment.