Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

EKF: replacement of covariance prediction autocode with sympy generated output #870

Merged
merged 26 commits into from Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
432880c
added python script with ekf derivation (WIP)
RomanBapst Feb 27, 2020
4174859
worked on c code auto-generation
RomanBapst Mar 5, 2020
696f392
save before variable name change
RomanBapst Mar 11, 2020
4afbd7a
changed symbol names
RomanBapst Mar 11, 2020
6f27afd
added codegeneration class
RomanBapst Mar 14, 2020
4f5f6e1
improve 3D mag fusion derivation
RomanBapst Mar 17, 2020
6c019b8
EKF: Extend ekf sympy derivation to include all observation types
priseborough Jul 23, 2020
0e81ab5
EKF: Add custom ecl::powf function for integer powers
priseborough Jul 23, 2020
35e51ed
EKF: Convert ekf covariance prediction to use sympy output
priseborough Jul 23, 2020
1e1da84
EKF: Add test program to compare sympy and matlab covariance prediction
priseborough Jul 23, 2020
c36557a
EKF: simplify ecl::powf function
priseborough Jul 23, 2020
bf548be
Generate code to subfolder generated/
kamilritz Jul 23, 2020
29717d9
Add printouts for showing code generation progress
kamilritz Jul 23, 2020
63ca748
Move generated covariance code to generated folder
kamilritz Jul 23, 2020
a8b127e
Upgrade code generation to python3
kamilritz Jul 23, 2020
bdef8c1
main.py: Remove unused create_symbols function
kamilritz Jul 23, 2020
32b3c3c
main.py: move main part into function
kamilritz Jul 23, 2020
dfb7bb3
Code generation: fix passing wrong rotation matrix to yaw_observation ()
kamilritz Jul 23, 2020
55b8a61
EKF: Amend generated code filename for consistency
priseborough Jul 25, 2020
70399a6
Move ecl::powf function test to unit tests
priseborough Jul 25, 2020
0a71724
EKF: Use updated ecl:powf functionality in test program
priseborough Jul 25, 2020
c30686e
Move ecl::powf to utils.hpp
kamilritz Jul 26, 2020
4a88d14
Update ecl::powf test
kamilritz Jul 26, 2020
b51499a
Update output change indication
kamilritz Jul 26, 2020
b5db866
test: update expected output for change indicator
priseborough Jul 28, 2020
057ecb3
test: update expected output for change indicator again
priseborough Jul 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
728 changes: 455 additions & 273 deletions EKF/covariance.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions EKF/python/ekf_derivation/__init__.py
@@ -0,0 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 13:02:26 2020

@author: roman
"""

55 changes: 55 additions & 0 deletions EKF/python/ekf_derivation/code_gen.py
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 12:47:24 2020

@author: roman
"""
from sympy import ccode
from sympy.codegen.ast import float32, real

class CodeGenerator:
def __init__(self, file_name):
self.file_name = file_name
self.file = open(self.file_name, 'w')

def print_string(self, string):
self.file.write("// " + string + "\n")

def get_ccode(self, expression):
return ccode(expression, type_aliases={real:float32})

def write_subexpressions(self,subexpressions):
write_string = ""
for item in subexpressions:
write_string = write_string + "const float " + str(item[0]) + " = " + self.get_ccode(item[1]) + ";\n"

write_string = write_string + "\n\n"
self.file.write(write_string)

def write_matrix(self, matrix, identifier, is_symmetric=False):
write_string = ""

if matrix.shape[0] * matrix.shape[1] == 1:
write_string = write_string + identifier + " = " + self.get_ccode(matrix[0]) + ";\n"
elif matrix.shape[0] == 1 or matrix.shape[1] == 1:
for i in range(0,len(matrix)):
if (identifier == "Kfusion"):
# Vector f format used by Kfusion
write_string = write_string + identifier + "(" + str(i) + ") = " + self.get_ccode(matrix[i]) + ";\n"
else:
# legacy array format used by Hfusion
write_string = write_string + identifier + "[" + str(i) + "] = " + self.get_ccode(matrix[i]) + ";\n"
else:
for j in range(0, matrix.shape[1]):
for i in range(0, matrix.shape[0]):
if j >= i or not is_symmetric:
write_string = write_string + identifier + "(" + str(i) + "," + str(j) + ") = " + self.get_ccode(matrix[i,j]) + ";\n"
# legacy array format
# write_string = write_string + identifier + "[" + str(i) + "][" + str(j) + "] = " + self.get_ccode(matrix[i,j]) + ";\n"

write_string = write_string + "\n\n"
self.file.write(write_string)

def close(self):
self.file.close()
492 changes: 492 additions & 0 deletions EKF/python/ekf_derivation/generated/covariance_generated.cpp

Large diffs are not rendered by default.

955 changes: 955 additions & 0 deletions EKF/python/ekf_derivation/generated/covariance_generated_compare.cpp

Large diffs are not rendered by default.