Shop OBEX P1 Docs P2 Docs Learn Events
R/C examples please — Parallax Forums

R/C examples please

ArchiverArchiver Posts: 46,084
edited 2000-10-27 20:47 in General Discussion
Here is my dilemma.

I have a R/C receiver attached to the BS2. Works fine. The values are
Max_Forward = 554, Radio_Neutral = 760, Max_ Reverse = 966. This is the
data I get for the mentioned values by moving the stick up and down. Easy
enough. How here is my problem. I want to control two motor controllers
using PWM . The controllers are the MC6 buy Diverse Electronics
http://divelec.tripod.com/ . He has examples with R/C connections, but not
for this type model. So back to the issue at hand.

The motor controller can accept a PWM command value from 52(1.0v) to
165(3.2v). This value is used for both directions. Meaning I have to use a
second pin to control direction for forward and reverse, and a third pin to
enable/disable the board, which is no big deal. The real issue is how to I
get the Forward Value from 758 to 554 to equate to the values from 52 to 165
and then again for reverse values of 762 to 966 to equal the same values of
52 to 165. If I'm not clear please email me I really want to get this to
work this weekend.

Shawn Rogers
*Internet: Shawn.rogers2@c...

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-10-27 20:06
    If I understand your question, you want to change a span of 758 to 554 into
    52 to 165. You also want to change a span of 762 to 996 into 52 to 165.

    Should be easy enough:

    lowin0 con 554
    lowout0 con 52 ' lowest output value
    span1 con 204
    span2 con 113 ' diff between 165 and 52

    value = ???? (whatever)

    if value>=762 then revspan
    ' compute forward span
    value=value-lowin0 ' (now 0 to 204)
    ' optional -- reverse direction
    value=span1-value ' (now 204 to 0) ' ** omit line in one of the routines
    value=value*113/204 ' won't overflow 16 bits -- now from 0 to 113
    ' offset
    value=value+lowout0

    ' do what you want here
    blah blah blah

    revspan:
    ' Same thing, but use lowin1 and reverse (or not -- one should reverse, one
    should not)

    Let's try an example. An input of 654 is about half way, right? So more or
    less you should get about 100 out of the formula (I don't want exactly half
    for reasons you'll see in a second, but this will tell me I'm in the
    ballpark).

    654-554 => 100
    (no reverse)
    100*113 => 11300
    11300/204 => 55
    55+52 => 107 ' close enough to my estimate

    If you reverse, it won't be much different because we are roughly the
    middle:
    (reverse)
    204-100 => 104
    104*113 => 11752
    11752/204 => 57
    57+52 => 109

    The exact middle, by the way would be 554+102=656:
    656-554 => 102
    102*113 => 11526
    11526/204 => 56
    56+52 => 108 or:

    656-554 => 102
    204-102 => 102 (!)
    102*113 => 11526
    11526/204 => 56
    56+52 => 108

    Reversing the value within the larger span makes this work out. Try
    reversing it after adjusting to the shorter span and you'll find out that a
    "mid" value gives you 107 or 108 because of integer math problems.

    Since you are going from a span of 204 to a span of 113, every 2 units on
    the input works out to about 1 unit on the output. That proves out becuase
    656 in the reverse direction came out to 108, but 654 (2 units) worked out
    to 109. (Not reversed: 107 and 108 -- same thing).

    Hope that helps. By the way, you can use our PAK-V to generate 8 channels of
    PWM at once (although you still need external drive transistors to handle
    your motors). The PAK-VIII can also -- among other things -- generate 8
    channels of PWM.

    Regards,

    Al Williams
    AWC
    * 8 channels of PWM at http://www.al-williams.com/awce/pak5.htm
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-27 20:28
    Thanks for your input Al, I will read it and see how much I can understand
    and absorb.

    I guess the easiest way I can explain my goal is.

    I have a R/C receiver whose input pulses at neutral = 760 and full forward =
    554.

    Full Reverse = 996
    I have for simplistic purposes one motor controller
    Features are

    pin1 - controls power to board AKA also = neutral
    pin2 - controls Forward - making sure pin3 is low
    pin3 - Controls Reverse - making sure pin2 is low
    pin4 - controls PWM - min_pulse = 52(1.0v) , Max_pulse = 165 (will affect
    the speed of pin2 or pin3 based on which one is set High)

    Now again without understanding your code as of yet(which is really
    appreciated)

    I would like to accomplish the below on a BS2:
    By moving the R/C trans stick forward slowly the motor controller will
    respond accordingly and again moving it backward slows it down to neutral
    which stops and then continue to full reverse would speed it up the other
    direction.

    I can not stress how appreciative I am of your assistance and any one
    else's. My skills are at best minimal and need all the help I can get.
    Thanks again

    Shawn Rogers
    Original Message
    From: Al Williams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=7_DdmFimNkvMOvhciyQX14t5r87wAYY-xVvKOkDNSsHxdkaEAI2k9zdEXAXiffBR2L6iGI3XXlNLIw]alw@a...[/url
    Sent: Friday, October 27, 2000 2:06 PM
    To: basicstamps@egroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] R/C examples please


    If I understand your question, you want to change a span of 758 to 554 into
    52 to 165. You also want to change a span of 762 to 996 into 52 to 165.

    Should be easy enough:

    lowin0 con 554
    lowout0 con 52 ' lowest output value
    span1 con 204
    span2 con 113 ' diff between 165 and 52

    value = ???? (whatever)

    if value>=762 then revspan
    ' compute forward span
    value=value-lowin0 ' (now 0 to 204)
    ' optional -- reverse direction
    value=span1-value ' (now 204 to 0) ' ** omit line in one of the routines
    value=value*113/204 ' won't overflow 16 bits -- now from 0 to 113
    ' offset
    value=value+lowout0

    ' do what you want here
    blah blah blah

    revspan:
    ' Same thing, but use lowin1 and reverse (or not -- one should reverse, one
    should not)

    Let's try an example. An input of 654 is about half way, right? So more or
    less you should get about 100 out of the formula (I don't want exactly half
    for reasons you'll see in a second, but this will tell me I'm in the
    ballpark).

    654-554 => 100
    (no reverse)
    100*113 => 11300
    11300/204 => 55
    55+52 => 107 ' close enough to my estimate

    If you reverse, it won't be much different because we are roughly the
    middle:
    (reverse)
    204-100 => 104
    104*113 => 11752
    11752/204 => 57
    57+52 => 109

    The exact middle, by the way would be 554+102=656:
    656-554 => 102
    102*113 => 11526
    11526/204 => 56
    56+52 => 108 or:

    656-554 => 102
    204-102 => 102 (!)
    102*113 => 11526
    11526/204 => 56
    56+52 => 108

    Reversing the value within the larger span makes this work out. Try
    reversing it after adjusting to the shorter span and you'll find out that a
    "mid" value gives you 107 or 108 because of integer math problems.

    Since you are going from a span of 204 to a span of 113, every 2 units on
    the input works out to about 1 unit on the output. That proves out becuase
    656 in the reverse direction came out to 108, but 654 (2 units) worked out
    to 109. (Not reversed: 107 and 108 -- same thing).

    Hope that helps. By the way, you can use our PAK-V to generate 8 channels of
    PWM at once (although you still need external drive transistors to handle
    your motors). The PAK-VIII can also -- among other things -- generate 8
    channels of PWM.

    Regards,

    Al Williams
    AWC
    * 8 channels of PWM at http://www.al-williams.com/awce/pak5.htm
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-27 20:47
    Okay cool, in looking at Al's formula I think I got it.

    Shawn

    Original Message
    From: Al Williams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=M7Xe1OJYKv9lC4vMYWFFi6grP5v2rAhZnY8CM3HEhgEM-NUV6bVPQzNejcCnUkYOICmC5ehH4hMftSyI]alw@a...[/url
    Sent: Friday, October 27, 2000 2:06 PM
    To: basicstamps@egroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] R/C examples please


    If I understand your question, you want to change a span of 758 to 554 into
    52 to 165. You also want to change a span of 762 to 996 into 52 to 165.

    Should be easy enough:

    lowin0 con 554
    lowout0 con 52 ' lowest output value
    span1 con 204
    span2 con 113 ' diff between 165 and 52

    value = ???? (whatever)

    if value>=762 then revspan
    ' compute forward span
    value=value-lowin0 ' (now 0 to 204)
    ' optional -- reverse direction
    value=span1-value ' (now 204 to 0) ' ** omit line in one of the routines
    value=value*113/204 ' won't overflow 16 bits -- now from 0 to 113
    ' offset
    value=value+lowout0

    ' do what you want here
    blah blah blah

    revspan:
    ' Same thing, but use lowin1 and reverse (or not -- one should reverse, one
    should not)

    Let's try an example. An input of 654 is about half way, right? So more or
    less you should get about 100 out of the formula (I don't want exactly half
    for reasons you'll see in a second, but this will tell me I'm in the
    ballpark).

    654-554 => 100
    (no reverse)
    100*113 => 11300
    11300/204 => 55
    55+52 => 107 ' close enough to my estimate

    If you reverse, it won't be much different because we are roughly the
    middle:
    (reverse)
    204-100 => 104
    104*113 => 11752
    11752/204 => 57
    57+52 => 109

    The exact middle, by the way would be 554+102=656:
    656-554 => 102
    102*113 => 11526
    11526/204 => 56
    56+52 => 108 or:

    656-554 => 102
    204-102 => 102 (!)
    102*113 => 11526
    11526/204 => 56
    56+52 => 108

    Reversing the value within the larger span makes this work out. Try
    reversing it after adjusting to the shorter span and you'll find out that a
    "mid" value gives you 107 or 108 because of integer math problems.

    Since you are going from a span of 204 to a span of 113, every 2 units on
    the input works out to about 1 unit on the output. That proves out becuase
    656 in the reverse direction came out to 108, but 654 (2 units) worked out
    to 109. (Not reversed: 107 and 108 -- same thing).

    Hope that helps. By the way, you can use our PAK-V to generate 8 channels of
    PWM at once (although you still need external drive transistors to handle
    your motors). The PAK-VIII can also -- among other things -- generate 8
    channels of PWM.

    Regards,

    Al Williams
    AWC
    * 8 channels of PWM at http://www.al-williams.com/awce/pak5.htm
Sign In or Register to comment.