Shop OBEX P1 Docs P2 Docs Learn Events
methods? — Parallax Forums

methods?

CodeGuruCodeGuru Posts: 2
edited 2005-10-18 11:14 in BASIC Stamp
I take Computer science in school and we work with Java.

Well what I am wondering about is can you make and recall back to methods?
Like you have a method to make a left turn, you know just so you don't have repetitive code.

Anyone know?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-17 01:26
    Lookup GOSUB in the manual. PBASIC does not use local variables or pass parameters -- everything is global. If Java is your choice, we do have a controller called the Javelin that might just be what you're looking for.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • CodeGuruCodeGuru Posts: 2
    edited 2005-10-18 03:02
    Thanks a lot, I found it.

    Now I ran into a new problem...
    I made this code while also looking in the manual, and the code looks great.

    "Left:
    FOR counter = 0 TO 70
    PULSOUT 12, 750 - counter
    PULSOUT 13, 750 - counter
    NEXT

    FOR counter = 70 TO 0
    PULSOUT 12, 750 - counter
    PULSOUT 13, 750 - counter
    NEXT
    PAUSE 100
    RETURN

    Right:
    FOR counter = 0 TO 70
    PULSOUT 12, 750 + counter
    PULSOUT 13, 750 + counter
    NEXT

    FOR counter = 70 TO 0
    PULSOUT 12, 750 + counter
    PULSOUT 13, 750 + counter
    NEXT
    PAUSE 100
    RETURN

    Forward:
    FOR counter = 0 TO 100
    PULSOUT 12, 750 - counter
    PULSOUT 13, 750 + counter
    NEXT

    FOR counter = 1 TO 100
    PULSOUT 12, 650
    PULSOUT 13, 850
    NEXT

    FOR counter = 100 TO 0
    PULSOUT 12, 750 - counter
    PULSOUT 13, 750 + counter
    NEXT
    PAUSE 100
    RETURN"

    The Problem is that the left turn works fine; the servos turn and stop when told. But the forward and Right do a big jerk at the end (like they go in reverse for a split second)
    I don’t know why this is happening, because the code for left and right are exactly the same besides a few "+"s and "-"s.

    Any one else have this problem?
  • BeanBean Posts: 8,129
    edited 2005-10-18 11:14
    The servos need some time to "process" the movement.

    You need to put "PAUSE 20" inside each of your FOR...NEXT loops.

    Like this:
    FOR counter = 0 TO 70
    PULSOUT 12, 750 - counter
    PULSOUT 13, 750 - counter
    PAUSE 20
    NEXT

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available now... SX-Video OSD module $59.95 www.sxvm.com

    "Save your money. Pay with cash."
    ·
Sign In or Register to comment.