Shop OBEX P1 Docs P2 Docs Learn Events
Porting PBASIC Boe-Bot code from BS2 to BS2px — Parallax Forums

Porting PBASIC Boe-Bot code from BS2 to BS2px

edited 2010-11-04 18:43 in Learn with BlocklyProp
BASIC Stamp upgrades are·NOT recommended for use with Stamps in Class kits and textbooks.

If you want to go through Stamps in Class material like What's a Microcontroller and Robotics with the Boe-Bot, use·the BASIC Stamp 2 included with the kit and avoid the temptation to upgrade.· Set aside·any money you saved on the kit over buying the parts indivudually for an upgrade in the future.· BASIC Stamp modules like the BASIC Stamp 2sx, 2p, 2pe, or 2px are·not recommended·for use with·Stamps in Class·kits.· Learn how to use the BASIC Stamp 2 on its own terms first, then upgrade later, and only if you really need to.· You'd be amazed at the projects you can accomplish with just the BASIC Stamp 2.· ·

Examples of what you·would have to do to every example program if you upgrade:

Robotics with the Boe-Bot is written for the BASIC Stamp 2.· If you are going to replace the BASIC Stamp 2 with a faster BASIC Stamp, like the BASIC Stamp 2sx, 2p or 2px, you'll need to update commands in the example programs that involve time measurements.· For example, let's say you replace the BASIC Stamp 2 with the BASIC Stamp 2px.· The following adjustments have to be made for timing.

·- Multiply all FREQOUT commands' Duration arguments by 6
·- Divide all FREQOUT commands' Freq arguments by 6
·- Multiply all PULSOUT commands' Duration arguments by 2.5
·-·Multiply all RCTIME command results by·0.375
·- Multiply all PULSIN command results by 0.4

To multiply by 2.5, you can use */640, and multiplying by 2.66 is about */ 682.· (*/ multiplies by a number of 256ths.)

Here are some examples of quick updates to time sensitive commands found in some Robotics with the Boe-Bot program examples.

FREQOUT 4, 1000, 3000 -> FREQOUT 4, 1000*6, 3000/6·· ' Piezospeaker
FREQOUT 8, 1, 38500 -> FREQOUT 8, 1*6, 38500/6········ ' IR detection

PULSOUT 12, 650 -> PULSOUT 12, 650*/640················· ' R servo forward
PULSOUT 13, 850 -> POLSOUT 13, 850*/640················· ' L servo forward

RCTIME 6, 1, time -> RCTIME 6, 1, time : time = time·** 24576

PULSIN 15, time· -> PULSIN 15,·time : time = time ** 26124

Three code examples are attached that demonstrate this "quick fix" for PBASIC Boe-Bot code examples for the BASIC Stamp 2px.· If you are using the BASIC Stamp 2p or 2sx, you'll need to look up the speed differences for FREQOUT, RCTIME, and PULSOUT in the BASIC Stamp manual and figure out how to adjust your code.·

You can also customize your code to work a variety of different BASIC Stamp modules with conditional compilation directives.· To get started with conditional compilation, open up the BASIC Stamp Editor's Help feature and look for #IF in the index.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay

Education Department
Parallax, Inc.

