Skip to content

Commit

Permalink
ekf2-derivation: build state struct based on type
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch committed Oct 30, 2024
1 parent f349294 commit 89c7788
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,21 @@ def generate_python_function(function_name, output_names):
def build_state_struct(state, T="float"):
out = "struct StateSample {\n"

def TypeFromLength(len):
if len == 1:
def get_px4_type(obj):
if isinstance(obj, sf.M11):
return f"{T}"
elif len == 2:
elif isinstance(obj, sf.M21):
return f"matrix::Vector2<{T}>"
elif len == 3:
elif isinstance(obj, sf.M31):
return f"matrix::Vector3<{T}>"
elif len == 4:
elif isinstance(obj, sf.Rot3):
return f"matrix::Quaternion<{T}>"
else:
print(f"unknown type {type(obj)}")
raise NotImplementedError

for key, val in state.items():
out += f"\t{TypeFromLength(val.storage_dim())} {key}{{}};\n"
out += f"\t{get_px4_type(val)} {key}{{}};\n"

state_size = state.storage_dim()
out += f"\n\tmatrix::Vector<{T}, {state_size}> Data() const {{\n" \
Expand Down

0 comments on commit 89c7788

Please sign in to comment.