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

S2 Ping))) Object and a FREE Offer

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2012-08-23 10:56 in Robotics
I think I've figured out a way for the S2 to support Parallax's Ping))) distance sensor. The fact that the usual Ping))) code does not work with the S2 was discussed here:

In a nutshell, the reason the Ping)) does not work with the S2 is due to the S2's hacker-port level translator, combined with its filter caps and the Ping)))'s series I/O resistor. As a consequence, the S2 does not see the low pulse that terminates the Ping)))'s timing interval. My solution is to use a counter in DUTY mode to bias the input to the Prop a little bit lower so it can catch the low pulse. It's a bit surprising that this actually works, since the DUTY output is on the same pin that's being read via waitpeq to catch the pulse. One would think that the low pulses on the DUTY output would trigger the waitpeq before it even got to the return pulse form the Ping))). But, apparently, the Prop itself has enough internal capacitance that an isolated 12.5 ns low pulse is not enough in and of itself to be recognized by waitpeq without a little external help driving the same pin.

The attached archive includes an object and demo program for the S2 Ping))) combo. It starts by doing a self-calibration for the DUTY bias value, then continues pinging and outputting distance values.

Now for the FREE offer. I've designed a Ping))) bracket for the S2, which I will mail free of charge to the first six people who test this program with their Ping))) on an S2. To qualify, you will need to post a copy of the demo program's output in this thread and email me your mailing address.

Here's a photo of the Ping))) bracket installed in the S2:

attachment.php?attachmentid=94899&d=1344971376

It does not use any fasteners. The Ping))) is held tightly in the acetal bracket by deformable grip rings.

BTW, the distance registered by the s2_ping object is the distance from the front of the S2, not the distance from the Ping))). Also, I have not bothered commenting anything yet. I need to know first whether the code works for everyone's particular S2/Ping))) combination.

-Phil
«1

