Using conditional conversions


Recommended Posts

After calibrating a displacement sensor it shows that the best results are obtained when splitting the range of the sensor in two parts (range A and range B).

In range A, conversion A is the best, in range B, conversion B gives the best results.

How can I use two different conversions, based on a button with which I select the range taht I use.

Link to comment
Share on other sites

Use simple boolean math and a flag.  So let's say you create a flag called "UseRangeB" that is either 0 for Range A, or 1 for Range B.  Use "global UseRangeB = 0" in an autostart sequence to do this.  Let's say Range A's conversion is "Value * 2" while Range B's conversion is "Value * 3".  The overall Conversion would then be:

(Value * 2) * !UseRangeB + (Value * 3) * UseRangeB

 

Link to comment
Share on other sites

The problem is that you can't have two channels that reference the same I/O point.  They are considered the same channel and whether the Conversion is applied is unpredictable because one has a Conversion and the other does not.

If you really want to have a raw and converted channel, then you need to create a regular raw channel for the I/O point, then create a Test D/A channel with Timing = 0, and then put code in the Event for the raw reading that stuffs the converted value into the test channel.  In this case, you can use iif instead of the boolean math.  iif() doesn't work inside a Conversion under the latest version of DAQFactory (something we need to fix...)

sensor_output_converted.addvalue(iif(button_state), sensor_output_raw[0] + 10, sensor_output_raw[0] + 50)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.