Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ekf2: fix symforce cmake code generation targets #23220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 24 additions & 37 deletions src/modules/ekf2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,19 @@

add_subdirectory(Utility)

option(EKF2_SYMFORCE_GEN "ekf2 generate symforce output" OFF)
option(EKF2_SYMFORCE_GEN "ekf2 generate symforce output" ON)

# Symforce code generation TODO:fixme
# Symforce code generation
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -m symforce.symbolic
RESULT_VARIABLE PYTHON_SYMFORCE_EXIT_CODE
OUTPUT_QUIET
)

# for now only provide symforce target helper if derivation.py generation isn't default
if((NOT CONFIG_EKF2_MAGNETOMETER) OR (NOT CONFIG_EKF2_WIND))
set(EKF2_SYMFORCE_GEN ON)
endif()

set(EKF_DERIVATION_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/EKF/python/ekf_derivation)

set(EKF_GENERATED_FILES ${EKF_DERIVATION_SRC_DIR}/generated/state.h)
set(EKF_GENERATED_DERIVATION_INCLUDE_PATH "${EKF_DERIVATION_SRC_DIR}/..")

if(EKF2_SYMFORCE_GEN AND (${PYTHON_SYMFORCE_EXIT_CODE} EQUAL 0))

# regenerate default in tree
add_custom_command(
OUTPUT
${EKF_DERIVATION_SRC_DIR}/generated/predict_covariance.h
${EKF_DERIVATION_SRC_DIR}/generated/state.h
COMMAND
${PYTHON_EXECUTABLE} ${EKF_DERIVATION_SRC_DIR}/derivation.py
DEPENDS
${EKF_DERIVATION_SRC_DIR}/derivation.py
${EKF_DERIVATION_SRC_DIR}/utils/derivation_utils.py

WORKING_DIRECTORY ${EKF_DERIVATION_SRC_DIR}
COMMENT "Symforce code generation (default)"
USES_TERMINAL
)

# generate to build directory
set(EKF_DERIVATION_DST_DIR ${CMAKE_CURRENT_BINARY_DIR}/ekf_derivation)
file(MAKE_DIRECTORY ${EKF_DERIVATION_DST_DIR})
Expand All @@ -91,28 +67,37 @@ if(EKF2_SYMFORCE_GEN AND (${PYTHON_SYMFORCE_EXIT_CODE} EQUAL 0))

add_custom_command(
OUTPUT
${EKF_DERIVATION_DST_DIR}/generated/predict_covariance.h
${EKF_DERIVATION_DST_DIR}/generated/state.h
${EKF_GENERATED_FILES}
COMMAND
${PYTHON_EXECUTABLE} ${EKF_DERIVATION_SRC_DIR}/derivation.py ${SYMFORCE_ARGS}
DEPENDS
${EKF_DERIVATION_SRC_DIR}/derivation.py
${EKF_DERIVATION_SRC_DIR}/utils/derivation_utils.py

WORKING_DIRECTORY ${EKF_DERIVATION_DST_DIR}
COMMENT "Symforce code generation"
USES_TERMINAL
COMMENT "ekf2 symforce code generation"
#USES_TERMINAL
)



add_custom_target(ekf2_symforce_generate
DEPENDS
${EKF_DERIVATION_SRC_DIR}/generated/predict_covariance.h
${EKF_DERIVATION_DST_DIR}/generated/predict_covariance.h
else()
# generation disabled or symforce not available, use pre-generated default files in tree (src/modules/ekf2/EKF/python/ekf_derivation/generated)
set(EKF_GENERATED_FILES ${EKF_DERIVATION_SRC_DIR}/generated/state.h)
set(EKF_GENERATED_DERIVATION_INCLUDE_PATH "${EKF_DERIVATION_SRC_DIR}/..")
endif()

# symforce in tree code generation helper
if(${PYTHON_SYMFORCE_EXIT_CODE} EQUAL 0)
# regenerate default symforce output in tree (src/modules/ekf2/EKF/python/ekf_derivation/generated)
add_custom_target(ekf2_generate_symforce_default
COMMAND ${PYTHON_EXECUTABLE} ${EKF_DERIVATION_SRC_DIR}/derivation.py
DEPENDS ${EKF_DERIVATION_SRC_DIR}/derivation.py
WORKING_DIRECTORY ${EKF_DERIVATION_SRC_DIR}
COMMENT "Symforce code generation (default)"
USES_TERMINAL
)
endif()

add_custom_target(ekf_symforce_generated DEPENDS ${EKF_GENERATED_FILES})

set(EKF_LIBS)
set(EKF_SRCS)
list(APPEND EKF_SRCS
Expand Down Expand Up @@ -257,9 +242,11 @@ px4_add_module(
px4_work_queue
world_magnetic_model

ekf_symforce_generated
${EKF_LIBS}
bias_estimator
output_predictor

UNITY_BUILD
)

Expand Down
2 changes: 1 addition & 1 deletion src/modules/ekf2/EKF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ add_library(ecl_EKF
${EKF_SRCS}
)

add_dependencies(ecl_EKF prebuild_targets)
add_dependencies(ecl_EKF prebuild_targets ekf_symforce_generated)
target_include_directories(ecl_EKF PUBLIC ${EKF_GENERATED_DERIVATION_INCLUDE_PATH})

target_link_libraries(ecl_EKF
Expand Down
Loading