How to convert a string to a usable formule inside my prog ?

Just starting out? Need help? Post your questions and find answers here.
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

How to convert a string to a usable formule inside my prog ?

Post by marc_256 »

Hallo,

For my CNC program, who is communicating with an arduino,
I want to read the temperature of the cooling water.

This is messured via a sensor connected on the analog input A0 on the arduino board.
This input haves a resolution of 10 bits => ReadAnalogValue = 0...1023

I want to give the enduser the freedom to enter a formule to convert this value to a temperature

EXAMPLE:
-20.0...110.0 C


My used variables:

Code: Select all

Global ReadAnalogValue.w = Arduino analog input A0 => 0...1023
Global TempMin.f = -20.0
Global TempMax.f = 110.0
Global DeltaTemp.f = TempMax - TempMin = 120.0
Global Resolution.w = 10 bits = 1024
Global MyTemperature.f
Global UserString.s
So, the enduser will enter this formule as a UserString.s:

Code: Select all

UserString = "(ReadAnalogValue * (120.0 / 1024)) - 10.0"
OR the user can enter "-10 + (ReadAnalogValue * (120.0 / 1024))"
So MyTemperature = ...

Question:
How can I convert this string UserString to a usable formule inside my program ?
WIN10 x64 - PB 5.72x64 LST

Thanks,
marc

Image
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to convert a string to a usable formule inside my pr

Post by infratec »

User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: How to convert a string to a usable formule inside my pr

Post by Demivec »

It would seem the formula for the temperature doesn't change. Instead of having them entering a formula why don't you have them enter the constants MinTemp and MaxTemp?

Temperature = ( (MaxTemp - MinTemp) / 1024) * ReadAnalogValue + MinTemp
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How to convert a string to a usable formule inside my pr

Post by marc_256 »

Hi infratec,

Yes, I think this is what I need.
thanks for helping.

Hallo Demivec,

Well, this is an example,
I don't know what the enduser will enter as formule ...
otherwise you are right,
this was a temperature example, there are also other analog inputs as tachy (speed) sensors.

tanks,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: How to convert a string to a usable formule inside my pr

Post by Fig »

If your sensor is linear Demivec is right...
I don't see any other sensor except maybe Delta pressure to measure a flow. (which need a root square)
But you can handle this specific case by using a checkboxgadget. (and usualy that kind of sensors already have a root square in their parameter if needed)

Else, you also can handle specific cases by using a table the user uploads, with linear interpolation between points.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Post Reply