Shop OBEX P1 Docs P2 Docs Learn Events
Data, Read, & Target variable — Parallax Forums

Data, Read, & Target variable

ArchiverArchiver Posts: 46,084
edited 2001-08-17 18:02 in General Discussion
I am using a tilt sensor in an automatic leveling application.

My target variable that indicates a level position (90 degrees for the sake
of this argument) is 1780.

if the sensor is at 80 degrees it returns a value of 1710 (-70 from target)
and if the sensor is at 100 degrees it returns 1860 (+70 from target). I
would like to use the difference to control the level correction speed using
a "read / Data" table. Is there a simple way to ignore the sign and just
use the value of the result?

i.e.,

Correction_speed data 50,100,200,500,2000
speed var word
X var word

Get_sensor X (lets just say X =1760)
read correction_speed + (1780-x/10), speed

in this example speed will have the value of the "2" in eeprom (200). But if
my sensor is on the other side of level and returns a value of 1800, the
result will be a negative number.

i.e.,

Correction_speed data 50,100,200,500,2000
speed var word
X var word

Get_sensor X (lets just say X =1800)
read correction_speed + (1780-x/10), speed

this time we get a -2

I know there has to be a simple solution for a simple problem. Any help
would be appreciated. Thanks

Jeff

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-08-17 18:00
    Jeff,

    y = abs x

    the absolute value of x


    > I am using a tilt sensor in an automatic leveling application.
    >
    >My target variable that indicates a level position (90 degrees for the sake
    >of this argument) is 1780.
    >
    >if the sensor is at 80 degrees it returns a value of 1710 (-70 from target)
    >and if the sensor is at 100 degrees it returns 1860 (+70 from target). I
    >would like to use the difference to control the level correction speed using
    >a "read / Data" table. Is there a simple way to ignore the sign and just
    >use the value of the result?
    >
    >i.e.,
    >
    >Correction_speed data 50,100,200,500,2000
    >speed var word
    >X var word
    >
    >Get_sensor X (lets just say X =1760)
    >read correction_speed + (1780-x/10), speed
    >
    >in this example speed will have the value of the "2" in eeprom (200). But if
    >my sensor is on the other side of level and returns a value of 1800, the
    >result will be a negative number.
    >
    >i.e.,
    >
    >Correction_speed data 50,100,200,500,2000
    >speed var word
    >X var word
    >
    >Get_sensor X (lets just say X =1800)
    >read correction_speed + (1780-x/10), speed
    >
    > this time we get a -2
    >
    >I know there has to be a simple solution for a simple problem. Any help
    >would be appreciated. Thanks
    >
    >Jeff
  • ArchiverArchiver Posts: 46,084
    edited 2001-08-17 18:02
    D'oh. That hurt! [noparse]:)[/noparse]

    Thanks Tracy!.
Sign In or Register to comment.