Decision with floating variable
Moderator: Benj
Decision with floating variable
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
-
- 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
Hi.
Can you post your project file (.fcfx extension), so we can have a look for you?
Can you post your project file (.fcfx extension), so we can have a look for you?
Martin
-
- Valued Contributor
- Posts: 1189
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: Decision with floating variable
Hi dagr.
Please could you post your code-- someone will be able to help you then...
Martin
Please could you post your code-- someone will be able to help you then...
Martin
- 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
Hello,
If the variable D is a float then you might want to make your comparison value a float as well.
D <= 10.0
If the variable D is a float then you might want to make your comparison value a float as well.
D <= 10.0
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 663
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 184 times
- Been thanked: 203 times
- Contact:
Re: Decision with floating variable
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
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