Shop OBEX P1 Docs P2 Docs Learn Events
New here - Just a few things — Parallax Forums

New here - Just a few things

AdamEAdamE Posts: 11
edited 2006-04-26 22:22 in Learn with BlocklyProp
Just thought I'd introduce myself and explain my situation for starters;

My names Adam, Ive just been selected to join the robotics team at my school. The main assignment is to program a Boe-Bot to travel through a maze and reach the endpoint within a time limit, the fastest one winning ofcourse.

As far as my programming experience goes, Im only 16 but I've been programming since I was about 9 years old. Im currently using Darkbasic Pro, www.darkbasicpro.com, an excellent version of BASIC.

Ive pretty much mastered the language (I know, there is no mastering a language, but you get what I mean) and can create almost anything my mind thnks up.

Ive just installed the main BASIC Stamp compiler/editor, and Im currently looking over some basic code snippets and methods of doing things. So far the language looks extremely similar to DarkBASIC's language (ofcourse they're both basic so that makes complete sense), so getting used to how things work shouldnt be too hard. My main problem is figuring out how it recievs the information from the Boe-Bot (how to make the Boe-Bot move/turn/stop, and how to obtain the distance to the walls infront, to the left, and to the right of the bot using the infra-red raycasting system). But I've been doing some research and it looks relatively simple, sending a certain charge to Pins will turn them ina certain direction at a certain speed is what I've been able to figure out so far.

Anyways, the due date for this thing is mid-May and I'm (as far as I know) the only programmer on the project. I've figured out all of the artificial intelligence needed to make this thing work and Im also working on creating a virtual simulation of the bot using the AI theories with Darkbasic Pro, just to see if there are any major problems I need to correct.

Im not usually the type to ask for pure code, more like asking for a hint in the right direction, but my deadline is coming in fast and Ive still got to balanace school work and other things. Ill still be constantly researching how this thing works for pretty much the rest of the weekend, (well not Sunday as much as Im going to a wedding), but I was just wondering if anyone had some useful links to other tutorials, common methods for doing the usual tasks a Boe-Bot requires, or other hints.

