Decision with floating variable

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
dagr99
Posts: 1
Joined: Wed Jan 12, 2022 10:19 am
Contact:

Decision with floating variable

Post by dagr99 »

I am setting up an Automatic dispenser in flowcode, it has a servo and an ultrasound, I am using the ultrasound of the program that has the GetDistance macro, So I start the components with their macros, enable the servo to the channel, and create a loop, put the GetDistance macro and save to a floating variable called "D" then create a decision for To move the servo, in this I put "D <= 10" since the GetDistance followed the description of the macro call it gives it in cm, I compare it with a value, so that based on that, it activates the servo or not, the problem It comes, that when testing, the servo moves by itself even though the decision is not fulfilled, the sensor is working, it is sending the signal back and forth, but I think the problem is in the formulation of the Decision next to the floating variable, is there a way to write this decision next to floats that I don't know? Should I transform this variable first and then compare it in a decision? Many thanks

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Decision with floating variable

Post by medelec35 »

Hi.
Can you post your project file (.fcfx extension), so we can have a look for you?
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Decision with floating variable

Post by mnf »

Hi dagr.

Please could you post your code-- someone will be able to help you then...

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Decision with floating variable

Post by Benj »

Hello,

If the variable D is a float then you might want to make your comparison value a float as well.

D <= 10.0

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Decision with floating variable

Post by chipfryer27 »

Hi

Alternatively, you may wish to consider using an Ultrasonic module that can be preset with a distance. If anything appears within the selected distance then the output toggles Low / High or vice versa. The module does the thinking for you and provides a clear high / low upon detection. Available from all the usual suspects.

How are you controlling the servo? I admit I'm no expert in such but I've seen "budget" controllers act quite weird. Cheap components drifting etc.

Regards

Post Reply