mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-09 09:28:31 -04:00
AP_NavEKF3: derivation: auto-substitute optimized power functions
Avoids the need to manually insert them after generation.
This commit is contained in:
parent
f3a39105b9
commit
c880bf57cd
@ -9,11 +9,22 @@ class CodeGenerator:
|
|||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
self.file = open(self.file_name, 'w')
|
self.file = open(self.file_name, 'w')
|
||||||
|
|
||||||
|
# custom SymPy -> C function mappings. note that at least one entry must
|
||||||
|
# match, the last entry will always be used if none match!
|
||||||
|
self._custom_funcs = {
|
||||||
|
"Pow": [
|
||||||
|
(lambda b, e: e == 2, lambda b, e: f"sq({b})"), # use square function for b**2
|
||||||
|
(lambda b, e: e == -1, lambda b, e: f"1.0F/({b})"), # inverse
|
||||||
|
(lambda b, e: e == -2, lambda b, e: f"1.0F/sq({b})"), # inverse square
|
||||||
|
(lambda b, e: True, "powf"), # otherwise use default powf
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
def print_string(self, string):
|
def print_string(self, string):
|
||||||
self.file.write("// " + string + "\n")
|
self.file.write("// " + string + "\n")
|
||||||
|
|
||||||
def get_ccode(self, expression):
|
def get_ccode(self, expression):
|
||||||
return ccode(expression, type_aliases={real:float32})
|
return ccode(expression, type_aliases={real:float32}, user_functions=self._custom_funcs)
|
||||||
|
|
||||||
def write_subexpressions(self,subexpressions):
|
def write_subexpressions(self,subexpressions):
|
||||||
write_string = ""
|
write_string = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user