Shop OBEX P1 Docs P2 Docs Learn Events
S2 Ping))) Object and a FREE Offer - Page 2 — Parallax Forums

S2 Ping))) Object and a FREE Offer

2»

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-20 12:39
    Here's a brand new approach that uses PASM (and no pre-calibration):
    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      PING_PIN      = 0
    
    OBJ
    
      pst   :       "parallax serial terminal"
    
    VAR
    
      long echo
    
    PUB  start
    
      pst.start(38400)
      cognew(@ping, @echo)
      repeat
        pst.char(1)
        pst.dec(dist_mm)
        pst.char(11)
    
    PUB dist_mm
    
      return (((echo / 80) >> 1) * 10_000 / 29034 - 87) #> 0
    
    DAT
    
    ping          mov       dira,pin_mask
                  test      cnt_mask,cnt wc
            if_c  jmp       #ping
            
    :wait_hi      test      cnt_mask,cnt wc
            if_nc jmp       #:wait_hi
    
                  mov       outa,pin_mask
                  mov       dira,pin_mask
    :wait_pulse   test      pulse_mask,cnt wc
            if_nc jmp       #:wait_pulse
    
                  mov       outa,#0
    
    :wait_wait    test      wait_mask,cnt wc
            if_nc jmp       #:wait_wait
            
                  mov       dira,#0 
                  neg       time,cnt
    
    :echo_loop    mov       dira,pin_mask
                  mov       dira,#0
                  nop
                  nop
                  nop
                  test      pin_mask,ina wc
            if_c  jmp       #:echo_loop
    
                  add       time,cnt
                  wrlong    time,par              
                  jmp       #ping
    
    cnt_mask      long      $0040_0000
    pulse_mask    long      $0002_0000
    wait_mask     long      $0001_0000
    pin_mask      long      1 << PING_PIN
    
    time          res       1
    

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-20 20:01
    This is working great! Phil, no problems to report..:blank:
    I will let it heat up for a while, and see whats to see. it's only been running ten minutes or so...

    The problem is that the pulse that has to be detected is so short and so runty, that nothing short of waitpeq in Spin will catch it. And, if waitpeq misses it, well, you know what happens then.
    Can't tell you how much this short explanation cleared some things up for me. Thanks very much.:thumb:


    -Tommy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-21 09:39
    I'm much happier with the new code, since the Ping))) pin isn't being driven all the time during the detect interval, but just pulsed low then tri-stated again. I've created an object from the new code and replaced the previous version in the first post with it.

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-22 17:29
    Works great Phil, thank you for your time with this. :thumb::thumb:

    Here is my version of "Roaming with a Ping((("
    CON
      _CLKMODE = XTAL1 + PLL16X
      _CLKFREQ = 5_000_000
      PING_PIN      = 0
      
    OBJ
      S2       : "S2"
      S2_ping  : "S2_ping"
      
    PUB Main | distance
      S2.start                                ' Start S2 object
      
      S2.set_led(s2#POWER, s2#BLUE)           ' Turn on the power LED.
      
      S2.start_motors                         ' Start motor controller
      S2_ping.start(PING_PIN)                 ' Start Ping((( controller
      repeat
        S2.move_now(100, 100, 0, 10, 1)       ' Forward until preempted.
        
        distance := (S2_ping.dist_mm)         ' Get distance reading from ping(((
        
        if distance < 170                     ' if distance less then 170 then...
        
          S2.stop_now                         ' Stop moving
               
          S2.set_speed(15)                    ' Set turning speed 
            S2.begin_path                       ' Begin path
            S2.turn_deg(-90)                    ' Turn right.
            S2.end_path                         ' End movements
            S2.wait_stop                        ' Wait for turn to complete
    
    
    Not the fanciest code, but she works...

    -Tommy
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-22 17:39
    Oooh, oooh!! I forgot to share yesterday.

    I loaded the new code, put my PING))) in my new holder and went measuring distances. It worked like a champ for about 30 minutes of playing.

    Well done!!!

    Now, I'll have to go roaming with Tommy's code. My S2 hasn't had this much attention in a long time!!


    Hmmm.....wonder how the S2 would like running under Forth? Hmmm......
  • ercoerco Posts: 20,256
    edited 2012-08-22 19:29
    Sounds like Phil split the atom AGAIN! Great work PhiPi, as usual, there nothing you can't make the S2 do. How's your hovering object coming along?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-22 19:57
    erco wrote:
    How's your hovering object coming along?
    There's no hope in that department, I'm afraid, since there's no way I could test such a thing. Lack of eye-hand coordination renders me useless as an RC pilot. :(

    -Phil
  • ercoerco Posts: 20,256
    edited 2012-08-23 10:16
    Hmm. Parallax ought to pull a Skycrane maneuver, lowering an S2 to the ground from a hovering ELEV-8.
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-23 10:56
    Can we have "Ride of the Valkyries" playing the background??

    I love the smell of magic smoke in the morning...
    ... it smells like.....testing!
Sign In or Register to comment.