Post Edited (Andy Lindsay (Parallax)) : 12/10/2008 2:21:35 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-07 02:05
    You have to methodically go through the Roaming with Ping and follow Andy's instructions. He's given examples of what has to be done. Probably you've missed one or more statements that need to be changed.

    If you replace the IR detector that comes with the BoeBot with the Sharp IR device, you'll have to change the IR routines completely.
  • MovieMakerMovieMaker Posts: 502
    edited 2008-12-07 02:58
    Well put Andy! Thanks, Mike. . . Happy Holidays~!

    Post Edited (MovieMaker) : 12/10/2008 1:57:54 AM GMT
  • MovieMakerMovieMaker Posts: 502
    edited 2008-12-07 03:03
    I just tried his code. All it does is make my boe-bot turn in circles and chase it's tail.

    Could be that something is wired wrong. Because MOST of the tests wind up the same way. The robot chases it's tail like a dog or the ping bracket just has a muscle spasm.

    :-(

    I am going to attach some code that does work. But it is only a start. Let me find it.


    We found out that I had a bad servo on my left wheel. It worked, but not correctly ie; the going around in circles like a dog.

    Post Edited (MovieMaker) : 12/9/2008 5:16:27 AM GMT
  • MovieMakerMovieMaker Posts: 502
    edited 2008-12-07 03:10
    Here it is. Notice all of the heart of it is missing. I have to figure that part out yet. The logical parts that determind wether to go right, left, forward, backward, etc. If you know something that would work, just let me know. I have tested all of the subroutines that are remarked out. They all work fine on this bot.

    When I change the code to match his, the robot acts really crazy or doesn't do much but just grunt.

    Post Edited (MovieMaker) : 12/7/2008 3:16:19 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-07 03:58
    You have to make the changes Andy showed in his message for it to work on a BS2px. I don't see where you made the changes.
  • MovieMakerMovieMaker Posts: 502
    edited 2008-12-07 17:33
    The code that I sent you is what works for me right now. If I undo the comments and make them work, each subroutine works. But, I have not got the middle part in place yet. I did not send you the code that I modified to match his. I guess that would have been useful too. sorry. Andy has sent me an email and think he is going to send me something that will make everything work fine.


    Thanks, Mike. You are always a big help. Hope you have a nice holiday.

    Post Edited (MovieMaker) : 12/7/2008 5:38:33 PM GMT
  • MovieMakerMovieMaker Posts: 502
    edited 2008-12-09 05:12
    Andy has updated the code and it now works.
  • edited 2008-12-09 20:08
    The code always worked, with one exception - I made a mistake in the RCTIME command example that is now corrected, and it was not related to the problems reported·in this thread.· That problem turned out to be a malfunctioning servo, which is why·MovieMaker's Boe-Bot robot always turned in circles.

    Also, for the instructions on centering your servos in the Robotics with the Boe-Bot text, it is crucial that you use the modification for the PULSOUT command when centering each servo.··See the first post in this thread for details.· The code adjustments have to be made to every example code in the book.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 12/9/2008 8:28:26 PM GMT
  • MovieMakerMovieMaker Posts: 502
    edited 2008-12-10 01:57
    Andy. You're Da Man!!! You too, Mike.

    And, Andy, God Bless Your Sales Manager.

    Everyone at Parallax is so wonderful to do business with and so helpful. Especially you.

    jumpin.gif

    Post Edited (MovieMaker) : 12/10/2008 2:15:42 AM GMT
  • mikeyjunomikeyjuno Posts: 15
    edited 2010-11-02 23:40
    " ' Robotics with the Boe-Bot - BoeBotForwardThreeSeconds.bs2
    ' Make the Boe-Bot roll forward for three seconds.
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    DEBUG "Program Running!"
    counter VAR Word
    FREQOUT 4, 2000, 3000 ' Signal program start/reset.
    FOR counter = 1 TO 122 ' Run servos for 3 seconds.
    PULSOUT 13, 850
    PULSOUT 12, 650
    PAUSE 20
    NEXT
    END"

    heres an easy bit of code from the robotics with boe-bot. all i did was switch the stamp to bs2p... what this code DOES in real life to the boebot is make the wheels both go the same directions in lil pulses and never stop.

    "' Robotics with the Boe-Bot - BoeBotForwardThreeSeconds.bs2
    ' Make the Boe-Bot roll forward for three seconds.
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    DEBUG "Program Running!"
    counter VAR Word
    FREQOUT 4, 334, 500 ' Signal program start/reset. div by 6
    FOR counter = 1 TO 122 ' Run servos for 3 seconds.
    PULSOUT 13, 2125
    PULSOUT 12, 1625 'both multiplied by 2.5
    PAUSE 20
    NEXT
    END
    "
    heres the same code altered with your conversion...what it does in real life now is constantly spin both wheels one forward one backward. effectivly spinning the bot in circles. did i do something wrong?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-03 08:07
    Did you recalibrate the servos? If you went through the adjustment procedure with the BS2 timing values, the servos will be set wrong. Try it again with the BS2p values.
  • mikeyjunomikeyjuno Posts: 15
    edited 2010-11-03 14:53
    what is the value for bs2p?

    and if i understand the process for bs2.
    make the wheels spin at a value of 750
    use screwdriver to turn the screw in the servor till the wheels stop

    EDIT:
    oops duh it should be 2.5 * 750 =1875 ill calibrate them to this and see if it works then
  • mikeyjunomikeyjuno Posts: 15
    edited 2010-11-03 15:18
    okay resetting them now fixed the wheel rotation in the right direction but it still doesnt stop after 3 seconds
  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-03 16:12
    You have to figure out the loop count to get it to stop when you want. The PULSOUT statements go for about 1.7ms + 1.3ms = 3ms total. If you add in the PAUSE time, that's 3ms + 20ms = 23ms. The loop count is 122, so that's a total execution time of roughly 2.8s, not quite 3 seconds. The actual statements take much less time to execute, maybe 1ms max. per loop. If your program isn't behaving that way, there must be something else going on.
  • mikeyjunomikeyjuno Posts: 15
    edited 2010-11-04 17:23
    tried this .
    i set the switch on the boebot to position 1 and ran the program. i have led's going from 12 and 13 through a resistor to the ground just to see if wheels are "high/on". the LED's do infact stay on for 3ish seconds then turn off. but in position 2 the wheels just keep spinning in little bursts. so im wondering what could be causing this difference in position 1 and 2. maybe my batteries are going out by now?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-04 18:43
    Weak batteries is one of the main reasons for the kind of behavior you're describing.
Sign In or Register to comment.