Shop OBEX P1 Docs P2 Docs Learn Events
PSC data conversion — Parallax Forums

PSC data conversion

ArchiverArchiver Posts: 46,084
edited 2004-07-13 03:04 in General Discussion
Maybe someone out there can help with this one.

I have a BS2 driving a PSC. I want to be able to send commands to
the bs2 in degrees and convert that value to a number that the PSC
can use.

Since every channel travels 180 degrees and through calibration, we
can determine the PSC value for the extreme limits (0-180 degrees)
It should be a simple matter to calculate the appropriate PSC value
based on a degree value and adjusted by the limits of the particular
servo.

Does anyone know the math for this off hand?

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 14:32
    In a system that could handle floating point numbers, the following
    translation could do it:

    (((max-min)/180)*degrees)+min

    but the stamp does not do floating point so there must be a way to
    handle it.

    Anyone want to take a shot at this one?
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 15:43
    This is actaully pretty easy. Commands to the PSC range from 250 - 1250
    that correspond to 0 - 180 degrees. The solution is a simple mx + b
    equation:

    command = degrees * 5.555 + 250

    Before you panic, the BASIC Stamp can if fact multiply by fractional
    values (the result will be an integer). There are two operators that
    can be used, we'll use */ (star-slash). To use star-slash, multiply
    your fractional value by 256, then apply it as the parameter. The
    equation above becomes:

    command = degrees */ $058E + 250

    I prefer hex when using */ because I can see the whole portion in the
    upper byte, the fractional portion in the lower byte. The BASIC Stamp
    doesn't care what numeric format we use; it's all the same inside.

    For those that need more resolution in fractional values, you can use
    the ** operator. With it you are able to multiply by a value less that
    one in units of 1/65536. Both operators are in the help file.

    Does everyone know there is a new installer and separate help file
    available on our web site?

    http://www.parallax.com/html_pages/downloads/software/software_basic_sta
    mp.asp

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: Dave Evartt [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=dtgta2JMFDY0A-gPaID-D_XeWYsvpXBb2633qVbmf_iNoVKS-_PL2Cu9TkbWW2BZEpxPFm7spDecGaeNNYs]davee@f...[/url
    Sent: Monday, July 12, 2004 8:13 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] PSC data conversion


    Maybe someone out there can help with this one.

    I have a BS2 driving a PSC. I want to be able to send commands to
    the bs2 in degrees and convert that value to a number that the PSC
    can use.

    Since every channel travels 180 degrees and through calibration, we
    can determine the PSC value for the extreme limits (0-180 degrees)
    It should be a simple matter to calculate the appropriate PSC value
    based on a degree value and adjusted by the limits of the particular
    servo.

    Does anyone know the math for this off hand?
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 16:30
    Thanks Jon,

    Not knowing that much about the PSC, is the 0-180 range always 1000?
    Assuming that the servo can always travel 180 degree.

    My experience is that there are always little discrepancies between
    servos and I've learned not to trust the hard coded numbers.

    For instance, 770 is shown as what is considered 'center' but in
    real life it varies by quite a bit. Is that variance consistant
    wonce you determine one partitular angle? If that is the case than
    the 5.555 can be cast in stone and that's fine by me.


    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > This is actaully pretty easy. Commands to the PSC range from 250 -
    1250
    > that correspond to 0 - 180 degrees. The solution is a simple mx + b
    > equation:
    >
    > command = degrees * 5.555 + 250
    >
    > Before you panic, the BASIC Stamp can if fact multiply by
    fractional
    > values (the result will be an integer). There are two operators
    that
    > can be used, we'll use */ (star-slash). To use star-slash,
    multiply
    > your fractional value by 256, then apply it as the parameter. The
    > equation above becomes:
    >
    > command = degrees */ $058E + 250
    >
    > I prefer hex when using */ because I can see the whole portion in
    the
    > upper byte, the fractional portion in the lower byte. The BASIC
    Stamp
    > doesn't care what numeric format we use; it's all the same inside.
    >
    > For those that need more resolution in fractional values, you can
    use
    > the ** operator. With it you are able to multiply by a value less
    that
    > one in units of 1/65536. Both operators are in the help file.
    >
    > Does everyone know there is a new installer and separate help file
    > available on our web site?
    >
    >
    http://www.parallax.com/html_pages/downloads/software/software_basic_
    sta
    > mp.asp
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > Sent: Monday, July 12, 2004 8:13 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    >
    >
    > Maybe someone out there can help with this one.
    >
    > I have a BS2 driving a PSC. I want to be able to send commands to
    > the bs2 in degrees and convert that value to a number that the PSC
    > can use.
    >
    > Since every channel travels 180 degrees and through calibration,
    we
    > can determine the PSC value for the extreme limits (0-180 degrees)
    > It should be a simple matter to calculate the appropriate PSC
    value
    > based on a degree value and adjusted by the limits of the
    particular
    > servo.
    >
    > Does anyone know the math for this off hand?
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 17:38
    Dave,

    I haven't personally used the PSC -- I responded to your question using
    the documentation provided. You're right in that servos will vary, and
    the docs even mention this. You'll need to work with your servos to
    find the endpoints and center. From there you can adust the equation.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: Dave Evartt [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=jJPXDF3Rix9-kd8Owfwal-1qgds_ayI4WfTdT31QwQak_sjLtcGSADZdoRPQ1D3Uw80UwZPvvQ41zQBPpTNVintYHg]davee@f...[/url
    Sent: Monday, July 12, 2004 10:30 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: PSC data conversion


    Thanks Jon,

    Not knowing that much about the PSC, is the 0-180 range always 1000?
    Assuming that the servo can always travel 180 degree.

    My experience is that there are always little discrepancies between
    servos and I've learned not to trust the hard coded numbers.

    For instance, 770 is shown as what is considered 'center' but in
    real life it varies by quite a bit. Is that variance consistant
    wonce you determine one partitular angle? If that is the case than
    the 5.555 can be cast in stone and that's fine by me.


    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > This is actaully pretty easy. Commands to the PSC range from 250 -
    1250
    > that correspond to 0 - 180 degrees. The solution is a simple mx + b
    > equation:
    >
    > command = degrees * 5.555 + 250
    >
    > Before you panic, the BASIC Stamp can if fact multiply by
    fractional
    > values (the result will be an integer). There are two operators
    that
    > can be used, we'll use */ (star-slash). To use star-slash,
    multiply
    > your fractional value by 256, then apply it as the parameter. The
    > equation above becomes:
    >
    > command = degrees */ $058E + 250
    >
    > I prefer hex when using */ because I can see the whole portion in
    the
    > upper byte, the fractional portion in the lower byte. The BASIC
    Stamp
    > doesn't care what numeric format we use; it's all the same inside.
    >
    > For those that need more resolution in fractional values, you can
    use
    > the ** operator. With it you are able to multiply by a value less
    that
    > one in units of 1/65536. Both operators are in the help file.
    >
    > Does everyone know there is a new installer and separate help file
    > available on our web site?
    >
    >
    http://www.parallax.com/html_pages/downloads/software/software_basic_
    sta
    > mp.asp
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > Sent: Monday, July 12, 2004 8:13 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    >
    >
    > Maybe someone out there can help with this one.
    >
    > I have a BS2 driving a PSC. I want to be able to send commands to
    > the bs2 in degrees and convert that value to a number that the PSC
    > can use.
    >
    > Since every channel travels 180 degrees and through calibration,
    we
    > can determine the PSC value for the extreme limits (0-180 degrees)
    > It should be a simple matter to calculate the appropriate PSC
    value
    > based on a degree value and adjusted by the limits of the
    particular
    > servo.
    >
    > Does anyone know the math for this off hand?
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 17:43
    Hi Dave,

    You can find the */ factor at run time,

    (degrees*256/180) */ (PSCmax-PSCmin) + PSCmin

    (degrees/180) will be between 0 and 1 when degrees is between 0 and
    179, so (degrees*256/180) will be proportionately between 0 and 256,
    and */ gets the same proportion of the difference (PSCmax-PSCmin).


    -- Tracy


    >Thanks Jon,
    >
    >Not knowing that much about the PSC, is the 0-180 range always 1000?
    >Assuming that the servo can always travel 180 degree.
    >
    >My experience is that there are always little discrepancies between
    >servos and I've learned not to trust the hard coded numbers.
    >
    >For instance, 770 is shown as what is considered 'center' but in
    >real life it varies by quite a bit. Is that variance consistant
    >wonce you determine one partitular angle? If that is the case than
    >the 5.555 can be cast in stone and that's fine by me.
    >
    >
    >--- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    >wrote:
    > > This is actaully pretty easy. Commands to the PSC range from 250 -
    > 1250
    > > that correspond to 0 - 180 degrees. The solution is a simple mx + b
    > > equation:
    > >
    > > command = degrees * 5.555 + 250
    > >
    > > Before you panic, the BASIC Stamp can if fact multiply by
    >fractional
    > > values (the result will be an integer). There are two operators
    >that
    > > can be used, we'll use */ (star-slash). To use star-slash,
    >multiply
    > > your fractional value by 256, then apply it as the parameter. The
    > > equation above becomes:
    > >
    > > command = degrees */ $058E + 250
    > >
    > > I prefer hex when using */ because I can see the whole portion in
    >the
    > > upper byte, the fractional portion in the lower byte. The BASIC
    >Stamp
    > > doesn't care what numeric format we use; it's all the same inside.
    > >
    > > For those that need more resolution in fractional values, you can
    >use
    > > the ** operator. With it you are able to multiply by a value less
    >that
    > > one in units of 1/65536. Both operators are in the help file.
    > >
    > > Does everyone know there is a new installer and separate help file
    > > available on our web site?
    > >
    > >
    >http://www.parallax.com/html_pages/downloads/software/software_basic_
    >sta
    > > mp.asp
    > >
    > > -- Jon Williams
    > > -- Applications Engineer, Parallax
    > > -- Dallas Office
    > >
    > >
    > >
    Original Message
    > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > > Sent: Monday, July 12, 2004 8:13 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    > >
    > >
    > > Maybe someone out there can help with this one.
    > >
    > > I have a BS2 driving a PSC. I want to be able to send commands to
    > > the bs2 in degrees and convert that value to a number that the PSC
    > > can use.
    > >
    > > Since every channel travels 180 degrees and through calibration,
    >we
    > > can determine the PSC value for the extreme limits (0-180 degrees)
    > > It should be a simple matter to calculate the appropriate PSC
    >value
    > > based on a degree value and adjusted by the limits of the
    >particular
    > > servo.
    > >
    > Does anyone know the math for this off hand?

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 18:29
    that's why you can't assume that the 5.555 is a good number, it
    needs to be calculated by MAX-MIN and then devide THAT number by
    180. That's what I don't know how to do on the stamp.

    once again please: (((MAX-MIN)/180)*DEGREES)+MIN

    (it would be so nice if the compiler could handle the conversion of
    the math but it's a lot to ask.)





    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > Dave,
    >
    > I haven't personally used the PSC -- I responded to your question
    using
    > the documentation provided. You're right in that servos will
    vary, and
    > the docs even mention this. You'll need to work with your servos
    to
    > find the endpoints and center. From there you can adust the
    equation.
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > Sent: Monday, July 12, 2004 10:30 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Re: PSC data conversion
    >
    >
    > Thanks Jon,
    >
    > Not knowing that much about the PSC, is the 0-180 range always
    1000?
    > Assuming that the servo can always travel 180 degree.
    >
    > My experience is that there are always little discrepancies
    between
    > servos and I've learned not to trust the hard coded numbers.
    >
    > For instance, 770 is shown as what is considered 'center' but in
    > real life it varies by quite a bit. Is that variance consistant
    > wonce you determine one partitular angle? If that is the case than
    > the 5.555 can be cast in stone and that's fine by me.
    >
    >
    > --- In basicstamps@yahoogroups.com, "Jon Williams"
    <jwilliams@p...>
    > wrote:
    > > This is actaully pretty easy. Commands to the PSC range from
    250 -
    > 1250
    > > that correspond to 0 - 180 degrees. The solution is a simple mx
    + b
    > > equation:
    > >
    > > command = degrees * 5.555 + 250
    > >
    > > Before you panic, the BASIC Stamp can if fact multiply by
    > fractional
    > > values (the result will be an integer). There are two operators
    > that
    > > can be used, we'll use */ (star-slash). To use star-slash,
    > multiply
    > > your fractional value by 256, then apply it as the parameter.
    The
    > > equation above becomes:
    > >
    > > command = degrees */ $058E + 250
    > >
    > > I prefer hex when using */ because I can see the whole portion in
    > the
    > > upper byte, the fractional portion in the lower byte. The BASIC
    > Stamp
    > > doesn't care what numeric format we use; it's all the same
    inside.
    > >
    > > For those that need more resolution in fractional values, you can
    > use
    > > the ** operator. With it you are able to multiply by a value
    less
    > that
    > > one in units of 1/65536. Both operators are in the help file.
    > >
    > > Does everyone know there is a new installer and separate help
    file
    > > available on our web site?
    > >
    > >
    >
    http://www.parallax.com/html_pages/downloads/software/software_basic_
    > sta
    > > mp.asp
    > >
    > > -- Jon Williams
    > > -- Applications Engineer, Parallax
    > > -- Dallas Office
    > >
    > >
    > >
    Original Message
    > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > > Sent: Monday, July 12, 2004 8:13 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    > >
    > >
    > > Maybe someone out there can help with this one.
    > >
    > > I have a BS2 driving a PSC. I want to be able to send commands to
    > > the bs2 in degrees and convert that value to a number that the
    PSC
    > > can use.
    > >
    > > Since every channel travels 180 degrees and through calibration,
    > we
    > > can determine the PSC value for the extreme limits (0-180
    degrees)
    > > It should be a simple matter to calculate the appropriate PSC
    > value
    > > based on a degree value and adjusted by the limits of the
    > particular
    > > servo.
    > >
    > > Does anyone know the math for this off hand?
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 18:34
    Thanks tracy. I don't quite understand it but if it works, cool.

    Between you and Jon, you both make it easy. Can't wait till I get
    home tonight to try it.


    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > Hi Dave,
    >
    > You can find the */ factor at run time,
    >
    > (degrees*256/180) */ (PSCmax-PSCmin) + PSCmin
    >
    > (degrees/180) will be between 0 and 1 when degrees is between 0
    and
    > 179, so (degrees*256/180) will be proportionately between 0 and
    256,
    > and */ gets the same proportion of the difference (PSCmax-PSCmin).
    >
    >
    > -- Tracy
    >
    >
    > >Thanks Jon,
    > >
    > >Not knowing that much about the PSC, is the 0-180 range always
    1000?
    > >Assuming that the servo can always travel 180 degree.
    > >
    > >My experience is that there are always little discrepancies
    between
    > >servos and I've learned not to trust the hard coded numbers.
    > >
    > >For instance, 770 is shown as what is considered 'center' but in
    > >real life it varies by quite a bit. Is that variance consistant
    > >wonce you determine one partitular angle? If that is the case than
    > >the 5.555 can be cast in stone and that's fine by me.
    > >
    > >
    > >--- In basicstamps@yahoogroups.com, "Jon Williams"
    <jwilliams@p...>
    > >wrote:
    > > > This is actaully pretty easy. Commands to the PSC range from
    250 -
    > > 1250
    > > > that correspond to 0 - 180 degrees. The solution is a simple
    mx + b
    > > > equation:
    > > >
    > > > command = degrees * 5.555 + 250
    > > >
    > > > Before you panic, the BASIC Stamp can if fact multiply by
    > >fractional
    > > > values (the result will be an integer). There are two
    operators
    > >that
    > > > can be used, we'll use */ (star-slash). To use star-slash,
    > >multiply
    > > > your fractional value by 256, then apply it as the
    parameter. The
    > > > equation above becomes:
    > > >
    > > > command = degrees */ $058E + 250
    > > >
    > > > I prefer hex when using */ because I can see the whole
    portion in
    > >the
    > > > upper byte, the fractional portion in the lower byte. The
    BASIC
    > >Stamp
    > > > doesn't care what numeric format we use; it's all the same
    inside.
    > > >
    > > > For those that need more resolution in fractional values, you
    can
    > >use
    > > > the ** operator. With it you are able to multiply by a value
    less
    > >that
    > > > one in units of 1/65536. Both operators are in the help file.
    > > >
    > > > Does everyone know there is a new installer and separate help
    file
    > > > available on our web site?
    > > >
    > > >
    >
    >http://www.parallax.com/html_pages/downloads/software/software_basic
    _
    > >sta
    > > > mp.asp
    > > >
    > > > -- Jon Williams
    > > > -- Applications Engineer, Parallax
    > > > -- Dallas Office
    > > >
    > > >
    > > >
    Original Message
    > > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > > > Sent: Monday, July 12, 2004 8:13 AM
    > > > To: basicstamps@yahoogroups.com
    > > > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    > > >
    > > >
    > > > Maybe someone out there can help with this one.
    > > >
    > > > I have a BS2 driving a PSC. I want to be able to send
    commands to
    > > > the bs2 in degrees and convert that value to a number that
    the PSC
    > > > can use.
    > > >
    > > > Since every channel travels 180 degrees and through
    calibration,
    > >we
    > > > can determine the PSC value for the extreme limits (0-180
    degrees)
    > > > It should be a simple matter to calculate the appropriate PSC
    > >value
    > > > based on a degree value and adjusted by the limits of the
    > >particular
    > > > servo.
    > > >
    > > Does anyone know the math for this off hand?
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 19:02
    Please disregard, it was answered by tracy in a response I didn't
    see until after I wrote this message.


    --- In basicstamps@yahoogroups.com, "Dave Evartt" <davee@f...> wrote:
    > that's why you can't assume that the 5.555 is a good number, it
    > needs to be calculated by MAX-MIN and then devide THAT number by
    > 180. That's what I don't know how to do on the stamp.
    >
    > once again please: (((MAX-MIN)/180)*DEGREES)+MIN
    >
    > (it would be so nice if the compiler could handle the conversion
    of
    > the math but it's a lot to ask.)
    >
    >
    >
    >
    >
    > --- In basicstamps@yahoogroups.com, "Jon Williams"
    <jwilliams@p...>
    > wrote:
    > > Dave,
    > >
    > > I haven't personally used the PSC -- I responded to your
    question
    > using
    > > the documentation provided. You're right in that servos will
    > vary, and
    > > the docs even mention this. You'll need to work with your
    servos
    > to
    > > find the endpoints and center. From there you can adust the
    > equation.
    > >
    > > -- Jon Williams
    > > -- Applications Engineer, Parallax
    > > -- Dallas Office
    > >
    > >
    > >
    Original Message
    > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > > Sent: Monday, July 12, 2004 10:30 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] Re: PSC data conversion
    > >
    > >
    > > Thanks Jon,
    > >
    > > Not knowing that much about the PSC, is the 0-180 range always
    > 1000?
    > > Assuming that the servo can always travel 180 degree.
    > >
    > > My experience is that there are always little discrepancies
    > between
    > > servos and I've learned not to trust the hard coded numbers.
    > >
    > > For instance, 770 is shown as what is considered 'center' but in
    > > real life it varies by quite a bit. Is that variance consistant
    > > wonce you determine one partitular angle? If that is the case
    than
    > > the 5.555 can be cast in stone and that's fine by me.
    > >
    > >
    > > --- In basicstamps@yahoogroups.com, "Jon Williams"
    > <jwilliams@p...>
    > > wrote:
    > > > This is actaully pretty easy. Commands to the PSC range from
    > 250 -
    > > 1250
    > > > that correspond to 0 - 180 degrees. The solution is a simple
    mx
    > + b
    > > > equation:
    > > >
    > > > command = degrees * 5.555 + 250
    > > >
    > > > Before you panic, the BASIC Stamp can if fact multiply by
    > > fractional
    > > > values (the result will be an integer). There are two
    operators
    > > that
    > > > can be used, we'll use */ (star-slash). To use star-slash,
    > > multiply
    > > > your fractional value by 256, then apply it as the parameter.
    > The
    > > > equation above becomes:
    > > >
    > > > command = degrees */ $058E + 250
    > > >
    > > > I prefer hex when using */ because I can see the whole portion
    in
    > > the
    > > > upper byte, the fractional portion in the lower byte. The
    BASIC
    > > Stamp
    > > > doesn't care what numeric format we use; it's all the same
    > inside.
    > > >
    > > > For those that need more resolution in fractional values, you
    can
    > > use
    > > > the ** operator. With it you are able to multiply by a value
    > less
    > > that
    > > > one in units of 1/65536. Both operators are in the help file.
    > > >
    > > > Does everyone know there is a new installer and separate help
    > file
    > > > available on our web site?
    > > >
    > > >
    > >
    >
    http://www.parallax.com/html_pages/downloads/software/software_basic_
    > > sta
    > > > mp.asp
    > > >
    > > > -- Jon Williams
    > > > -- Applications Engineer, Parallax
    > > > -- Dallas Office
    > > >
    > > >
    > > >
    Original Message
    > > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > > > Sent: Monday, July 12, 2004 8:13 AM
    > > > To: basicstamps@yahoogroups.com
    > > > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    > > >
    > > >
    > > > Maybe someone out there can help with this one.
    > > >
    > > > I have a BS2 driving a PSC. I want to be able to send commands
    to
    > > > the bs2 in degrees and convert that value to a number that the
    > PSC
    > > > can use.
    > > >
    > > > Since every channel travels 180 degrees and through
    calibration,
    > > we
    > > > can determine the PSC value for the extreme limits (0-180
    > degrees)
    > > > It should be a simple matter to calculate the appropriate PSC
    > > value
    > > > based on a degree value and adjusted by the limits of the
    > > particular
    > > > servo.
    > > >
    > > > Does anyone know the math for this off hand?
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-12 22:07
    There should be no big mystery in the */ operator.

    Suppose degrees=77, for example. The idea behind the */ operator is
    to approximate your fraction, 77/180, by the fraction 109/256.
    Calculate it out. You will see that they are the same number, 0.427
    (as close as can be done with the denominator 256).

    When the stamp computes {x = 109 */ (PSCmax-PSCmin)}, it multiplies
    the numbers together internally in a 32 bit workspace, and then
    shifts the result 8 bits to the right. That is equivalent to
    dividing by 256, making the whole thing, 109/256. In summary, {x =
    109 */ (PSCmax-PSCmin)} is the same as {x = 0.426 * (PSCmax-PSCmin)}
    on a calculator.

    The calculation (degrees*256/180) takes 77 as its input and gives 109
    as its output. It is in effect solving for y in, y/256 = 77/180.
    That is the same relation you or the Stamp would have to solve to
    find the factor to go with the */. If you knew degrees=77 in advance
    at compile time, then you would just use y= 77/180 * 256 = 0.426 *
    256 = 109. But in your situation, degrees is a variable. The stamp
    has to do it in this order, (degrees * 256 / 180), so that degrees *
    256 will be a large number that can be divided by 180. If the stamp
    did it this other way, (degrees / 180 * 256), it would always come
    out zero.

    There are other ways to find the answer, but */ seems good for this situation.

    -- Tracy



    >Thanks tracy. I don't quite understand it but if it works, cool.
    >
    >Between you and Jon, you both make it easy. Can't wait till I get
    >home tonight to try it.
    >
    >
    > --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    >> Hi Dave,
    >>
    >> You can find the */ factor at run time,
    >>
    > > (degrees*256/180) */ (PSCmax-PSCmin) + PSCmin
    >>
    >> (degrees/180) will be between 0 and 1 when degrees is between 0
    >and
    >> 179, so (degrees*256/180) will be proportionately between 0 and
    >256,
    >> and */ gets the same proportion of the difference (PSCmax-PSCmin).
    >>
    >>
    >> -- Tracy
    >>
    >>
    >> >Thanks Jon,
    >> >
    >> >Not knowing that much about the PSC, is the 0-180 range always
    >1000?
    >> >Assuming that the servo can always travel 180 degree.
    >> >
    >> >My experience is that there are always little discrepancies
    >between
    >> >servos and I've learned not to trust the hard coded numbers.
    >> >
    >> >For instance, 770 is shown as what is considered 'center' but in
    >> >real life it varies by quite a bit. Is that variance consistant
    >> >wonce you determine one partitular angle? If that is the case than
    >> >the 5.555 can be cast in stone and that's fine by me.
    >> >
    >> >
    >> >--- In basicstamps@yahoogroups.com, "Jon Williams"
    ><jwilliams@p...>
    >> >wrote:
    >> > > This is actaully pretty easy. Commands to the PSC range from
    >250 -
    >> > 1250
    >> > > that correspond to 0 - 180 degrees. The solution is a simple
    >mx + b
    >> > > equation:
    >> > >
    >> > > command = degrees * 5.555 + 250
    >> > >
    >> > > Before you panic, the BASIC Stamp can if fact multiply by
    >> >fractional
    >> > > values (the result will be an integer). There are two
    >operators
    >> >that
    >> > > can be used, we'll use */ (star-slash). To use star-slash,
    >> >multiply
    >> > > your fractional value by 256, then apply it as the
    >parameter. The
    >> > > equation above becomes:
    >> > >
    >> > > command = degrees */ $058E + 250
    >> > >
    >> > > I prefer hex when using */ because I can see the whole
    >portion in
    >> >the
    >> > > upper byte, the fractional portion in the lower byte. The
    >BASIC
    >> >Stamp
    >> > > doesn't care what numeric format we use; it's all the same
    >inside.
    >> > >
    >> > > For those that need more resolution in fractional values, you
    >can
    >> >use
    >> > > the ** operator. With it you are able to multiply by a value
    >less
    >> >that
    >> > > one in units of 1/65536. Both operators are in the help file.
    >> > >
    >> > > Does everyone know there is a new installer and separate help
    >file
    >> > > available on our web site?
    >> > >
    >> > >
    >>
    >>http://www.parallax.com/html_pages/downloads/software/software_basic
    >_
    >> >sta
    >> > > mp.asp
    >> > >
    >> > > -- Jon Williams
    > > > > -- Applications Engineer, Parallax
    >> > > -- Dallas Office
    >> > >
    >> > >
    >> > >
    Original Message
    >> > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    >> > > Sent: Monday, July 12, 2004 8:13 AM
    >> > > To: basicstamps@yahoogroups.com
    >> > > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    >> > >
    >> > >
    >> > > Maybe someone out there can help with this one.
    >> > >
    >> > > I have a BS2 driving a PSC. I want to be able to send
    >commands to
    >> > > the bs2 in degrees and convert that value to a number that
    >the PSC
    >> > > can use.
    >> > >
    >> > > Since every channel travels 180 degrees and through
    >calibration,
    >> >we
    >> > > can determine the PSC value for the extreme limits (0-180
    >degrees)
    >> > > It should be a simple matter to calculate the appropriate PSC
    >> >value
    >> > > based on a degree value and adjusted by the limits of the
    >> >particular
    >> > > servo.
    >> > >
    >> > Does anyone know the math for this off hand?
    >>
    >> [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    >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.
    >
    >Yahoo! Groups Links
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-13 03:04
    For the record, it works perfectly. I now have a functional BS2P
    robot controller that uses the PSC to control the servos. The BS2P
    is the interface between the serial port on the computer and the
    whole thing.

    All I have to do is send joint commands that consist of the first
    letter of the joint and a 0-180 value and the joint rotates there
    very nicely.

    s90
    e90
    w0

    puts it into a nice 90 degree configuration

    __
    | |
    |
    =

    I wonder what I'll do tomorrow [noparse]:)[/noparse]
    Thanks again, and thanks for the explanation.



    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > There should be no big mystery in the */ operator.
    >
    > Suppose degrees=77, for example. The idea behind the */ operator
    is
    > to approximate your fraction, 77/180, by the fraction 109/256.
    > Calculate it out. You will see that they are the same number,
    0.427
    > (as close as can be done with the denominator 256).
    >
    > When the stamp computes {x = 109 */ (PSCmax-PSCmin)}, it
    multiplies
    > the numbers together internally in a 32 bit workspace, and then
    > shifts the result 8 bits to the right. That is equivalent to
    > dividing by 256, making the whole thing, 109/256. In summary, {x
    =
    > 109 */ (PSCmax-PSCmin)} is the same as {x = 0.426 * (PSCmax-
    PSCmin)}
    > on a calculator.
    >
    > The calculation (degrees*256/180) takes 77 as its input and gives
    109
    > as its output. It is in effect solving for y in, y/256 = 77/180.
    > That is the same relation you or the Stamp would have to solve to
    > find the factor to go with the */. If you knew degrees=77 in
    advance
    > at compile time, then you would just use y= 77/180 * 256 = 0.426 *
    > 256 = 109. But in your situation, degrees is a variable. The
    stamp
    > has to do it in this order, (degrees * 256 / 180), so that degrees
    *
    > 256 will be a large number that can be divided by 180. If the
    stamp
    > did it this other way, (degrees / 180 * 256), it would always come
    > out zero.
    >
    > There are other ways to find the answer, but */ seems good for
    this situation.
    >
    > -- Tracy
    >
    >
    >
    > >Thanks tracy. I don't quite understand it but if it works, cool.
    > >
    > >Between you and Jon, you both make it easy. Can't wait till I get
    > >home tonight to try it.
    > >
    > >
    > > --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...>
    wrote:
    > >> Hi Dave,
    > >>
    > >> You can find the */ factor at run time,
    > >>
    > > > (degrees*256/180) */ (PSCmax-PSCmin) + PSCmin
    > >>
    > >> (degrees/180) will be between 0 and 1 when degrees is between 0
    > >and
    > >> 179, so (degrees*256/180) will be proportionately between 0 and
    > >256,
    > >> and */ gets the same proportion of the difference (PSCmax-
    PSCmin).
    > >>
    > >>
    > >> -- Tracy
    > >>
    > >>
    > >> >Thanks Jon,
    > >> >
    > >> >Not knowing that much about the PSC, is the 0-180 range always
    > >1000?
    > >> >Assuming that the servo can always travel 180 degree.
    > >> >
    > >> >My experience is that there are always little discrepancies
    > >between
    > >> >servos and I've learned not to trust the hard coded numbers.
    > >> >
    > >> >For instance, 770 is shown as what is considered 'center' but
    in
    > >> >real life it varies by quite a bit. Is that variance
    consistant
    > >> >wonce you determine one partitular angle? If that is the case
    than
    > >> >the 5.555 can be cast in stone and that's fine by me.
    > >> >
    > >> >
    > >> >--- In basicstamps@yahoogroups.com, "Jon Williams"
    > ><jwilliams@p...>
    > >> >wrote:
    > >> > > This is actaully pretty easy. Commands to the PSC range
    from
    > >250 -
    > >> > 1250
    > >> > > that correspond to 0 - 180 degrees. The solution is a
    simple
    > >mx + b
    > >> > > equation:
    > >> > >
    > >> > > command = degrees * 5.555 + 250
    > >> > >
    > >> > > Before you panic, the BASIC Stamp can if fact multiply by
    > >> >fractional
    > >> > > values (the result will be an integer). There are two
    > >operators
    > >> >that
    > >> > > can be used, we'll use */ (star-slash). To use star-
    slash,
    > >> >multiply
    > >> > > your fractional value by 256, then apply it as the
    > >parameter. The
    > >> > > equation above becomes:
    > >> > >
    > >> > > command = degrees */ $058E + 250
    > >> > >
    > >> > > I prefer hex when using */ because I can see the whole
    > >portion in
    > >> >the
    > >> > > upper byte, the fractional portion in the lower byte. The
    > >BASIC
    > >> >Stamp
    > >> > > doesn't care what numeric format we use; it's all the same
    > >inside.
    > >> > >
    > >> > > For those that need more resolution in fractional values,
    you
    > >can
    > >> >use
    > >> > > the ** operator. With it you are able to multiply by a
    value
    > >less
    > >> >that
    > >> > > one in units of 1/65536. Both operators are in the help
    file.
    > >> > >
    > >> > > Does everyone know there is a new installer and separate
    help
    > >file
    > >> > > available on our web site?
    > >> > >
    > >> > >
    > >>
    >
    >>http://www.parallax.com/html_pages/downloads/software/software_basi
    c
    > >_
    > >> >sta
    > >> > > mp.asp
    > >> > >
    > >> > > -- Jon Williams
    > > > > > -- Applications Engineer, Parallax
    > >> > > -- Dallas Office
    > >> > >
    > >> > >
    > >> > >
    Original Message
    > >> > > From: Dave Evartt [noparse][[/noparse]mailto:davee@f...]
    > >> > > Sent: Monday, July 12, 2004 8:13 AM
    > >> > > To: basicstamps@yahoogroups.com
    > >> > > Subject: [noparse][[/noparse]basicstamps] PSC data conversion
    > >> > >
    > >> > >
    > >> > > Maybe someone out there can help with this one.
    > >> > >
    > >> > > I have a BS2 driving a PSC. I want to be able to send
    > >commands to
    > >> > > the bs2 in degrees and convert that value to a number that
    > >the PSC
    > >> > > can use.
    > >> > >
    > >> > > Since every channel travels 180 degrees and through
    > >calibration,
    > >> >we
    > >> > > can determine the PSC value for the extreme limits (0-180
    > >degrees)
    > >> > > It should be a simple matter to calculate the appropriate
    PSC
    > >> >value
    > >> > > based on a degree value and adjusted by the limits of the
    > >> >particular
    > >> > > servo.
    > >> > >
    > >> > Does anyone know the math for this off hand?
    > >>
    > >> [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > >
    > >
    > >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.
    > >
    > >Yahoo! Groups Links
    > >
    > >
    > >
    > >
Sign In or Register to comment.