Shop OBEX P1 Docs P2 Docs Learn Events
rc car — Parallax Forums

rc car

invad8erinvad8er Posts: 14
edited 2008-11-18 12:48 in General Discussion
hello,

i need to ask for some help with a project
I was needing to use a computer to control an rc car.

so far i have the wiring working.
I just don't know how to program it
640 x 480 - 36K
640 x 480 - 39K
640 x 480 - 32K

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-11-08 02:54
    I guess your first task is to figure out what you want it to do then break that down into steps and figure out what the computer needs to do to accomplish that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • invad8erinvad8er Posts: 14
    edited 2008-11-08 03:08
    well i was going to just need basic rc functions
    but using the debug terminal as the input
  • SRLMSRLM Posts: 5,045
    edited 2008-11-08 03:44
    Take a look at the code I posted here for ideas. It controls a BOE-BOT, but, if you take out the RF link stuff, then the code does essentially what you want.
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2008-11-08 16:32
    If you need a place to start, get this book (there are two volumes, you want the first):

    The Microcontroller Application Cookbook (Microcontroller Application Cookbooks) (Paperback)
    by Matt Gilliland (Author)

    Its a great book that breaks down input/output/control very and makes it very easy because the code examples are very brief. Even better for you, they are written in PBASIC which is your stamp's language. Of special interest to you should be the details on circuit protection.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thomas Talbot, MD
    Gunpowder, MD, USA
  • invad8erinvad8er Posts: 14
    edited 2008-11-10 00:02
    the books $30.00

    I tried a code (but did not work) the debug would only accept 02

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    direction VAR Word

    DEBUG "enter direction ",CR
    DEBUGIN DEC direction
    DO
    IF (direction = 02) THEN
    HIGH 0
    HIGH 2
    IF (direction = 01) THEN
    HIGH 0
    HIGH 3
    IF (direction = 00) THEN
    LOW 0
    IF (direction = 1) THEN
    HIGH 1
    IF (direction = 0) THEN
    HIGH 0
    IF (direction = 11) THEN
    HIGH 1
    HIGH 2
    IF (direction = 12) THEN
    HIGH 1
    HIGH 3
    PAUSE 1000


    ENDIF
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    ENDIF


    END
    LOOP
  • sylvie369sylvie369 Posts: 1,622
    edited 2008-11-10 01:09
    You'll want to use the SELECT...CASE structure instead of all of those nested IF-THENs. It'll clean things up considerably.
    Take a look in the Basic Stamp Manual online.
  • invad8erinvad8er Posts: 14
    edited 2008-11-15 01:51
    well i could not get select-case structure to work but i did get elseif to work
    (program still has the problems)
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    direction VAR Word


    DO
    DEBUG "enter direction ",CR
    DEBUGIN DEC direction


    IF (direction = 02) THEN
    HIGH 0
    HIGH 2
    ELSEIF ( direction = 03) THEN
    HIGH 0
    HIGH 3
    ELSEIF (direction = 00) THEN
    LOW 0
    ELSEIF (direction = 1) THEN
    HIGH 1
    ELSEIF (direction = 0) THEN
    HIGH 0
    ELSEIF (direction = 11) THEN
    HIGH 1
    HIGH 2
    ELSEIF (direction = 12) THEN
    HIGH 1
    HIGH 3
    PAUSE 1000
    DEBUGIN direction : direction =00


    ENDIF


    END
    LOOP
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-11-15 02:46
    You have listed seven different evaluations for the variable "direction". Since the value 0 is the same as 00 then you are really only evaluating six. "ELSEIF (direction = 0) THEN" never gets evaluated because "ELSEIF (direction = 00) THEN" is identical logic. This IF-THEN-ELSEIF structure will find the first (and only the first) TRUE statement and execute the code block for that statement only.
    The SELECT-CASE should work for you as well. A common mistake is using the "=" between CASE and the variable
    you are evaluating. This is the syntax:

    SELECT direction
    CASE 0 THEN ' don't use equal sign
    HIGH 0
    CASE 1 THEN
    HIGH 1
    .
    .
    .
    ENDSELECT

    · Also, your program won't loop because you have an END statement within your loop structure.· Did you mean to end your IF-THEN-ELSEIF structure with this?· You should remove END.

    Post Edited (Mikerocontroller) : 11/15/2008 4:00:37 AM GMT
  • invad8erinvad8er Posts: 14
    edited 2008-11-16 23:12
    ok that cleaned it up alot and the rest of the the selection works
    but the program only excepts one direction then has to be reset-any ideas?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    direction VAR Word
    DO
    DEBUG "enter direction ",CR
    DEBUGIN DEC direction
    SELECT direction
    CASE 0
    HIGH 0
    CASE 1
    HIGH 1
    CASE 2
    HIGH 2
    CASE 3
    HIGH 3
    CASE 4
    HIGH 4
    ENDSELECT
    LOOP
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-11-17 02:58
    · Are you controlling motors or servos? Please post schematics or more detailed info.· Your code is sound but it looks like it won't suit your purpose.

    Also, the pins will stay·HIGH once you set them.· If your program doesen't change their state they will stay that way.

    Don't drive any kind of motor directly from the Stamp pins.

    Post Edited (Mikerocontroller) : 11/17/2008 3:16:32 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2008-11-17 05:16
    Also note that if you are posting formatted code, it's best to use the code option in order to keep the format. It's difficult to quickly read unformatted code.
  • invad8erinvad8er Posts: 14
    edited 2008-11-17 21:46
    the stamp is hooked to a RC controller
    640 x 424 - 46K
    640 x 480 - 51K
    653 x 400 - 26K
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-11-18 03:19
    · You really should consider getting some kind of motor controller for this project.·· Your·setup right now has pin 3 of the Stamp controlling the emitter current of all those transistors.· That will most definitely damage your microcontroller .·
  • invad8erinvad8er Posts: 14
    edited 2008-11-18 12:48
    i probably should of used a better diagram

    i had used relays
    5v .002a
Sign In or Register to comment.