Shop OBEX P1 Docs P2 Docs Learn Events
math issue — Parallax Forums

math issue

acadienjccacadienjcc Posts: 6
edited 2013-01-16 15:56 in BASIC Stamp
Hello all,

what would be the math function to reverse a value?

i.e. the value is high when there is less pressure, and it gets lower as pressure is increased. what math algorithm would I use to obtain the reverse? (higher pressure gives a higher number & lower pressure gives a lower number)

the sensor is a flexiforce sensor, sample code: FlexiForce_Simple.bs2

Comments

  • BeanBean Posts: 8,129
    edited 2013-01-16 10:37
    Just take the negative of the value. Or subtract the value from a constant.
    For example if the value goes from 10 to 100 just do "value = 110 - value" and the value have the same range.

    I hope this helps,
    Bean
  • stamptrolstamptrol Posts: 1,731
    edited 2013-01-16 10:44
    Its not so much a math function, but the application of the standard "scaling and offset" equation used with sensors and signals. You'll find it written as y=mx+b.
    Just Google "signal scaling equation" or "signal scaling and offset" and check out a couple of articles.

    Briefly, to reverse the response of the sensor, you start with the maximum possible value and subtract the sensor output from it. Say the sensor goes from 0 - 256. For normal readout, you'd expect the number to go from 0 up to 256. For reverse readout you'd say (256-sensor)=value.

    Cheers,
  • acadienjccacadienjcc Posts: 6
    edited 2013-01-16 11:03
    thanks guys, that was very helpful.

    I'll see if I can get it to work now and post if I run into problems.
  • stamptrolstamptrol Posts: 1,731
    edited 2013-01-16 12:18
    Just to follow up, here's an article showing how it is done: http://kb.mccdaq.com/KnowledgebaseArticle50048.aspx

    Cheers,
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-01-16 14:43
    Keep in mind that there are other functions that can satisfy the notion, "the value is high when there is less pressure, and it gets lower as pressure is increased". One common such function is K/x, or a variation thereof, such as K/(x+B). I suspect that this sensor has a dependence of the form of R = K/F, roughly speaking, where F is force or pressure, R is resistance, and K is a constant. The same applied to an RCTIME measurement, R*C = C*K/F.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-01-16 15:56
    From the flexiforce user manual, resistance proportional to 1/F:
    Flexiforce_FvsR.png
    511 x 274 - 87K
Sign In or Register to comment.