Page 1 of 1
Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 7:53 pm
by jay_dee
Hi,
Does FC have an ABS ( Absolute ) function?
I have a current sensor and get both positive and Negative Values.
Is there a Calculation Function that will always return positive Value. I thought C had an ABS function.
If the Float Abs function is used, the compiler throws an error.
thanks, J.
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 8:08 pm
by chipfryer27
Hi
Are you supposed to be getting negative values, which would suggest a reversal of flow?
Regards
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 8:12 pm
by jay_dee
Hi, Yeah absolutly. It is a H Bridge driven DC motor. I use the current to define the 'Clamping' force and hard limits of the driven assembly. J.
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 8:41 pm
by chipfryer27
Hi
OK, just curious.
I assume you are getting a 2's compliment return?
If for example x = -27 could you not use x = fabs(x) to give 27 ?
Regards
PS
The above simulates but can't try compiling to hex yet as I need to install the compilers on this little machine I'm using
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 9:09 pm
by jay_dee
Hi,
Ahhh.... Fabs(Value) this will not pass
but fabs(value) will pass the compiler.
it was not a problem with the function but with my capitalisation! doh!
FC usually lets me play fast and loose with capitalisation but not in this case!
Thanks.
OK...back to fixing the bigger project!!
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 9:15 pm
by chipfryer27
Haha
Many times I have been caught out similarly and spent way, way too long chasing.....
Glad it is working now
Regards
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 9:24 pm
by jay_dee
appologies to the FC team, I think it might have been a even more basic mistake and not the capitialisation....
REVERSE...REVERSE...back away from the situation!!! haha!
Re: Absolute ABS Function for Integers?
Posted: Thu Jun 26, 2025 10:40 pm
by chipfryer27
Disengaging Panic Circuits...???