Comments

  • PublisonPublison Posts: 12,366
    edited 2012-08-14 12:30
    Nice one Phil! I knew you were getting close based on the other thread. Don't have my S2 yet, so I'll sit by and see what the other S2 owners find on their units.
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-14 14:54
    Funny results...
    S2 Ping Test.jpg

    The Ping tries to calibrate for a seemingly random time, and then randomly sets the Bias: and dist: #s,
    After calibration, the Ping stops reporting any new distance readings...(the dist # never changes).


    -Tommy
    253 x 145 - 16K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-14 15:21
    Tommy,

    The bias value looks right and is about what I get on mine. Try setting the second argument of png.start to 100 and see if the behavior changes. With this setting you should see the light on the Ping))) flash about ten times per second after calibration.

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-14 16:00
    pst.hex(png.start(PING_PIN, 100), 8)
    
    I changed the 0 to 100 and I could see the Ping light, light..
    but that only lasts a few seconds before the Ping light stays on. I get Distance updates while the Ping light flashes...
    This is only after being turned off (power switch off) for a minute or so, and then reloading the eeprom using F11.

    If I just turn off the S2 and then back on, the Ping light flashes maybe 5 times, then stays on, and no Dist updates..


    -Tommy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-14 16:20
    Well, okay. Thanks, Tommy! It appears that my solution may not be that great. Anyone else wanna try it?


    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-14 16:31
    The code from post #14 of this thread http://forums.parallax.com/showthread.php?136921 works, but is not accurate at short distance..

    Your new code (from this thread) does return distance values, but only for a short while, then freezes up,
    Just wish I could be of more help..


    -Tommy
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-14 16:44
    I may give it a shot. I haven't cracked open an S2 yet!!
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-15 08:10
    Rev B Ping in Center of S2 approximately perpendicular and parallel
    Nose of S2 200mm from monitor screen

    Program as provided
    Bias: BE000000
    Dist: 186mm (most consistent distance - sometimes 6mm, 9mm or 55245mm)

    My PING light stays on constantly

    Changed png.start 2nd argument to 100 - no real change in results. Ping light never flashes.

    For a short moment, it measures distance but then picks a number top display and sticks with that.

    I removed the cursor positioning so it just kept printing lines - I was curious what actually was hanging up - it kept printing but the numbers never changed.

    I switched to a different PING (rev. B) - no change in results.

    My distances were consistently 15-20mm short of the actual nose to target distance when they were reported and looked reasonable.

    On the bright side, it was real easy to open up the S2 and add the PING to it! :lol:

    Ready for any other testing you require!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-15 09:39
    Okay, guys, thanks for your help and indulgence. Here's a debug version to try (one object this time):
    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      PING_PIN      = 0
    
    OBJ
    
      pst   :       "Parallax Serial Terminal"
    
    VAR
    
      long bias, mask, cog, first_reading, last_reading, stack[30]
    
    PUB  start | i
    
      stop
      pst.start(38400)
      mask := 1 << ping_pin
      if (cog := cognew(calibrate, @stack) + 1)
        waitcnt(cnt + clkfreq * 2)
        if (last_reading > first_reading + 3)
          bias := first_reading >> 1 + last_reading >> 1
          pst.hex(bias, 8)
          pst.char(13)
          coginit(cog - 1, background(100), @stack)
          repeat
            pst.char(14)
            pst.char(0)
            pst.str(string("Dist: "))
            pst.dec(dist_mm)
            pst.str(string(" mm"))
            pst.char(11)
        else
          stop
          return 0
           
    PUB stop
    
      if (cog--)
        cogstop(cog)
        cog~
         
    PUB dist_mm
    
      return (((last_reading / 80 - 800) >> 1) * 10_000 / 29034 - 90) #> 0
    
    PRI calibrate | time, ptime
    
      ptime := 0
      repeat bias from $8000_0000 to $f000_0000 step $0100_0000
        last_reading := bias
        time := measure
        pst.hex(bias, 8)
        pst.char(" ")
        pst.dec(time)
        pst.char(13)
        if (||(time - ptime) * 100 / time > 20)
          first_reading := bias
          ptime := time    
    
    PRI background(interval) | time
    
      interval := (interval * 80_000) #> 800_000
      time := cnt
      repeat
        if (time - cnt =< 0)
          time := cnt + interval
          last_reading := measure   
    
    PRI measure : time
    
      dira[ping_pin]~~
      frqa := bias
      outa[ping_pin]~~
      waitcnt(cnt + clkfreq / 1000)
      outa[ping_pin]~
      time := -cnt
      ctra := constant(%00110 << 26)
      waitpeq(0, mask, 0)
      time += cnt
      ctra := 0
    

    I'd be interested in seeing what the last 30 or so lines look like.

    Thanks,
    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-15 10:17
    This works great Phil, It shows 0 mm's at the S2's front bumper, and a max distance read of over 3600.
    And steady as a rock too, ran for five minutes, twice...:thumb::thumb:
    S2 Ping Test 1.jpg



    -Tommy
    138 x 687 - 89K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-15 10:38
    Excellent! Now, please give the new demo/object version another try, if you don't mind.

    Thanks,
    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-15 11:40
    Seems to work perfectly, :thumb::thumb:
    all though I can't vouch for the accuracy of distance, as I don't know from mm's,
    IIRC 1/2 inch is pretty close to 12mm's and that is close to what the Ping((( was reporting,
    and at 6 inches from the bumper, the Ping reported about 175 mm or so.. +/- some spastic hand movements...

    Here is the reading at the front bumper...
    S2 Ping Test 2.jpg


    -Tommy
    255 x 176 - 13K
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-15 11:51
    Testing to commence as soon real world job stops interrupting and the workspace is cleared of "obstacles".

    workspace.jpg
    1024 x 768 - 66K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-15 12:39
    Now there's a contented cat!

    Hey you guys, email me your postal addresses, and I'll send you each a laser-cut Ping))) bracket for your S2.

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-15 13:18
    Sure glad to see the S2 vs Ping((( issue ironed out, now I will see what kind of navigation trouble I can get the S2 into...

    I would love to have one of your laser cut Ping((( brackets Phil, Especially since erco doesn't have one... :)
    Thanks for your time with this.


    -Tommy
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-15 14:38
    Brilliant!!

    It was good to within 10-15mm (short of actual distance) with my jury rigged holder. This will be so sweet to have a working Ping((( on an S2! I can't wait to tune it up with a rigid support!

    I'd love to have a bracket, thank you!

    {The cat left just long enough for me to test. He's back now, tired out again after snacking!}
  • WhitWhit Posts: 4,191
    edited 2012-08-16 20:17
    Great work Phil and testers/contributors! Will give this a try with the GatorBots when we are up and running. School just started this week.
  • ercoerco Posts: 20,256
    edited 2012-08-16 23:14
    Ttailspin wrote: »
    I would love to have one of your laser cut Ping((( brackets Phil, Especially since erco doesn't have one... :)

    Maybe I can find one made of plywood on Ebay. :)
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-18 20:01
    Fiddlesticks! I spoke to soon, The S2 Ping((( Object is acting up again...

    I tried to run the latest version this afternoon and it froze up within seconds, tried a couple of times with same results.
    Figured it might have something to do with ambient temperature, it was about 80 degrees when I turned the S2 on,
    So I thought I might wait till the fog rolled in and cooled everything down to about 68 or so.
    Success! I tried the program again, and it ran as advertised for at least ten minutes, then I rebooted the S2, and
    the program froze within maybe twenty seconds, so I reboot again, and it freezes in about 5 seconds,
    Reboot again, and it freezes almost instantly...:frown:

    I waited 30 minutes and tried again, The program ran for thirty seconds then froze, Reboot and it ran for 5 seconds,
    Reboot again, and she freezes instantly again...

    I was curious, and so I reloaded the Debug code from post #10
    Unfortunately, it also froze after about thirty seconds or so...
    Ping Test3.jpg

    I offer An uneducated guess that something heats up and changes the bias thingy into some kind of monster...

    I did receive the S2 Ping((( mounting bracket (that erco does not have), and wanted to thank you again Phil.
    don't think ebay is going to have these in plywood anytime soon...:smile:

    Anyways, let me know what how I can help to test the next version of the S2 Ping((( Object, when you get around to it...


    -Tommy
    144 x 631 - 88K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-18 20:13
    Tommy,

    A lot depends upon what the Ping))) is aiming at during calibration. From your debug output, it looks as if there may be two objects in its field of view, one closer than the other. Try aiming it away from any objects during calibration, or else place a flat, hard surface about six inches away or so.

    -Phil
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-18 20:20
    I'll try it again tomorrow. I hadn't done anything since the initial testing.

    Hopefully reporting news tomorrow.

    P.S. I also received my Ping mount too. Excellent work! Thanks, Phil!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-18 20:40
    BTW, the program may well be temperature-dependent, to whatever extent temperature affects the Prop's logic thresholds and internal propagation times. Basically, it's little more than a hail Mary pass until Parallax is able to change the Ping's firmware to extend the amount of time it holds the output low after receiving an echo. Once that occurs, simpler, less fussy S2 code will be possible.

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-18 21:15
    Ok, I started the Ping((( six inches from a hard surface (the box the S2 came in), and I thought that fixed it, it ran for several minutes.
    Then I tried to duplicate the symptoms I described earlier, but I could not get the program to freeze no matter what I tried...

    I was just about to declare success again and reached over to turn off the S2, and the program froze, I then went thru several cycles
    of rebooting and freezing... So just to make sure, I again started the Ping((( while it was facing the hard surface six inches away.
    but... the program froze anyway... so now I wonder if I am not so far off when I say "Something gets warmed up and throws the bias off"

    I will pull out a stop watch and thermometer tomorrow morning and try to be more precise..

    -Tommy
  • TtailspinTtailspin Posts: 1,326
    edited 2012-08-19 11:41
    I ran the program this morning, the temp was 66 degrees F.

    First test lasted 40 minutes continuous running with no obvious defects.
    I.E, Min dist at bumper =0, Max dist =3630, and all ranges in between measured accurately for many minutes at a time.
    Started the S2 NOT facing a wall and the Bias # was: BE800000, the Dist # varied as expected.

    I figured 40 minutes was long enough, So I turned off the S2, faced it toward a wall 6 inches away, and turned it back on.
    Poof, Instant freeze... the Bias # was: BF800000, the Dist # was: 55245.

    Test 3, the S2 was again NOT facing the wall, and the program worked as expected until I reset after 2 minutes,
    The Bias # : B5800000, and Dist # varied as expected.

    Test 4 thru 10, the S2 was facing the wall, and froze within one second after reporting various Bias #s
    BF000000, B5000000, and (BF800000 << always associated with a Dist reading of 55245 for what it's worth...)

    Test 11 thru 16, the S2 was NOT facing the wall, and the program worked as expected for at least 2 minutes
    before I would reset the power...

    So this morning I've come to the conclusion: "Don't have any obstacles in front of the Ping((( when you power up".

    This afternoon I will test again, and most likely will come to the conclusion: "My head hurts...":tongue:


    -Tommy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-19 11:50
    Sorry for the migraines, Tommy. I wish there was more I could do to alleviate them, but I don't think there are any other pure Spin plays left. 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. Perhaps a PASM loop with a timeout can do the trick. Stay tuned...

    -Phil
  • ercoerco Posts: 20,256
    edited 2012-08-19 12:04
    Man, you guys are working hard! You're really earning those "free" PING stands...
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-19 13:20
    Ambient temp 79 degrees

    20 minutes no problems with start from about 1360mm from object. Appears to be accurately measuring.

    Restarted with object at nose (0mm) - running fine like that for about 5 minutes so far. Distances changing and settling down to be pretty accurate.

    My S2 will not reset, I need to turn on/off. Not sure if related, I may just have a hardware issue on this one.

    I haven't had mine hang up. I may let this run for a while and then switch to a different PING)))

    I think my S2 needs a 2 PING))) turret to sit in the center, driven by a servo.......if only I knew someone with a laser cutter......
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-19 13:25
    mindrobots wrote:
    My S2 will not reset, I need to turn on/off. Not sure if related, I may just have a hardware issue on this one.
    The "reset" button on the S2 is not wired to /RST. It has to be programmed to cause a reset, which is something the S2 object handles. Since my demo program does not start the S2 object, the button will be non-functional.
    I think my S2 needs a 2 PING))) turret to sit in the center, driven by a servo.......if only I knew someone with a laser cutter......
    Uh, oh. My testers are getting restless -- and demanding. :)

    -Phil
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-19 13:35
    Good thing to know about RESET. Didn't know that little fact!

    Shortly after I hit "post" on the last message it hung up.

    Now it's acting flakey. I'll recycle it again and see how it does.

    ....maybe I don't need that turret after all! :lol:

    On the good side, I've found out that cats don't absorb high frequency as much as I thought they would!!!
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-19 14:55
    1 Hr 20 minutes without fail. Initialized to 0mm with object on nose.

    Beats me!

    Time for some field trials!
Sign In or Register to comment.