Shop OBEX P1 Docs P2 Docs Learn Events
help to shorten code — Parallax Forums

help to shorten code

ArchiverArchiver Posts: 46,084
edited 2003-11-03 00:02 in General Discussion
I was wondering if you could help me shorten the code and tell me how how to
make it loop a certain amount of times. I have tried several ways too but all of
them didnt work.
The code is to control rudders on a model airplane.

here is the code.


resetb2: b2=100
servo: pulsout 6,b2
pause 20
let b2=b2+2
if b2>600 then resetb3
pause 5000

resetb3: b3=600
pulsout 6,b3
let b3=b3-2
if b3<100 then resetb2


Do you Yahoo!?
Exclusive Video Premiere - Britney Spears

[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-10-27 06:26
    From: "Kyle Cooper" <crazykurby@y...>

    > I was wondering if you could help me shorten the code and tell
    > me how how to make it loop a certain amount of times. I have
    > tried several ways too but all of them didnt work. The code is
    > to control rudders on a model airplane.

    Actually, Kyle, I can't understand exactly what sequence of actions you're
    trying to create. Maybe you can explain a little more. Here's what I get
    from the code right now:

    >
    > resetb2: b2=100
    > servo: pulsout 6,b2
    > pause 20
    > let b2=b2+2
    > if b2>600 then resetb3
    > pause 5000

    This loop will never jump to resetB3, because it can't reach 600. B2 is a
    byte, so its highest value is 255. It appears you want to wait five seconds
    after pulsing pin six and then... then pulse pin six again.

    Are you trying to put out increasingly higher pulse positions until they
    reach 600, and then decrease them back to 100? If so, you must be careful.
    Not many servos will accept a pulse width in that range. If your Stamp is a
    BS1 that is 1 millisecond to 6 milliseconds. If you have a BS2, the range
    will be 0.2 milliseconds to 1.2 milliseconds. A typical hobby servo will
    accept pulses between one and two milliseconds. Check your arithmetic and
    make sure you know how long a pulse you're trying to emit.

    I said that last snippet of code would not jump to "resetB3" because the
    test for B2>600 can never succeed, but it will "fall through" after that
    five second pause. Then we have:

    >
    > resetb3: b3=600
    > pulsout 6,b3
    > let b3=b3-2
    > if b3<100 then resetb2
    >
    and again B3 cannot equal 600. Offhand, I think the assignment B3=600 will
    result in B3 holding the value 88. That means the test b3<100 will succeed
    and you're back to the top of the routine.

    May I suggest a coding technique? Use FOR loops to repeat your pulses. One
    to step up from the shortest pulse and another to step back down from the
    longest pulse. Don't use GOTO statements unless you absolutely must. It is
    very difficult to keep track of our own code if we let it jump around from
    here to there.

    Moving from a short pulse to a long one and back again would look like this
    using FOR loops.

    'First some names so we can keep track of what our numbers mean
    MinPulse CON 100
    MaxPulse CON 200
    RudderServoPin CON 6

    Waggles CON 3

    PulseDuration VAR Byte
    WaggleCount VAR Byte

    'Then an outer loop to control how many times we waggle the rudder
    FOR WaggleCount=1 TO Waggles STEP 2

    'First, we move the rudder servo to a longer pulse width
    FOR PulseDuration=MinPulse TO MaxPulse
    PULSOUT RudderServoPin, PulseDuration
    PAUSE 20
    NEXT

    'Now we move the rudder servo back to shorter pulse widths
    FOR PulseDuration=MaxPulse TO MinPulse STEP 2
    PULSOUT RudderServoPin, PulseDuration
    PAUSE 20
    NEXT
    'That completes one waggle. Now repeat as required.

    NEXT

    Incidentally, as a pilot the notion of increasing my rudder deflection more
    and more over a period of twenty minutes worries me. That's what your
    original code would do with that five second pause between each step. I
    would expect to auger into the ground after the first minute or so.

    If you want to waggle the tail, I'd remove that five second pause. With the
    minimum 20 millisecond pause between each pulse to the servo, that FOR loop
    above will spend about one second moving the rudder one way and then one
    second back the other. I figured that by multiplying the fifty steps times
    20 milliseconds. That's 1,000 milliseconds, or one second. That won't give
    your airplane enough time to roll inverted and dive into the ground while
    it's at full rudder in either direction.

    Notice that I used a range from 100 to 200. That's about right for a BS1 and
    a standard servo, but "about right" is not good enough. You'll burn out a
    servo that way. You need to find out how long a pulse will work with your
    servo. Start in the middle and work to changes that are greater and greater
    until you can see the servo is reaching it's limit. You might write
    something like:

    Center CON 150
    Delta CON 10
    Cnt VAR Byte

    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center-Delta
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center+Delta
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center
    PAUSE 20
    NEXT
    END

    This will center the servo, move it one way, and then the other. That's how
    I test a new servo. You have to guess about the first value for "Center". On
    a BS2 I use 750 which gives a pulse length of 1.5 milliseconds. On a BS1,
    150 gives that same pulse length.

    Run this program. Watch where the servo moves. Change the value of Center
    until the rudder is at the center position after the last movement ends.

    Now change the value of Delta. Try perhaps 20 or 25, and run the program
    again. Keep increasing Delta until the servo is near it's limits. If the
    servo reaches its limit one way or the other before the rudder is at the
    position you want to reach, you will have to adjust the control horn on the
    servo. That's too long a procedure to go into unless you need to know.

    Hope all this helps. Read the Stamp manual on FOR loops. They help a lot.

    Gary
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-27 13:24
    Thank you very much Gary this is my first project with servos

    "Gary W. Sims" <simsgw@c...> wrote:From: "Kyle Cooper"

    > I was wondering if you could help me shorten the code and tell
    > me how how to make it loop a certain amount of times. I have
    > tried several ways too but all of them didnt work. The code is
    > to control rudders on a model airplane.

    Actually, Kyle, I can't understand exactly what sequence of actions you're
    trying to create. Maybe you can explain a little more. Here's what I get
    from the code right now:

    >
    > resetb2: b2=100
    > servo: pulsout 6,b2
    > pause 20
    > let b2=b2+2
    > if b2>600 then resetb3
    > pause 5000

    This loop will never jump to resetB3, because it can't reach 600. B2 is a
    byte, so its highest value is 255. It appears you want to wait five seconds
    after pulsing pin six and then... then pulse pin six again.

    Are you trying to put out increasingly higher pulse positions until they
    reach 600, and then decrease them back to 100? If so, you must be careful.
    Not many servos will accept a pulse width in that range. If your Stamp is a
    BS1 that is 1 millisecond to 6 milliseconds. If you have a BS2, the range
    will be 0.2 milliseconds to 1.2 milliseconds. A typical hobby servo will
    accept pulses between one and two milliseconds. Check your arithmetic and
    make sure you know how long a pulse you're trying to emit.

    I said that last snippet of code would not jump to "resetB3" because the
    test for B2>600 can never succeed, but it will "fall through" after that
    five second pause. Then we have:

    >
    > resetb3: b3=600
    > pulsout 6,b3
    > let b3=b3-2
    > if b3<100 then resetb2
    >
    and again B3 cannot equal 600. Offhand, I think the assignment B3=600 will
    result in B3 holding the value 88. That means the test b3<100 will succeed
    and you're back to the top of the routine.

    May I suggest a coding technique? Use FOR loops to repeat your pulses. One
    to step up from the shortest pulse and another to step back down from the
    longest pulse. Don't use GOTO statements unless you absolutely must. It is
    very difficult to keep track of our own code if we let it jump around from
    here to there.

    Moving from a short pulse to a long one and back again would look like this
    using FOR loops.

    'First some names so we can keep track of what our numbers mean
    MinPulse CON 100
    MaxPulse CON 200
    RudderServoPin CON 6

    Waggles CON 3

    PulseDuration VAR Byte
    WaggleCount VAR Byte

    'Then an outer loop to control how many times we waggle the rudder
    FOR WaggleCount=1 TO Waggles STEP 2

    'First, we move the rudder servo to a longer pulse width
    FOR PulseDuration=MinPulse TO MaxPulse
    PULSOUT RudderServoPin, PulseDuration
    PAUSE 20
    NEXT

    'Now we move the rudder servo back to shorter pulse widths
    FOR PulseDuration=MaxPulse TO MinPulse STEP 2
    PULSOUT RudderServoPin, PulseDuration
    PAUSE 20
    NEXT
    'That completes one waggle. Now repeat as required.

    NEXT

    Incidentally, as a pilot the notion of increasing my rudder deflection more
    and more over a period of twenty minutes worries me. That's what your
    original code would do with that five second pause between each step. I
    would expect to auger into the ground after the first minute or so.

    If you want to waggle the tail, I'd remove that five second pause. With the
    minimum 20 millisecond pause between each pulse to the servo, that FOR loop
    above will spend about one second moving the rudder one way and then one
    second back the other. I figured that by multiplying the fifty steps times
    20 milliseconds. That's 1,000 milliseconds, or one second. That won't give
    your airplane enough time to roll inverted and dive into the ground while
    it's at full rudder in either direction.

    Notice that I used a range from 100 to 200. That's about right for a BS1 and
    a standard servo, but "about right" is not good enough. You'll burn out a
    servo that way. You need to find out how long a pulse will work with your
    servo. Start in the middle and work to changes that are greater and greater
    until you can see the servo is reaching it's limit. You might write
    something like:

    Center CON 150
    Delta CON 10
    Cnt VAR Byte

    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center-Delta
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center+Delta
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center
    PAUSE 20
    NEXT
    END

    This will center the servo, move it one way, and then the other. That's how
    I test a new servo. You have to guess about the first value for "Center". On
    a BS2 I use 750 which gives a pulse length of 1.5 milliseconds. On a BS1,
    150 gives that same pulse length.

    Run this program. Watch where the servo moves. Change the value of Center
    until the rudder is at the center position after the last movement ends.

    Now change the value of Delta. Try perhaps 20 or 25, and run the program
    again. Keep increasing Delta until the servo is near it's limits. If the
    servo reaches its limit one way or the other before the rudder is at the
    position you want to reach, you will have to adjust the control horn on the
    servo. That's too long a procedure to go into unless you need to know.

    Hope all this helps. Read the Stamp manual on FOR loops. They help a lot.

    Gary



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/




    Do you Yahoo!?
    Exclusive Video Premiere - Britney Spears

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-28 01:24
    From: "Kyle Cooper" <crazykurby@y...>

    > Thank you very much Gary this is my first project with servos
    >
    You're welcome, Kyle. Let us know if you need more help.

    Gary
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-28 01:59
    What does the CON stand for? after I typed the program it put CON as an error. I
    looked through the book but probably missed it.

    "Gary W. Sims" <simsgw@c...> wrote:From: "Kyle Cooper"

    > Thank you very much Gary this is my first project with servos
    >
    You're welcome, Kyle. Let us know if you need more help.

    Gary


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/




    Do you Yahoo!?
    Exclusive Video Premiere - Britney Spears

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-28 02:33
    From: "Kyle Cooper" <crazykurby@y...>


    > What does the CON stand for? after I typed the
    > program it put CON as an error.
    >
    No that was my mistake, Kyle. You clearly are using the BS1, and I did not
    realize the editor for the BS1 defines constants in a different way. (I have
    it on hand, but haven't used it yet.) CON and VAR are different ways to
    define symbols in the later version of the editor. For your editor, make
    that code read like this:

    symbol MinPulse=100
    symbol MaxPulse=200
    symbol RudderServoPin=6

    symbol Waggles=3

    symbol PulseDuration=B0
    symbol WaggleCount=B1

    The rest should compile correctly, though I can't be sure without shutting
    down my system and starting up the first-version editor from a floppy. I'll
    try it later tonight and let you know if I made any other mistakes.

    Gary
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-28 02:38
    That will work I had the word symbol floating around in my head. thanks again
    Gary

    "Gary W. Sims" <simsgw@c...> wrote:From: "Kyle Cooper"


    > What does the CON stand for? after I typed the
    > program it put CON as an error.
    >
    No that was my mistake, Kyle. You clearly are using the BS1, and I did not
    realize the editor for the BS1 defines constants in a different way. (I have
    it on hand, but haven't used it yet.) CON and VAR are different ways to
    define symbols in the later version of the editor. For your editor, make
    that code read like this:

    symbol MinPulse=100
    symbol MaxPulse=200
    symbol RudderServoPin=6

    symbol Waggles=3

    symbol PulseDuration=B0
    symbol WaggleCount=B1

    The rest should compile correctly, though I can't be sure without shutting
    down my system and starting up the first-version editor from a floppy. I'll
    try it later tonight and let you know if I made any other mistakes.

    Gary



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/




    Do you Yahoo!?
    Exclusive Video Premiere - Britney Spears

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-02 03:21
    Sorry for asking about this problem now (been busy last few weeks), but I
    couldn't get the code to repeat it. The motor only goes through the program once
    and stops could somebody help or tell me what I'm doing wrong. : )

    "Gary W. Sims" <simsgw@c...> wrote:From: "Kyle Cooper"

    > I was wondering if you could help me shorten the code and tell
    > me how how to make it loop a certain amount of times. I have
    > tried several ways too but all of them didnt work. The code is
    > to control rudders on a model airplane.

    Actually, Kyle, I can't understand exactly what sequence of actions you're
    trying to create. Maybe you can explain a little more. Here's what I get
    from the code right now:

    >
    > resetb2: b2=100
    > servo: pulsout 6,b2
    > pause 20
    > let b2=b2+2
    > if b2>600 then resetb3
    > pause 5000

    This loop will never jump to resetB3, because it can't reach 600. B2 is a
    byte, so its highest value is 255. It appears you want to wait five seconds
    after pulsing pin six and then... then pulse pin six again.

    Are you trying to put out increasingly higher pulse positions until they
    reach 600, and then decrease them back to 100? If so, you must be careful.
    Not many servos will accept a pulse width in that range. If your Stamp is a
    BS1 that is 1 millisecond to 6 milliseconds. If you have a BS2, the range
    will be 0.2 milliseconds to 1.2 milliseconds. A typical hobby servo will
    accept pulses between one and two milliseconds. Check your arithmetic and
    make sure you know how long a pulse you're trying to emit.

    I said that last snippet of code would not jump to "resetB3" because the
    test for B2>600 can never succeed, but it will "fall through" after that
    five second pause. Then we have:

    >
    > resetb3: b3=600
    > pulsout 6,b3
    > let b3=b3-2
    > if b3<100 then resetb2
    >
    and again B3 cannot equal 600. Offhand, I think the assignment B3=600 will
    result in B3 holding the value 88. That means the test b3<100 will succeed
    and you're back to the top of the routine.

    May I suggest a coding technique? Use FOR loops to repeat your pulses. One
    to step up from the shortest pulse and another to step back down from the
    longest pulse. Don't use GOTO statements unless you absolutely must. It is
    very difficult to keep track of our own code if we let it jump around from
    here to there.

    Moving from a short pulse to a long one and back again would look like this
    using FOR loops.

    'First some names so we can keep track of what our numbers mean
    MinPulse CON 100
    MaxPulse CON 200
    RudderServoPin CON 6

    Waggles CON 3

    PulseDuration VAR Byte
    WaggleCount VAR Byte

    'Then an outer loop to control how many times we waggle the rudder
    FOR WaggleCount=1 TO Waggles STEP 2

    'First, we move the rudder servo to a longer pulse width
    FOR PulseDuration=MinPulse TO MaxPulse
    PULSOUT RudderServoPin, PulseDuration
    PAUSE 20
    NEXT

    'Now we move the rudder servo back to shorter pulse widths
    FOR PulseDuration=MaxPulse TO MinPulse STEP 2
    PULSOUT RudderServoPin, PulseDuration
    PAUSE 20
    NEXT
    'That completes one waggle. Now repeat as required.

    NEXT

    Incidentally, as a pilot the notion of increasing my rudder deflection more
    and more over a period of twenty minutes worries me. That's what your
    original code would do with that five second pause between each step. I
    would expect to auger into the ground after the first minute or so.

    If you want to waggle the tail, I'd remove that five second pause. With the
    minimum 20 millisecond pause between each pulse to the servo, that FOR loop
    above will spend about one second moving the rudder one way and then one
    second back the other. I figured that by multiplying the fifty steps times
    20 milliseconds. That's 1,000 milliseconds, or one second. That won't give
    your airplane enough time to roll inverted and dive into the ground while
    it's at full rudder in either direction.

    Notice that I used a range from 100 to 200. That's about right for a BS1 and
    a standard servo, but "about right" is not good enough. You'll burn out a
    servo that way. You need to find out how long a pulse will work with your
    servo. Start in the middle and work to changes that are greater and greater
    until you can see the servo is reaching it's limit. You might write
    something like:

    Center CON 150
    Delta CON 10
    Cnt VAR Byte

    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center-Delta
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center+Delta
    PAUSE 20
    NEXT
    PAUSE 1000
    FOR Cnt=1 to 20
    PULSOUT RudderServoPin,Center
    PAUSE 20
    NEXT
    END

    This will center the servo, move it one way, and then the other. That's how
    I test a new servo. You have to guess about the first value for "Center". On
    a BS2 I use 750 which gives a pulse length of 1.5 milliseconds. On a BS1,
    150 gives that same pulse length.

    Run this program. Watch where the servo moves. Change the value of Center
    until the rudder is at the center position after the last movement ends.

    Now change the value of Delta. Try perhaps 20 or 25, and run the program
    again. Keep increasing Delta until the servo is near it's limits. If the
    servo reaches its limit one way or the other before the rudder is at the
    position you want to reach, you will have to adjust the control horn on the
    servo. That's too long a procedure to go into unless you need to know.

    Hope all this helps. Read the Stamp manual on FOR loops. They help a lot.

    Gary



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/




    Do you Yahoo!?
    Exclusive Video Premiere - Britney Spears

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-02 09:33
    From: "Kyle Cooper" <crazykurby@y...>

    > Sorry for asking about this problem now (been busy last few
    > weeks), but [noparse][[/noparse]...]
    Yes, here too, Kyle. Can't remember where we left off exactly...

    > I couldn't get the code to repeat it. The motor
    > only goes through the program once and stops could
    > somebody help or tell me what I'm doing wrong. : )
    >
    I'm guessing, but I think you're probably talking about the code I posted
    that begins:

    > Center CON 150
    > Delta CON 10
    > Cnt VAR Byte
    >
    > FOR Cnt=1 to 20
    > PULSOUT RudderServoPin,Center
    > PAUSE 20
    > NEXT
    > [noparse][[/noparse]...and so forth]

    That is a calibration program. The code is only intended to run once each
    time you download it. Watch the action of the servo, then edit the constants
    and download it again. If I remember correctly, your Stamp is a BS1 so the
    code had to define the constants differently, but I'm too tired tonight to
    remember how it is done in PBasic 1.0. (We were busy with some medical
    problems here, and I'm a little fuzzy<g>.)

    Start with "Center". You need to find out what the correct value is for the
    servo pulse to put the rudder exactly in the center. Run the code as above
    and see if the rudder is exactly centered. It won't be this first time.
    Let's suppose it was to the left of center. Now change the "Center" value in
    that constant statement to be 160. Download the changed program and watch
    the rudder. Did it move toward the center? Or away? If it moved toward
    center, then you know higher numbers move the rudder right. Now keep
    increasing the value and running the program again until the rudder is
    centered.

    If it was further away when you changed the value to 160, then you know that
    higher numbers move the rudder to the left. Write down this information in
    either case. You will need when you write other programs. You want to know
    whether small numbers put the rudder to the left or the right. Now start
    using smaller numbers, and running the program after each change, until you
    find the center.

    Once you find the center value, write that down also. Now start increasing
    the value "Delta" (a word which means the difference between two values).
    We're going the find the difference between the center position and the two
    extremes, left and right. Gradually increase "Delta" in that statement and
    download the changed program each time. Watch the rudder to make sure you
    notice when it reaches the limit of movement. Write down that value of
    Delta.

    Let's suppose you found out the smaller values move the rudder left of
    center. Now whenever you want to move the rudder full left, you would say:

    PULSOUT RudderServoPin, Center-Delta

    Or you could just add a statement defining two new constants:

    RudderLeft CON Center-Delta
    RudderRight CON Center+Delta

    For a BS-1 you might have to subtract and add for yourself and put the
    actual result in the statement. Check your language manual or someone else
    here can tell you. Once you have those constants, you can write code like
    this:

    PULSOUT RudderServoPin, RudderRight

    Then you put statements like that inside a FOR loop and you can waggle the
    rudder back and forth as many times as you want.

    Hope this helps. Good luck,

    Gary
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-02 17:46
    I was talking about the program to waggle the rudders but it helps a lot that
    you went over that program too. thanks Gary sorry I wasn't specific. I went
    through the program several times and the motor would only go through one waggle
    but everything looks ok.
    on 1 line of code changed 2 to -2

    for pulseduration=maxpulse to minpulse step -2

    "Gary W. Sims" <simsgw@c...> wrote:
    From: "Kyle Cooper"

    > Sorry for asking about this problem now (been busy last few
    > weeks), but [noparse][[/noparse]...]
    Yes, here too, Kyle. Can't remember where we left off exactly...

    > I couldn't get the code to repeat it. The motor
    > only goes through the program once and stops could
    > somebody help or tell me what I'm doing wrong. : )
    >
    I'm guessing, but I think you're probably talking about the code I posted
    that begins:

    > Center CON 150
    > Delta CON 10
    > Cnt VAR Byte
    >
    > FOR Cnt=1 to 20
    > PULSOUT RudderServoPin,Center
    > PAUSE 20
    > NEXT
    > [noparse][[/noparse]...and so forth]

    That is a calibration program. The code is only intended to run once each
    time you download it. Watch the action of the servo, then edit the constants
    and download it again. If I remember correctly, your Stamp is a BS1 so the
    code had to define the constants differently, but I'm too tired tonight to
    remember how it is done in PBasic 1.0. (We were busy with some medical
    problems here, and I'm a little fuzzy.)

    Start with "Center". You need to find out what the correct value is for the
    servo pulse to put the rudder exactly in the center. Run the code as above
    and see if the rudder is exactly centered. It won't be this first time.
    Let's suppose it was to the left of center. Now change the "Center" value in
    that constant statement to be 160. Download the changed program and watch
    the rudder. Did it move toward the center? Or away? If it moved toward
    center, then you know higher numbers move the rudder right. Now keep
    increasing the value and running the program again until the rudder is
    centered.

    If it was further away when you changed the value to 160, then you know that
    higher numbers move the rudder to the left. Write down this information in
    either case. You will need when you write other programs. You want to know
    whether small numbers put the rudder to the left or the right. Now start
    using smaller numbers, and running the program after each change, until you
    find the center.

    Once you find the center value, write that down also. Now start increasing
    the value "Delta" (a word which means the difference between two values).
    We're going the find the difference between the center position and the two
    extremes, left and right. Gradually increase "Delta" in that statement and
    download the changed program each time. Watch the rudder to make sure you
    notice when it reaches the limit of movement. Write down that value of
    Delta.

    Let's suppose you found out the smaller values move the rudder left of
    center. Now whenever you want to move the rudder full left, you would say:

    PULSOUT RudderServoPin, Center-Delta

    Or you could just add a statement defining two new constants:

    RudderLeft CON Center-Delta
    RudderRight CON Center+Delta

    For a BS-1 you might have to subtract and add for yourself and put the
    actual result in the statement. Check your language manual or someone else
    here can tell you. Once you have those constants, you can write code like
    this:

    PULSOUT RudderServoPin, RudderRight

    Then you put statements like that inside a FOR loop and you can waggle the
    rudder back and forth as many times as you want.

    Hope this helps. Good luck,

    Gary



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



    Do you Yahoo!?
    Exclusive Video Premiere - Britney Spears

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-02 20:15
    From: "Kyle Cooper" <crazykurby@y...>


    > [noparse][[/noparse]...] everything looks ok. on 1 line of code changed 2 to -2
    >
    > for pulseduration=maxpulse to minpulse step -2
    >
    I speak subject to correction, but unless the PBasic 1.0 is different from
    my PBasic 2.5, I believe you must specify the step with a positive value.
    The interpreter sees that the end value is lower than the start value and
    decrements automatically. If you specify a negative step, you confuse
    things, and that might well cause the loop to execute only once.

    I haven't used loops that step downward lately, but I'm pretty sure that's
    how it works.

    Gary
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-03 00:02
    Before I changed the 2 to -2 the motor only went one way and stopped then after
    I changed it the motor went back and forth once. I cant figure out why it is not
    repeating.
    I know I gotta be doing something wrong but thanks for your help Gary.

    "Gary W. Sims" <simsgw@c...> wrote:
    From: "Kyle Cooper"


    > [noparse][[/noparse]...] everything looks ok. on 1 line of code changed 2 to -2
    >
    > for pulseduration=maxpulse to minpulse step -2
    >
    I speak subject to correction, but unless the PBasic 1.0 is different from
    my PBasic 2.5, I believe you must specify the step with a positive value.
    The interpreter sees that the end value is lower than the start value and
    decrements automatically. If you specify a negative step, you confuse
    things, and that might well cause the loop to execute only once.

    I haven't used loops that step downward lately, but I'm pretty sure that's
    how it works.

    Gary



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and Body of
    the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



    Do you Yahoo!?
    Exclusive Video Premiere - Britney Spears

    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.