Hal component notzero???

More
07 Aug 2012 08:01 #22931 by grandixximo
is there an hal component that can get a float in, and send a digital output, 0 when the float is 0 and 1 when the float is anything other than 0 (positive or negative)????

Please Log in or Create an account to join the conversation.

More
07 Aug 2012 08:32 - 07 Aug 2012 12:49 #22933 by ArcEye
Replied by ArcEye on topic Re:Hal component notzero???
Hi

There could be a way to use match for instance , but this is dead simple and exactly what you asked for.
component notzero               "This component returns 1 if input zero";
pin in float fin = 0            "Receives float in";
pin out bit dout = false        "bit indicating if input zero";

function _;
author "ArcEye";
license "GPL";
;;

FUNCTION(_)
{
    if(fin == 0)
        dout = 1;
    else
        dout = 0;
}

regards

PS depending what exactly you want to achieve, you may want to set the initialiser for fin to 1
Last edit: 07 Aug 2012 12:49 by ArcEye. Reason: typos everywhere!

Please Log in or Create an account to join the conversation.

More
07 Aug 2012 08:44 #22934 by grandixximo
Actually i have follow the archivist suggestion on IRC, use component "comp", compare your float with a float zero, then read the equal pin out to see if your float is equal to zero, you even get hyst which is a tolerance parameter!!!

Thank you anyway :P

Please Log in or Create an account to join the conversation.

Time to create page: 0.085 seconds
Powered by Kunena Forum