Shop OBEX P1 Docs P2 Docs Learn Events
Ping))) Problem — Parallax Forums

Ping))) Problem

wellman.ronwellman.ron Posts: 16
edited 2007-11-20 18:00 in BASIC Stamp
I've installed a ping))) sonar on my boe-bot, pointed down toward the table surface and initialized at 3 cm, so that when it reaches the edge of the table and sees opver the edge it stops backs up and turns around. I want it to recross the table to the starting point and when it sees over the edge, to stop. Not having a lot of luck. When I run the sample program from the Parallax website, it sees the table at 3 cm; when I lift the bot off the table, it says the distance is 4 cm, when I set it back on the table I have to press reset button to get it to see the 3 cm distance again. When I run the bot untethered, it crosses the table until it sees over the edge, backs up and turns around and stops. Only way to get it moving again is to press reset. Now it moves but pressing reset also resets my counter. Anyone have a suggestion for me?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-11-19 00:09
    Yes, show us the code you are running.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • wellman.ronwellman.ron Posts: 16
    edited 2007-11-19 00:41
    Stephan,

    thanks for your quick response.

    My code is in an attachment. This is my first time to use the forum, so I followed the directions although I don't see any indication that the attachment is attached to this post.

    I also have another question; I don't understand the '$200' value for the 'Scale' variable, which I carried over directly from the Parallax program for the Ping))) sonar. Maybe I've missed something but I haven't found the meaning of the '$'.

    BTW, I am using PB2.5.

    thanks, ron
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-19 00:52
    ron,
    The "$" indicates that the number is in hexadecimal, so $200 is the same as 512.
    You can indicate binary by using "%", so %1000 is the same as 8.

    Next time, don't use a ".doc" file for your attachment. Just attach the ".bs2" file.
    It's easier to use that way.

    Don't do a GOSUB EndProgram. It will work in this case, but it's wrong because
    you're called a subroutine that will never return (since the END stops the program).

    Post Edited (Mike Green) : 11/19/2007 12:57:05 AM GMT
  • wellman.ronwellman.ron Posts: 16
    edited 2007-11-19 01:10
    ok here's my code in .bs2 format; thanks
  • FranklinFranklin Posts: 4,747
    edited 2007-11-19 02:47
    Every time you go through forward you increment the edgecounter and you check it once if the distance is more than 3cm at which point it will almost always be > 1

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • wellman.ronwellman.ron Posts: 16
    edited 2007-11-19 05:23
    Franklin said...
    Every time you go through forward you increment the edgecounter and you check it once if the distance is more than 3cm at which point it will almost always be > 1


    But I initialized edgeCtr to 0; so the first time the bot looks over the edge, I say edgeCtr = edgeCtr +1. So now edgeCtr has the value of 1. Since '1' is not 'more than 1', the program should continue. After it looks over the edge the second time, the value for edgeCtr is 2, which is more than 1.

    I think the problem is somehow with the ping))) device or code for it. Like I said in my first post, if you lift the bot while connected to the serial cable, even though I lift it 12 inches, the value for cm only increases to 4, and when I set it back down on the table the value does not return to 3 unless I press the reset button. So I need information about how the ping))) device is working/should be working. I traded out the first ping))) with a previously unused one to no avail.

    With the Ping_Demo.bs2 from the website the values increase as I raise it and decrease back to the original when I lower it back to the tabletop. With my program the rawDist value increases by a considerable amount but the cm distance increases by 1 centimeter and freezes at the high value even while it is lowered back to the tabletop. When I press the reset button I again get the expected values.

    Here are the values:
    on tabletop ~12 inches above tabletop back on tabletop after reset
    Ping_Demo.bs2: 96uSec and 3cm 996uSec and 34cm 96uSec and 3cm
    My program: 96uSec and 3cm 198uSec and 6cm 198uSec and 6 cm 96uSec and 3 cm

    thanks for any ideas anyone may have about this! ron
  • wellman.ronwellman.ron Posts: 16
    edited 2007-11-19 05:31
    here are the values, in a more readable format:

    Ping_Demo.bs2:

    on tabletop: 96 uSec and 3 cm
    ~12 in. above tabletop: 996 uSec and 34 cm
    back on tabletop: 96 uSec and 3 cm



    My program:

    on tabletop: 96 uSec and 3 cm
    ~12 in. above tabletop: 198 uSec and 6 cm
    back on tabletop: 198 uSec and 6 cm
    after reset on tabletop: 96 uSec and 3 cm
  • FranklinFranklin Posts: 4,747
    edited 2007-11-19 16:10
    Move_Robot:
      IF (cm <= 3 ) THEN
        GOSUB Forward
        edgeCtr = edgeCtr + 1
      ENDIF
    Forward:
      PULSOUT 12, 662
      PULSOUT 13, 850
      PAUSE 20
      RETURN
    

    As you can see here every time you move the robot (a small amount and many times to get across the table) you increment edgeCtr and you don't reset anywhere I can see in the loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • wellman.ronwellman.ron Posts: 16
    edited 2007-11-19 17:03
    thanks for your response, Stephen,

    what I want it to do is go forward across the table UNTIL the value of cm is greater than 3 cm, then increment edgeCtr from 0 to 1. Then the bot backs up and makes two ninety degree turns. It works correctly to this point. When I call Forward: again, and II expect it see the table at 3 cm and go forward until it is again looking over the tabletop edge and the value of cm is greater than 3 cm for a second time. Then I increment edgeCtr to 2 and I test to see if edgeCtr is greater than 1. Since it is, now the bot program should end.

    The problem is that my program is not getting correct results from the Ping))) device as to lapsed time and distance from the table in cm. As you can see from my previous message it freezes after the first change, and in any case doesn't display correct values. I use the exact code that pertains to PB2 as used in the Ping_Demo.bs2 program that I downloaded from the Parallax website. So the question here is "Why does Parallax's code work but mine doesn't when I lift the bot up into the air and then set it back onto the table?" I am not a skilled programmer, where is my logic faulty?

    ron
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-20 04:50
    It's very simple to prove that it's your move_robot code. Simply put a RETURN right after the Move_Robot: label and run your program while watching the values in the DEBUG window.
  • wellman.ronwellman.ron Posts: 16
    edited 2007-11-20 18:00
    thanks Mike! I am now 100% convinced that my subroutine is causing the problem, lol. I really liked seeing those numbers change as I raised and lowered the bot. I may have misunderstood Stephen's earlier suggestions, so I'll play around with my subroutine and hopefully resolve my problem. ron
Sign In or Register to comment.