leandro.martins Posted January 17, 2022 Share Posted January 17, 2022 I am implementing a servo algorithm in C and it's necessary a sign function: sgn(x)=-1, if x<0 sgn(x)=0, if x=0 sgn(x)=1, if x>0 Since this logic is used in the ServoCtrl algorithm in the Kfff gain, is there any better manner than an if-else statement? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Omron Forums Support Posted January 18, 2022 Share Posted January 18, 2022 There is a copysign function, but it won't work because copysign(1.0, 0.0)=1.0; copysign(1.0, InputVar); 1 Quote Link to comment Share on other sites More sharing options...
leandro.martins Posted January 31, 2022 Author Share Posted January 31, 2022 Thanks Eric, I noticed that I will need if-else anyway, but nice to know about this function for other purposes Quote Link to comment Share on other sites More sharing options...
Curt Wilson Posted February 4, 2022 Share Posted February 4, 2022 I've never understood why the C math library does not include the sgn function. We made sure to include it in the Script library because of its usefulness (which doesn't help you here, of course). We had to do the branching logic for the friction feedforward implementation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.