### Python Bindings Example Source: https://github.com/collabora/libsurvive/blob/master/README.md This Python code demonstrates how to initialize the SimpleContext, list objects, and continuously print updated object names and poses. Ensure `pysurvive` is installed. ```python import pysurvive import sys actx = pysurvive.SimpleContext(sys.argv) for obj in actx.Objects(): print(obj.Name()) while actx.Running(): updated = actx.NextUpdated() if updated: print(updated.Name(), updated.Pose()) ``` -------------------------------- ### Install Library Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Installs the mpfit library to the lib directory. ```cmake install(TARGETS mpfit DESTINATION lib) ``` -------------------------------- ### Install Survive Library Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Installs the main survive library to the specified destination directory. ```cmake install(TARGETS survive DESTINATION ${LIB_INSTALL_DIR}) ``` -------------------------------- ### Launch libsurvive Visualization Source: https://github.com/collabora/libsurvive/blob/master/README.md Start the websocket server and open the visualization tool in the default browser. ```bash ./bin/survive-websocketd & xdg-open ./tools/viz/index.html ``` -------------------------------- ### Install Built Plugins Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Installs all registered survive plugins to the specified destination directory. ```cmake install(TARGETS ${SURVIVE_BUILT_PLUGINS} DESTINATION ${LIB_INSTALL_DIR}libsurvive/plugins) ``` -------------------------------- ### Execute libsurvive CLI Source: https://github.com/collabora/libsurvive/blob/master/README.md Run the command line interface to calibrate and display the tracking setup. ```bash ./bin/survive-cli ``` -------------------------------- ### Define Plugin Installation Directory Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Sets the installation directory for libraries based on the Windows platform or a default for other platforms. ```cmake if(WIN32) SET(LIB_INSTALL_DIR "bin/${CMAKE_GENERATOR_PLATFORM}/" CACHE STRING "") else() SET(LIB_INSTALL_DIR "lib/" CACHE STRING "") endif() ``` -------------------------------- ### Initialize and run a Kalman filter in C Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/README.md Demonstrates the basic setup of a Kalman filter state, measurement models, and the prediction-update cycle. ```C #include #include static inline void kalman_transition_model_fn(FLT dt, const struct cnkalman_state_s *k, const struct CnMat *x0, struct CnMat *x1, struct CnMat *F) { // Logic to fill in the next state x1 and the associated transition matrix F } static inline void kalman_process_noise_fn(void *user, FLT dt, const struct CnMat *x, struct CnMat *Q) { // Logic to fill in the process covariance Q } static inline bool kalman_measurement_model_fn(void *user, const struct CnMat *Z, const struct CnMat *x_t, struct CnMat *y, struct CnMat *H_k) { // Logic to fill in the residuals `y`, and the jacobian of the predicted measurement function `h` return false; // This should return true if the jacobian and evaluation were valid. } int main() { int state_cnt = 1; cnkalman_state_t kalman_state = { 0 }; cnkalman_state_init(&kalman_state, state_cnt, kalman_transition_model_fn, kalman_process_noise_fn, 0, 0); // Uncomment the next line if you want to use numerical jacobians for the transition matrix //kalman_state.transition_jacobian_mode = cnkalman_jacobian_mode_two_sided; cnkalman_meas_model_t kalman_meas_model = { 0 }; cnkalman_meas_model_init(&kalman_state, "Example Measurement", &kalman_meas_model, kalman_measurement_model_fn); // Uncomment the next line if you want to use numerical jacobians for this measurement // kalman_meas_model.meas_jacobian_mode = cnkalman_jacobian_mode_two_sided; CnMat Z, R; // Logic to fill in measurement matrix Z and measurement covariance matrix R cnkalman_meas_model_predict_update(1, &kalman_meas_model, 0, &Z, &R); printf("Output:%f\n", cn_as_vector(&kalman_state.state)[0]); return 0; } ``` -------------------------------- ### Install Bash Autocompletion Source: https://github.com/collabora/libsurvive/blob/master/README.md Install bash autocompletion for libsurvive to easily access and use command-line options. ```bash sudo cp survive_autocomplete.sh /etc/bash_completion.d/ ``` -------------------------------- ### Build and Run libsurvive on Debian Source: https://github.com/collabora/libsurvive/blob/master/README.md Commands to clone the repository, install dependencies, and build the project on Debian-based systems. ```bash git clone https://github.com/cntools/libsurvive.git cd libsurvive sudo cp ./useful_files/81-vive.rules /etc/udev/rules.d/ sudo udevadm control --reload-rules && sudo udevadm trigger sudo apt update && sudo apt install build-essential zlib1g-dev libx11-dev libusb-1.0-0-dev freeglut3-dev liblapacke-dev libopenblas-dev libatlas-base-dev cmake make ``` -------------------------------- ### Install udev rules for Linux Source: https://github.com/collabora/libsurvive/blob/master/README.md Required for Linux users to access Vive devices without root privileges. ```bash sudo cp ./useful_files/81-vive.rules to /etc/udev/rules.d/ sudo udevadm control --reload-rules && udevadm trigger ``` -------------------------------- ### Windows Runtime Dependency Installation Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt On Windows, this block installs runtime dependencies for the 'survive' and 'driver_vive' targets, resolving and copying necessary libraries. ```cmake if(WIN32) if(NOT USE_HIDAPI) cmake_policy(SET CMP0087 NEW) install(CODE "set(CMAKE_GENERATOR_PLATFORM \"${CMAKE_GENERATOR_PLATFORM}\")") install(CODE "set(LIB_INSTALL_DIR \"${LIB_INSTALL_DIR}\")") install(CODE "set(WIN_PLATFORMx \"${WIN_PLATFORMx}\")") install(CODE [[ file(GET_RUNTIME_DEPENDENCIES LIBRARIES $ $ RESOLVED_DEPENDENCIES_VAR _r_deps UNRESOLVED_DEPENDENCIES_VAR _u_deps POST_EXCLUDE_REGEXES ".*[Ww][Ii][Nn][Dd][Oo][Ww][Ss][/\][Ss]ystem32.*" DIRECTORIES ${CMAKE_BINARY_DIR}/packages/libusb.1.0.21/lib/native/${WIN_PLATFORMx}/ ) message("Resolved: ${_r_deps} unresolved: ${_u_deps}") foreach(_file ${_r_deps}) file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" TYPE SHARED_LIBRARY FILES "${_file}" ) endforeach() ]]) endif() endif() ``` -------------------------------- ### Configure cnkalman CMake build Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/src/CMakeLists.txt Defines the static library target, include paths, dependencies, and installation destination. ```cmake add_library(cnkalman STATIC kalman.c ./model.cc ./numerical_diff.c ./iekf.c ./ModelPlot.cc ../include/cnkalman/kalman.h) target_include_directories(cnkalman PUBLIC $ $ ) target_link_libraries(cnkalman cnmatrix) install(TARGETS cnkalman DESTINATION lib) ``` -------------------------------- ### Find OpenVR libraries and include paths Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Locates the OpenVR libraries and header files. It searches common installation paths and specific subdirectories for different platforms. ```cmake find_library(OPENVR_LIBRARIES NAMES openvr_api openvr_api64 PATH_SUFFIXES osx32 linux64 PATHS "C:/Program Files (x86)/OpenVRSDK/lib" ) find_path(OPENVR_INCLUDE_PATH NAMES openvr.h openvr_driver.h PATH_SUFFIXES openvr "C:/Program Files (x86)/OpenVRSDK/include" ) ``` -------------------------------- ### Initialize and poll libsurvive in C# Source: https://github.com/collabora/libsurvive/blob/master/README.md Example of using the SurviveAPI to poll for object position updates and button events in a console application. ```csharp using libsurvive; using System; namespace Demo { class Program { static void Main() { string[] args = System.Environment.GetCommandLineArgs(); var api = new SurviveAPI(args); while (api.WaitForUpdate()) { SurviveAPIOObject obj; while ((obj = api.GetNextUpdated()) != null) { Console.WriteLine(obj.Name + ": " + obj.LatestPose); } } api.Close(); } } } ``` -------------------------------- ### Enable USBMON Driver Source: https://github.com/collabora/libsurvive/blob/master/README.md These commands are necessary to enable the usbmon driver for raw USB data capture. Ensure libpcap is installed. ```bash sudo modprobe usbmon sudo setfacl -m u:$USER:r /dev/usbmon* ``` -------------------------------- ### SURVIVE_REGISTER_PLUGIN Function Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt A CMake function to register and configure a plugin library, including setting properties and installation rules. ```cmake function(SURVIVE_REGISTER_PLUGIN PLUGIN) IF(NOT TARGET ${PLUGIN}) SET(SRC ${PLUGIN}.c) if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC}) SET(SRC ${PLUGIN}.cc) endif() add_library(${PLUGIN} ${SURVIVE_LIBRARY_TYPE} ${SRC} ${${PLUGIN}_ADDITIONAL_SRCS}) target_link_libraries(${PLUGIN} survive ${${PLUGIN}_ADDITIONAL_LIBS}) set_target_properties(${PLUGIN} PROPERTIES INSTALL_RPATH "$ORIGIN/../..;$ORIGIN") ENDIF() target_link_libraries(${PLUGIN} survive) list(APPEND SURVIVE_BUILT_PLUGINS ${PLUGIN}) set(SURVIVE_BUILT_PLUGINS "${SURVIVE_BUILT_PLUGINS}" PARENT_SCOPE) add_dependencies(survive_plugins ${PLUGIN}) STRING(REGEX REPLACE "(.*)\_.*" "\1" plugin_type "${PLUGIN}") if(plugin_type) set_target_properties(${PLUGIN} PROPERTIES FOLDER "${plugin_type}") endif() set(OUTPUT_DIR "$/")#set(OUTPUT_DIR "${survive_location}") if(NOT BUILD_STATIC) set_target_properties(${PLUGIN} PROPERTIES PREFIX "") endif() set(PLUGIN_SUFFIX "plugins") set_target_properties(${PLUGIN} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}${PLUGIN_SUFFIX}") set_target_properties(${PLUGIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}${PLUGIN_SUFFIX}") #set_target_properties(${PLUGIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}Debug/plugins") #set_target_properties(${PLUGIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}Release/plugins") #set_target_properties(${PLUGIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIR}RelWithDebInfo/plugins") install(TARGETS ${PLUGIN} DESTINATION ${LIB_INSTALL_DIR}libsurvive/${PLUGIN_SUFFIX}) endfunction() ``` -------------------------------- ### Integrate libsurvive with Unity Update loop Source: https://github.com/collabora/libsurvive/blob/master/README.md Example of mapping libsurvive pose data to a Unity GameObject transform within the Update method. ```csharp // Update is called once per frame void Update() { var updated = survive?.GetNextUpdated(); if (updated == null) return; var updatedObject = getObject(updated.Name); Vector3 newPosition = Vector3.zero; Quaternion newRotation = Quaternion.identity; SurvivePose pose = updated.LatestPose; newPosition.x = (float) pose.Pos[0]; newPosition.y = (float) pose.Pos[1]; newPosition.z = (float) pose.Pos[2]; newRotation.w = (float) pose.Rot[0]; newRotation.x = (float) pose.Rot[1]; newRotation.y = (float) pose.Rot[2]; newRotation.z = (float) pose.Rot[3]; updatedObject.transform.localPosition = newPosition; updatedObject.transform.localRotation = newRotation; } ``` -------------------------------- ### Record Raw USB Data Source: https://github.com/collabora/libsurvive/blob/master/README.md Use this command to start recording raw USB data to a compressed pcap file. Additional options for the htcvive driver can be appended. ```bash ./survive-cli --usbmon-record .pcap.gz --htcvive ``` -------------------------------- ### Generated C Function Signatures Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/README.md These are example C function signatures generated by cnkalman's code generation process. They include functions for the prediction/measurement logic and their corresponding Jacobian calculations with respect to the state. ```c static inline void gen_predict_function(CnMat* out, const FLT dt, const FLT wheelbase, const FLT* state, const FLT* u); static inline void gen_predict_function_jac_state(CnMat* Hx, const FLT dt, const FLT wheelbase, const FLT* state, const FLT* u); ``` -------------------------------- ### Disable Default Driver Source: https://github.com/collabora/libsurvive/blob/master/README.md To disable a default driver, use the --no- flag. For example, to disable the htcvive driver, use --no-htcvive. ```bash --no- ``` -------------------------------- ### Package Logs for Sharing Source: https://github.com/collabora/libsurvive/blob/master/README.md This command creates a zip archive containing recorded data files and configuration, suitable for sharing for analysis. ```bash zip logs.zip *.pcap* config.json ``` -------------------------------- ### Build libsurvive C# bindings Source: https://github.com/collabora/libsurvive/blob/master/README.md Command to compile the C# project and generate the required DLL binary. ```bash dotnet build -c Release ``` -------------------------------- ### Link visualize_mpfit with Libraries Source: https://github.com/collabora/libsurvive/blob/master/tools/visualize_mpfit/CMakeLists.txt Links the 'visualize_mpfit' executable against the 'survive' and 'driver_simulator' libraries. ```cmake target_link_libraries(visualize_mpfit survive driver_simulator) ``` -------------------------------- ### Pre-process Lighthouse Data Source: https://github.com/collabora/libsurvive/blob/master/tools/plot_lighthouse/README.txt Run lighthousefind to extract lighthouse positions and redirect the output to L.txt and R.txt. Ensure these files are in the same directory as the plotting program. ```bash lighthousefind L processed_data.txt > L.txt lighthousefind R processed_data.txt > R.txt ``` -------------------------------- ### Configure BLAS Backend Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Selects between OpenBLAS or system-provided CBLAS and configures include directories. ```cmake if(USE_OPENBLAS OR WIN32) set(BLAS_BACKEND "openblas") include_directories(openblas) else() set(BLAS_BACKEND "${CBLAS_LOCATION}") find_file(CBLAS_FULL_PATH cblas.h HINT "/usr/local/opt/openblas/include") message("Searching for 'cblas.h'; found at ${CBLAS_FULL_PATH}") IF(CBLAS_FULL_PATH) get_filename_component(CBLAS_PATH ${CBLAS_FULL_PATH} DIRECTORY) include_directories( ${CBLAS_PATH}) ENDIF() endif() ``` -------------------------------- ### Add subdirectories for libraries and source code Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Includes subdirectories for cnmatrix, cnkalman, redist, src, and tools, integrating their build processes. ```cmake add_subdirectory(libs/cnmatrix) add_subdirectory(libs/cnkalman) add_subdirectory(redist) add_subdirectory(src) add_subdirectory(tools) ``` -------------------------------- ### Report Backend Status Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Logs the currently selected backend to the console. ```cmake if(USE_EIGEN) message("Using eigen backend") else() message("Using blas backend ${BLAS_BACKEND}") endif() ``` -------------------------------- ### Add visualize_mpfit Executable Source: https://github.com/collabora/libsurvive/blob/master/tools/visualize_mpfit/CMakeLists.txt Defines an executable target named 'visualize_mpfit' and specifies its source file as 'visualize_mpfit.c'. ```cmake add_executable(visualize_mpfit visualize_mpfit.c) ``` -------------------------------- ### Include OpenVR Directories and Libraries Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Conditionally includes directories and sets libraries for the OpenVR driver if OpenVR is found and single precision is not used. ```cmake if(OPENVR_LIBRARIES AND NOT USE_SINGLE_PRECISION) include_directories(redist include/libsurvive include ${OPENVR_INCLUDE_PATH}) LIST(APPEND PLUGINS driver_openvr) set(driver_openvr_ADDITIONAL_LIBS ${OPENVR_LIBRARIES}) endif() ``` -------------------------------- ### Enable testing Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Enables the testing framework if ENABLE_TESTS is set to ON. ```cmake IF(ENABLE_TESTS) enable_testing() ENDIF() ``` -------------------------------- ### Configure RPATH settings Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Configures RPATH settings for the build, disabling skipping and build-with-install RPATH, and enabling use of link path. ```cmake SET(CMAKE_SKIP_BUILD_RPATH FALSE) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) ``` -------------------------------- ### C High-Level API Main Loop Source: https://github.com/collabora/libsurvive/blob/master/README.md This C code demonstrates the main loop for the high-level API, processing updated object poses. Ensure `keepRunning` is managed appropriately. ```c while (survive_simple_wait_for_update(actx) && keepRunning) { for (const SurviveSimpleObject *it = survive_simple_get_next_updated(actx); it != 0; it = survive_simple_get_next_updated(actx)) { SurvivePose pose; uint32_t timecode = survive_simple_object_get_latest_pose(it, &pose); printf("%s %s (%u): %f %f %f %f %f %f %f\n", survive_simple_object_name(it), survive_simple_serial_number(it), timecode, pose.Pos[0], pose.Pos[1], pose.Pos[2], pose.Rot[0], pose.Rot[1], pose.Rot[2], pose.Rot[3]); } } ``` -------------------------------- ### Force Calibration with OOTX Source: https://github.com/collabora/libsurvive/blob/master/README.md Use the --force-calibrate flag to rerun calibration while reusing existing OOTX data, significantly speeding up the process. ```bash --force-calibrate ``` -------------------------------- ### Register Enabled Plugins Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Iterates through the list of plugins, enables them based on build options, and registers them using the SURVIVE_REGISTER_PLUGIN function. ```cmake foreach(PLUGIN ${PLUGINS}) VERBOSE_OPTION(ENABLE_${PLUGIN} "Build ${PLUGIN}" ${NOT_CORE_BUILD}) if(ENABLE_${PLUGIN}) SURVIVE_REGISTER_PLUGIN(${PLUGIN}) endif() endforeach() ``` -------------------------------- ### Configure CNGFX Library Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Defines source files and platform-specific drivers for the CNGFX library. ```cmake set(CNGFX_SRCS ./CNFG3D.c ./CNFGFunctions.c) IF(UNIX) check_include_file("X11/Xlib.h" HAVE_X11_H) IF(HAVE_X11_H) list(APPEND CNGFX_SRCS ./CNFGXDriver.c) set(CNGFX_LIBS X11) else() SET(CNGFX_SRCS) endif() elseif(WIN32) list(APPEND CNGFX_SRCS ./CNFGWinDriver.c) endif() if(CNGFX_SRCS) add_library(CNGFX ${CNGFX_SRCS}) set_target_properties(CNGFX PROPERTIES FOLDER "libraries") target_link_libraries(CNGFX ${CNGFX_LIBS}) endif() ``` -------------------------------- ### Configure .NET runtime flags Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Sets .NET runtime flags based on the Windows architecture (x64 or x86) if the 'dotnet' command is found. ```cmake find_program(DOTNET dotnet) if(DOTNET) SET(DOTNET_RUNTIME_FLAGS "") if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8) #SET(DOTNET_RUNTIME_FLAGS "--runtime;win-x64") elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) #SET(DOTNET_RUNTIME_FLAGS "--runtime;win-x86") endif() endif() message("${DOTNET} build -c Release ${DOTNET_RUNTIME_FLAGS}") execute_process( ``` -------------------------------- ### Register a Custom Driver Source: https://github.com/collabora/libsurvive/blob/master/README.md The entry point for a custom driver, which must return a status code and be registered using the REGISTER_LINKTIME macro. ```C int DriverRegExample(SurviveContext *ctx) { if(...error...) { return SURVIVE_DRIVER_ERROR; } return SURVIVE_DRIVER_NORMAL; } REGISTER_LINKTIME(DriverRegExample) ``` -------------------------------- ### Force Lighthouse Generation Source: https://github.com/collabora/libsurvive/blob/master/README.md Use --lighthouse-gen to manually specify the lighthouse generation when the system misidentifies base stations. ```bash --lighthouse-gen ``` -------------------------------- ### Add post-build command for survive-cli Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Adds a post-build command to copy the survive-websocketd script to the output directory of the survive-cli executable if the target exists. ```cmake IF(TARGET survive-cli) add_custom_command(TARGET survive-cli POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SURVIVE_WEBSOCKETD} $ ) install(PROGRAMS ${SURVIVE_WEBSOCKETD} DESTINATION bin/${CMAKE_GENERATOR_PLATFORM}) ENDIF() ``` -------------------------------- ### Define Test Suites Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/tests/CMakeLists.txt Registers benchmarks and model tests using add_test. ```cmake add_test(NAME runbenchmarks COMMAND ${CMAKE_COMMAND} -Dcnkalman_root_source_dir=${cnkalman_root_source_dir} -DTEST_KALMAN_MODELS=$ -DBENCHMARK_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/benchmark.py -P ${CMAKE_CURRENT_SOURCE_DIR}/runbenchmarks.cmake) add_test(NAME TestKalmanModels COMMAND TestKalmanModels) ``` -------------------------------- ### Add Survive Plugins Target Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Creates a custom target for building all survive plugins. ```cmake add_custom_target(survive_plugins) ``` -------------------------------- ### Define path for survive-websocketd Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Sets the path for the survive-websocketd script, using a .ps1 extension for Windows. ```cmake SET(SURVIVE_WEBSOCKETD ${CMAKE_CURRENT_SOURCE_DIR}/useful_files/survive-websocketd) if(WIN32) SET(SURVIVE_WEBSOCKETD ${CMAKE_CURRENT_SOURCE_DIR}/useful_files/survive-websocketd.ps1) endif() ``` -------------------------------- ### Registering a Custom Poser Source: https://github.com/collabora/libsurvive/blob/master/docs/writing_a_poser.md Implement a function with the 'Poser' prefix and use the REGISTER_LINKTIME macro to register it. Return -1 for unhandled input types. ```c #include "survive.h" int PoserMyPoser(SurviveObject *so, PoserFnData *pd) { switch (pd->pt) { case POSERDATA_LIGHT: { PoserDataLight *lightData = (PoserDataLight *)pd; return -1; } case POSERDATA_FULL_SCENE: { PoserDataFullScene pdfs = (PoserDataFullScene *)(pd); return -1; } case POSERDATA_IMU: { PoserDataIMU *imuData = (PoserDataIMU *)pd; return -1; } return -1; } REGISTER_LINKTIME(PoserMyPoser); ``` -------------------------------- ### Generate Kalman Models and Build Test Executables Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/tests/CMakeLists.txt Uses cnkalman_generate_code to process model definitions and links the resulting executables against the cnkalman library. ```cmake include_directories(../include) include_directories(.) cnkalman_generate_code(./models/BikeLandmarks.py) cnkalman_generate_code(./models/BearingsOnlyTracking.py) cnkalman_generate_code(./models/EggLandscape.py) cnkalman_generate_code(./models/BearingAccel.py) add_executable(TestKalmanModels ModelRunner.cc TestKalmanModels.cc models/LinearPoseVel.h ./models/BikeLandmarks.gen.h ./models/EggLandscape.gen.h ./models/BearingsOnlyTracking.gen.h ./models/BearingAccel.gen.h) target_link_libraries(TestKalmanModels cnkalman) add_executable(kalman_example kalman_example.c) target_link_libraries(kalman_example cnkalman) ``` -------------------------------- ### Define mpfit Library Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Adds the mpfit static library and links it against cnmatrix. ```cmake add_library(mpfit STATIC mpfit/mpfit.c) target_link_libraries(mpfit cnmatrix) set_target_properties(mpfit PROPERTIES LINKER_LANGUAGE C) set_target_properties(mpfit PROPERTIES FOLDER "libraries") ``` -------------------------------- ### Find Library Path Macro Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt A helper macro to locate libraries and provide feedback via messages. ```cmake macro(find_library_path var pkg) find_library(${var}_RAWFIND ${pkg} ${ARGN}) if(${var}_RAWFIND) set(${var} ${${var}_RAWFIND}) message("Found ${pkg} at ${${var}}") else() message("Could not find ${pkg}") set(${var} ${pkg}) endif() endmacro() find_library_path(CBLAS_LOCATION cblas HINTS /usr/local/opt/openblas/lib) find_library_path(OPENBLAS_LOCATION openblas HINTS /usr/local/opt/openblas/lib) find_library_path(LAPACKE_LOCATION lapacke HINTS /usr/local/opt/lapack/lib) ``` -------------------------------- ### Configure cnmatrix build system Source: https://github.com/collabora/libsurvive/blob/master/libs/cnmatrix/src/CMakeLists.txt This CMake script defines source files, manages dependencies for Eigen or BLAS backends, and configures library targets. ```cmake SET(CN_MATRIX_SRCS ../include/cnmatrix/cn_matrix.h cn_matrix.c) IF(USE_EIGEN) SET(CN_MATRIX_SRCS ${CN_MATRIX_SRCS} eigen/core.cpp eigen/gemm.cpp eigen/svd.cpp eigen/internal.h) ELSE() SET(CN_MATRIX_SRCS ${CN_MATRIX_SRCS} cn_matrix.blas.c) ENDIF() IF(WIN32) set(packages_config "") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/packages.config ${packages_config}) ADD_DEFINITIONS(-DHAVE_LAPACK_CONFIG_H -DLAPACK_COMPLEX_STRUCTURE) set(CN_MATRIX_SRCS ${CN_MATRIX_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/packages.config) endif() macro(find_library_path var pkg) find_library(${var}_RAWFIND ${pkg} ${ARGN}) if(${var}_RAWFIND) set(${var} ${${var}_RAWFIND}) message("Found ${pkg} at ${${var}}") else() message("Could not find ${pkg}") set(${var} ${pkg}) endif() endmacro() find_library_path(CBLAS_LOCATION cblas HINTS /usr/local/opt/openblas/lib) find_library_path(OPENBLAS_LOCATION openblas HINTS /usr/local/opt/openblas/lib) find_library_path(LAPACKE_LOCATION lapacke HINTS /usr/local/opt/lapack/lib) if(USE_OPENBLAS OR WIN32) set(BLAS_BACKEND "openblas") include_directories(openblas) else() set(BLAS_BACKEND "${CBLAS_LOCATION}") find_file(CBLAS_FULL_PATH cblas.h HINT "/usr/local/opt/openblas/include") message("Searching for 'cblas.h'; found at ${CBLAS_FULL_PATH}") IF(CBLAS_FULL_PATH) get_filename_component(CBLAS_PATH ${CBLAS_FULL_PATH} DIRECTORY) include_directories( ${CBLAS_PATH}) ENDIF() endif() check_include_file(lapacke/lapacke.h LAPACKE_FILE) if(LAPACKE_FILE) add_definitions(-DLAPACKE_FOLDER) endif() if(USE_EIGEN) message("Using eigen backend") else() message("Using blas backend ${BLAS_BACKEND}") endif() add_library(cnmatrix STATIC ${CN_MATRIX_SRCS}) target_include_directories(cnmatrix PUBLIC $ $) if(USE_SINGLE_PRECISION) target_compile_definitions(cnmatrix PUBLIC CN_USE_FLOAT) endif() set_target_properties(cnmatrix PROPERTIES FOLDER "libraries") IF(USE_EIGEN) add_definitions ( ${EIGEN3_DEFINITIONS} ) include_directories ( ${EIGEN3_INCLUDE_DIR} ) if(WIN32) target_compile_options(cnmatrix PRIVATE -bigobj) else() target_compile_options(cnmatrix PRIVATE -fno-exceptions -fPIC) endif() ELSE() IF(UNIX) target_link_libraries(cnmatrix ${BLAS_BACKEND} ${LAPACKE_LOCATION} m) elseif(WIN32) include_directories(${CMAKE_BINARY_DIR}/packages/OpenBLAS.0.2.14.1/lib/native/include/) target_link_libraries(cnmatrix ${CMAKE_BINARY_DIR}/packages/OpenBLAS.0.2.14.1/lib/native/lib/${WIN_PLATFORM}/libopenblas.dll.a ) ENDIF() ENDIF() install(TARGETS cnmatrix DESTINATION lib) ``` -------------------------------- ### Plot Lighthouse and HMD Data Source: https://github.com/collabora/libsurvive/blob/master/tools/plot_lighthouse/README.txt Pipe the processed raw capture data into the plot_lighthouse program for visualization. This step requires the output files from the previous step to be present. ```bash ../../tools/process_rawcap/process_to_points [raw data.csv] | ./plot_lighthouse ``` -------------------------------- ### Build executables based on SURVIVE_EXECUTABLES list Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Iterates through a list of executables, enabling their build based on specific conditions (e.g., WIN32 for survive-cli). Links against the survive library and thread libraries. ```cmake SET(SURVIVE_EXECUTABLES survive-cli api_example sensors-readout survive-solver survive-buttons) foreach(executable ${SURVIVE_EXECUTABLES}) VERBOSE_OPTION(ENABLE_${executable} "Build ${executable}" ${BUILD_APPLICATIONS}) if(${executable} STREQUAL "survive-cli" AND WIN32) set(ENABLE_survive-cli ON) endif() if(ENABLE_${executable}) add_executable(${executable} ${executable}.c ) target_link_libraries(${executable} survive ${${executable}_ADDITIONAL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(${executable} PROPERTIES FOLDER "apps") foreach(plugin ${SURVIVE_BUILT_PLUGINS}) add_dependencies(${executable} ${plugin}) endforeach() install(TARGETS ${executable} DESTINATION bin/${CMAKE_GENERATOR_PLATFORM}) endif() endforeach() ``` -------------------------------- ### Check for zlib.h header and Android environment Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Checks for the zlib.h header. If it's missing or the build is for Android, NOZLIB is defined. ```cmake check_include_file("zlib.h" HAVE_ZLIB_H) IF(NOT HAVE_ZLIB_H OR ANDROID) add_definitions(-DNOZLIB) ENDIF() ``` -------------------------------- ### Add Simple Pose Test Executable Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Conditionally adds the 'simple_pose_test' executable and its libraries if the CNGFX target is enabled. ```cmake IF(TARGET CNGFX) list(APPEND SURVIVE_EXECUTABLES simple_pose_test) set(simple_pose_test_ADDITIONAL_LIBS CNGFX) endif() ``` -------------------------------- ### Playback Recorded USB Data Source: https://github.com/collabora/libsurvive/blob/master/README.md This command replays a previously recorded raw USB data file. The playback speed can be adjusted using the --playback-factor option. ```bash ./survive-cli --usbmon-playback .pcap.gz [--playback-factor x] ``` -------------------------------- ### Configure C and C++ compiler flags for Unix-like systems Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Sets common compiler flags for Unix-like systems, including PIC, warnings, visibility, and error settings. Also configures C++ standard to c++14. ```cmake IF(UNIX) set(SHARED_FLAGS "-fPIC -Wall -Wno-unused-variable -Wno-switch -Wno-parentheses -Wno-missing-braces -Werror=return-type -fvisibility=hidden -Werror=vla -fno-math-errno -Werror=pointer-arith") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SHARED_FLAGS} -std=gnu99 -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=missing-field-initializers ") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SHARED_FLAGS} -std=c++14") if(USE_CPU_TUNE) add_compile_options("-mtune=native") endif() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic") if(ENABLE_WARNINGS_AS_ERRORS) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") endif() if(USE_ASAN) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined") endif() if(USE_MSAN) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fsanitize=undefined") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fsanitize=undefined") endif() ENDIF() ``` -------------------------------- ### Check LAPACKE Header Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Checks for the existence of lapacke.h and sets a preprocessor definition if found. ```cmake check_include_file(lapacke/lapacke.h LAPACKE_FILE) if(LAPACKE_FILE) add_definitions(-DLAPACKE_FOLDER) endif() ``` -------------------------------- ### Configure Test Executable Source: https://github.com/collabora/libsurvive/blob/master/redist/CMakeLists.txt Compiles and registers the lintest executable if testing is enabled. ```cmake IF (ENABLE_TESTS) add_executable(lintest linmath.c linmath.h lintest.c) target_link_libraries(lintest cnmatrix) set_target_properties(lintest PROPERTIES FOLDER "tests") add_test(NAME lintest COMMAND lintest) ENDIF() ``` -------------------------------- ### Add Test Cases Subdirectory Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Includes the test_cases subdirectory if tests are enabled. ```cmake IF (ENABLE_TESTS) add_subdirectory(test_cases) ENDIF() ``` -------------------------------- ### Playback recorded tracking data Source: https://github.com/collabora/libsurvive/blob/master/README.md Command to playback a previously recorded .rec.gz data file using the survive-cli tool. ```bash ./survive-cli --playback .rec.gz ``` -------------------------------- ### CMake Build Configuration for cnmatrix_test Source: https://github.com/collabora/libsurvive/blob/master/libs/cnmatrix/tests/CMakeLists.txt Configures the build environment for the cnmatrix_test executable, including dependency linking and test registration. ```cmake include_directories(../include) add_executable(cnmatrix_test cn_matrixtest.c) target_link_libraries(cnmatrix_test cnmatrix) add_test(NAME cnmatrix_test COMMAND cnmatrix_test) ``` -------------------------------- ### Check for gattlib.h header Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Checks if the gattlib.h header file is available. This is used to conditionally enable gatt support. ```cmake check_include_file("gattlib.h" HAVE_GATTLIB_H) VERBOSE_OPTION(BUILD_GATT_SUPPORT "Whether or not to include gatt support for the basestations -- requires gattlib (https://github.com/labapart/gattlib)" ${HAVE_GATTLIB_H}) ``` -------------------------------- ### Find and configure Threads package Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Finds the Threads package, preferring pthread on POSIX systems. ```cmake set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) ``` -------------------------------- ### Set Visual Studio specific properties for survive-cli on Windows Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Sets a VS_USER_PROPS property for the 'survive-cli' target on Windows, likely to include OpenBLAS build targets. ```cmake IF(WIN32) # This property needs to be set on a target at the root; doesn't matter which set_target_properties( survive-cli PROPERTIES VS_USER_PROPS "$(SolutionDir)\packages\OpenBLAS.0.14.1\build\native\openblas.targets" ) ENDIF() ``` -------------------------------- ### Set Global Property for Folders Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Enables the use of folders in the build system's IDE integration. ```cmake set_property(GLOBAL PROPERTY USE_FOLDERS ON) ``` -------------------------------- ### Configure Google Test Integration Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/tests/CMakeLists.txt Conditionally builds and discovers Google Test suites if GTest is found on the system. ```cmake find_package(GTest) if(GTest_FOUND) include(GoogleTest) add_executable(kalman_toy kalman_toy.cc) target_link_libraries(kalman_toy cnkalman GTest::gtest GTest::gtest_main) gtest_discover_tests(kalman_toy) add_executable(cnkalman-tests multi_model_test.cc feature_tests.cc) target_link_libraries(cnkalman-tests cnkalman GTest::gtest GTest::gtest_main) gtest_discover_tests(cnkalman-tests) endif() ``` -------------------------------- ### Check for libusb Headers Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Checks for the presence of libusb header files to determine the correct include path and define necessary preprocessor macros. ```cmake IF(NOT USE_HIDAPI) check_include_file(libusb.h LIBUSB_NO_DIR) check_include_file(libusb-1.0/libusb.h LIBUSB_VER) check_include_file(libusb/libusb.h LIBUSB_NO_VER) if(LIBUSB_NO_DIR) message("Using no dir in libusb path") add_definitions(-DSURVIVE_LIBUSB_NO_DIR) elseif(LIBUSB_VER) message("Using versioned libusb dir") add_definitions(-DSURVIVE_LIBUSB_VER_DIR) elseif(LIBUSB_NO_VER) message("Using non-versioned libusb dir") add_definitions(-DSURVIVE_LIBUSB_UNVER_DIR) endif() set(driver_vive_ADDITIONAL_LIBS ${LIBUSB_LIBRARY}) find_library(PCAP_LIBRARY pcap) if(PCAP_LIBRARY) list(APPEND PLUGINS driver_usbmon) find_path(PCAP_INCLUDE_PATH NAMES pcap.h) if(PCAP_INCLUDE_PATH) include_directories(${PCAP_INCLUDE_PATH}) endif() set(driver_usbmon_ADDITIONAL_LIBS "${PCAP_LIBRARY};z" driver_vive) else() message("Can't build usbmon plugin -- pcap library was not found") endif() endif() ``` -------------------------------- ### Add a Threaded Driver Source: https://github.com/collabora/libsurvive/blob/master/README.md Registers a driver that runs in a separate thread, providing more versatility for background tasks. ```C bool *survive_add_threaded_driver(SurviveContext *ctx, void *driver_data, const char *name, void *(routine)(void *), DeviceDriverCb close); ``` -------------------------------- ### Set library type (Shared/Static) Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Sets the library type to SHARED by default. If BUILD_STATIC is enabled, it sets the type to STATIC and defines SURVIVE_DISABLE_PLUGINS. ```cmake SET(SURVIVE_LIBRARY_TYPE SHARED) if(BUILD_STATIC) SET(SURVIVE_LIBRARY_TYPE STATIC) add_definitions(-DSURVIVE_DISABLE_PLUGINS) endif() ``` -------------------------------- ### Set build type for core components Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Determines whether to build core components. NOT_CORE_BUILD is ON by default and turned OFF if DO_CORE_BUILD is set. ```cmake SET(NOT_CORE_BUILD ON) if(DO_CORE_BUILD) SET(NOT_CORE_BUILD OFF) endif() VERBOSE_OPTION(BUILD_APPLICATIONS "Build the default libsurvive applications" ${NOT_CORE_BUILD}) ``` -------------------------------- ### Add a Polling Driver Source: https://github.com/collabora/libsurvive/blob/master/README.md Registers a driver that executes a poll function continuously during system runtime. ```C void survive_add_driver(SurviveContext *ctx, void *user_ptr, DeviceDriverCb poll, DeviceDriverCb close) ``` -------------------------------- ### Manage Context Locks Source: https://github.com/collabora/libsurvive/blob/master/README.md Functions required to safely access SurviveContext or SurviveObject members within a threaded driver to prevent race conditions. ```C void survive_get_ctx_lock(SurviveContext *ctx); void survive_release_ctx_lock(SurviveContext *ctx); ``` -------------------------------- ### Define USE_FLOAT for single-precision builds Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Defines the USE_FLOAT macro if the USE_SINGLE_PRECISION option is enabled, for single-precision floating-point builds. ```cmake if(USE_SINGLE_PRECISION) add_definitions(-DUSE_FLOAT) endif() ``` -------------------------------- ### Define Barycentric SVD Source Source: https://github.com/collabora/libsurvive/blob/master/src/CMakeLists.txt Sets the source file for the barycentric SVD module. ```cmake set(poser_barycentric_svd_ADDITIONAL_SRCS barycentric_svd/barycentric_svd.c ) ``` -------------------------------- ### Python Measurement Function Generation Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/README.md Define a measurement function in Python using SymEngine for symbolic computation. This function, decorated with @cg.generate_code, will be automatically converted into C code, including its Jacobian, for use in Kalman filters. Specify size hints for array-type inputs like 'state' and 'landmark'. ```python @cg.generate_code(state = 3, landmark = 2) def meas_function(state, landmark): x, y, theta = state px, py = landmark hyp = (px-x)**2 + (py-y)**2 dist = sqrt(hyp) return [dist, atan2(py - y, px - x) - theta] ``` -------------------------------- ### Check for gvprintf function availability Source: https://github.com/collabora/libsurvive/blob/master/CMakeLists.txt Checks if the gvprintf function is available in zlib. If not, defines NO_GZVPRINTF. ```cmake include(CheckCSourceCompiles) check_c_source_compiles(" #include #include int main(void) { va_list args; gzvprintf(0, 0, args); return 0; } " HAVE_GZVPRINTF ) if(NOT HAVE_GZVPRINTF) add_definitions(-DHAVE_NO_GZVPRINTF) endif() ``` -------------------------------- ### Adjust Playback Speed Source: https://github.com/collabora/libsurvive/blob/master/README.md The --playback-factor flag allows you to control the speed of recorded data playback. A value of 0 plays as fast as possible, while values greater than 1 slow down playback. ```bash --playback-factor x ``` -------------------------------- ### Python Prediction Function Generation Source: https://github.com/collabora/libsurvive/blob/master/libs/cnkalman/README.md Define a prediction function in Python using SymEngine for symbolic computation. This function, decorated with @cg.generate_code, will be automatically converted into C code, including its Jacobian, for use in Kalman filters. Specify size hints for array-type inputs like 'state' and 'u'. ```python from symengine import atan2, asin, cos, sin, tan, sqrt import cnkalman.codegen as cg @cg.generate_code(state = 3, u = 2) def predict_function(dt, wheelbase, state, u): x, y, theta = state v, alpha = u d = v * dt R = wheelbase/tan(alpha) beta = d / wheelbase * tan(alpha) return [x + -R * sin(theta) + R * sin(theta + beta), y + R * cos(theta) - R * cos(theta + beta), theta + beta] ``` -------------------------------- ### Set Verbosity Level Source: https://github.com/collabora/libsurvive/blob/master/README.md The --v flag controls the reporting level for debugging information. Higher values provide more detailed output. ```bash --v 10 ``` ```bash --v 100 ``` ```bash --v 150 ``` ```bash --v 250 ``` ```bash --v 1000 ``` -------------------------------- ### Conditionally Add Subdirectories in CMake Source: https://github.com/collabora/libsurvive/blob/master/tools/CMakeLists.txt Uses conditional checks to include subdirectories only when specific libraries or packages are found. ```cmake if(OPENVR_LIBRARIES AND NOT USE_SINGLE_PRECISION) add_subdirectory(openvr_driver) endif() ``` ```cmake find_package(catkin QUIET COMPONENTS roscpp geometry_msgs) IF(catkin_DIR) add_subdirectory(ros_publisher) ENDIF() ``` ```cmake find_library(XDO_LIB xdo) if(XDO_LIB) add_subdirectory(vive_mouse) endif() ``` ```cmake add_subdirectory(visualize_mpfit) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.