Hope to be showing some sort of progress soon,
- Adam smilewinkgrin.gif (jeez there aren't any good emoticons on here are there :P)

Comments

  • MikeKMikeK Posts: 118
    edited 2006-04-22 23:36
    Have you read Robotics with the BOE-BOT? It's a pretty good text.
    http://www.parallax.com/dl/docs/books/edu/Roboticsv2_2.pdf

    Mike
  • AdamEAdamE Posts: 11
    edited 2006-04-22 23:51
    Thanks Ill look into it, mainly focusing on getting the Stamp to read that it's plugged in, for some reason its not responding correctly to the code sends.
  • MikeKMikeK Posts: 118
    edited 2006-04-23 02:35
    In the printed copy that I've got, Appendix A has connection troubleshooting.
    One of the other Appendixes has information on running mazes of various types.
    Mike

    Post Edited (MikeK) : 4/23/2006 4:32:23 AM GMT
  • AdamEAdamE Posts: 11
    edited 2006-04-25 23:25
    I just thought I'd post a bit of my progress on here, not sure why :P, perhaps if anyone notices any dumb methods I'm currently using to accomplish something they could point it out.

    Im still working on getting the hang of the language but Im pretty confident Ill be able to finish this thing in time for the competition.

    The current code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    'Define Main Variables
    t VAR Byte
    dist VAR Byte
    data_ln CON 3
    clk_ln CON 7
    
    'Define Main Program Loop (Parent)
    main:
    
    'Begin Main Program Loop
    DO
    
      'Check the distance between bot and wall.
      'If the bot is close (dist < 190), then stop and play sound.
      'Otherwise, move forward (call the move sub)
      IF dist < 190 THEN GOSUB move ELSE GOSUB sound
    
    'Loop back to the top
    LOOP
    
    'Define Move Subdirectory
    move:
    
      'Turn the left and right wheels with a pause of 40
      PULSOUT 14,900
      PULSOUT 15,450
      PAUSE 40
      'Get the distance between the robot and the wall
      GOSUB detect
    
    'Define Sound Subdirectory
    sound:
    
      'Play a sound
      PULSOUT 14,900
      PULSOUT 15,900
      PAUSE 40
    
    'Define the IR Ratcasting subdirectory
    detect:
    
      'Standard IR Raycasting method:
      HIGH clk_ln
      PAUSE 3
      LOW clk_ln
    
      FOR t = 1 TO 70
        PAUSE 3
        IF IN5 = 1 THEN GOSUB jump
      NEXT
    
    'Define the jump subdirectory
    jump:
    
      'Standard Distance retrieval/display
      SHIFTIN data_ln,clk_ln,2,[noparse][[/noparse]dist\8]
      DEBUG "Distance = ",DEC dist,CR
      PAUSE 40
      GOTO main
    
    



    I can see a few places where it could be made more efficient but Im not worrying too much about that as of right now. I only have a few things left to figure out how to accomplish and then Ill be pretty much set for programming this thing, mainly being;

    - Traveling a specific distance (Im looking into how to use the wheel's circumference and speed of travel for this. Though finding the speed the robot is moving at is proving to be a bit daunting.)

    - Turning a specific angle (I realize this and the previous point is fairly hard to get precisely, but Im hoping Ill be able to get it close enough that the turn is relatively 90 degrees to the right or left.)

    - Non-Programming wise I need to get the measurements of the maze sections in order to figure out the distance I need to move and how big the maze is in comparison with the robot.

    Other than that Im pretty much set. I hope nobody sees this as a question (though ideas are welcomed), Im just posting my progress in hopes of it possibly enlightening someone else that comes to the forums for help, as well as trying to establish myself a bit on the boards.

    Special thanks to Mike for giving me a point in the right direction for the hardware problem I fixed it in no time. Thanks Mike.
  • SSteveSSteve Posts: 808
    edited 2006-04-26 01:13
    Here's a few random observations.

    data_ln·CON·3
    clk_ln·CON·7


    I'm not sure if it's significant (I'm still new to this myself), but in all the code I've seen I/O pins are defined like this:

    data_ln·PIN·3
    clk_ln·PIN·7


    You don't have any RETURNs for your GOSUBs. That will get you into trouble.

    In your comments you're using the word "subdirectory" when you mean "subroutine". It won't affect the code, but...

    The code in your "move" subroutine is sending data to the same pins as the code in your "sound" subroutine. One of them must be wrong. That's a good reason to use names for your pins instead of numbers.

    For making sound you probably want to use FREQOUT instead of PULSOUT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • AdamEAdamE Posts: 11
    edited 2006-04-26 12:22
    Woops, I put my experimental source code up by accident. The reaason I had movement in two subroutines was because previously I had it beeping but I switched it to turn and dodge the wall, mustve forgotten to change the comments.

    I only though returns were necassary for GOTO's, as GOSUBs return to where they were called automatically.

    Thanks for the correctio with the subroutine, Ill fix it up tonight.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-04-26 13:36
    You probably already know this, but it can be repeated:

    The GOSUB's do "return to where they're called from", but only do that when they hit the RETURN keyword. There's nothing in the next GOSUB target label that says "RETURN from previous GOSUB when you get to this line".

    And GOTO'S have no "RETURN" statement.

    What's going on is, when you hit a GOSUB, the 'return address' of the code location after the "GOSUB" keyword in the program is 'pushed' on a 'return stack'. The program then resumes execution at the GOSUB target label.

    When the program hits a 'RETURN' statement, the 'return address' is 'popped' off the 'return stack', and is used as the next location to execute. This "GOSUB--RETURN" cycle is critically important to how software works.

    Now, a "GOTO" doesn't 'push' a 'return address', it just redirects execution directly to the GOTO target label. If overused, this leads to something called "spagetti-code", where the process flow bounces all over your source. This can be very difficult to debug, or even get correct in the first place.

    Oh, and if you DO try to "RETURN" without having done a 'GOSUB' first, then there IS no 'return-address' sitting on the 'return stack'.· The BS2 resets itself in this case.
  • AdamEAdamE Posts: 11
    edited 2006-04-26 19:49
    Is there any way to define a function in Stamp? In DBP you'd do something like;

    
    FUNCTION MyFunc(A#,B#)
    
    C# = A# + B#
    
    ENDFUNCTION C#
    
    
    



    And then to call it;

    
    D# = MyFunc(5,10)
    
    
    



    Which would make D# equal 15. Is there anything similar to this in Stamp because Im much more comfortable with using functions than subroutines.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-04-26 22:22
    There are really no functions or subroutines as you're thinking of them. The GOSUB/RETURN does work as a parameterless subroutine call. You have to use global variables (they're all global) to pass values and return a result. There's also the "scratch RAM" in some models of Stamps and the READ/WRITE commands which store information in the same (flash) memory where the program is stored. The flash memory has limited rewrite capability (100,000 to 1,000,000 times) and shouldn't be used for frequently changing values.
Sign In or Register to comment.