### Install 2D Walking Example for Python Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/Moco/example2DWalking/CMakeLists.txt Installs the 2D walking example files to the designated Python examples directory. ```cmake install(FILES ${EXAMPLE_2D_WALKING_FILES} DESTINATION "${OPENSIM_INSTALL_PYTHONEXDIR}/Moco/example2DWalking") ``` -------------------------------- ### Install 2D Walking Example for Matlab Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/Moco/example2DWalking/CMakeLists.txt Installs the 2D walking example files to the designated Matlab examples directory. ```cmake install(FILES ${EXAMPLE_2D_WALKING_FILES} DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/example2DWalking") ``` -------------------------------- ### Install MATLAB Example Directories Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/CMakeLists.txt Installs various example directories to the OpenSim MATLAB export directory. Some files are excluded from the 'Dynamic_Walking_Tutorials' due to not being updated for version 4.0. ```cmake install(DIRECTORY examples/ DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") install(DIRECTORY Hopper_Device DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") install(DIRECTORY Utilities DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") install(DIRECTORY OpenSenseExample DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") install(DIRECTORY Dynamic_Walking_Tutorials/Dynamic_Walker_Builder DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") install(DIRECTORY Dynamic_Walking_Tutorials/Dynamic_Walker_Challenge DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}" # These files have not yet been updated for 4.0: PATTERN "DesignMainStarterWithControls.m" EXCLUDE PATTERN "AddCoordinateActuator.m" EXCLUDE PATTERN "AddMillardMuscle.m" EXCLUDE PATTERN "AddPathActuator.m" EXCLUDE PATTERN "IntegrateOpenSimPlant.m" EXCLUDE PATTERN "Main_WalkerForwardSim.m" EXCLUDE PATTERN "Main_WalkerForwardSimWithControls.m" EXCLUDE PATTERN "OpenSimPlantControlsFunction.m" EXCLUDE PATTERN "OpenSimPlantFunction.m" EXCLUDE PATTERN "Simulation_using_Matlab_Integration.m" EXCLUDE) install(DIRECTORY CustomStaticOptimization DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") ``` -------------------------------- ### Add Example Executable Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/OptimizationExample_Arm26/CMakeLists.txt Creates an executable target for the example and includes all header and source files from the example directory. ```cmake file(GLOB SOURCE_FILES ${EXAMPLE_DIR}/*.h ${EXAMPLE_DIR}/*.cpp) add_executable(${EXAMPLE_TARGET} ${SOURCE_FILES}) add_executable(${TEST_TARGET} ${TEST_TARGET}.cpp) ``` -------------------------------- ### Define Example and Test Executables Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/SimpleOptimizationExample/CMakeLists.txt Sets up CMake variables for example and test executable names and directories. Defines the source files for the example and test executables. ```cmake set(EXAMPLE_TARGET exampleOptimizationSimple) set(EXAMPLE_DIR ${OpenSim_SOURCE_DIR}/OpenSim/Examples/SimpleOptimizationExample) set(TEST_TARGET testSimpleOptimizationExample) set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) file(GLOB SOURCE_FILES ${EXAMPLE_DIR}/*.h ${EXAMPLE_DIR}/*.cpp) add_executable(${EXAMPLE_TARGET} ${SOURCE_FILES}) add_executable(${TEST_TARGET} ${TEST_TARGET}.cpp) ``` -------------------------------- ### MocoStateTrackingGoal Example (C++) Source: https://github.com/opensim-org/opensim-core/blob/main/doc/Moco/MocoExamples.dox A simple example of how to use a MocoStateTrackingGoal. ```cpp @example exampleTracking.cpp This is a simple example of how to use a MocoStateTrackingGoal. ``` -------------------------------- ### Install Geometry Folders for Examples Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/CMakeLists.txt Installs the 'Geometry' folder from the OpenSenseExample directory to various Moco example subdirectories for both MATLAB and Python installations. This ensures necessary model assets are available. ```cmake install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/exampleSquatToStand/Geometry/") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_PYTHONEXDIR}/Moco/exampleSquatToStand/Geometry/") # Copy Geometry folder for Moco examples install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/example2DWalking/Geometry/") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/example3DWalking/Geometry/") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/exampleEMGTracking/Geometry/") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/exampleMarkerTracking10DOF/Geometry/") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/exampleSquatToStand/Geometry/") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/OpenSenseExample/Geometry/" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/exampleSquatToStand/exampleIMUTracking/Geometry/") ``` -------------------------------- ### Copy Example Model Files Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/CMakeLists.txt Copies an example model file ('squatToStand_3dof9musc.osim') to the binary directory for use in Moco examples. ```cmake file(COPY "examples/Moco/exampleSquatToStand/squatToStand_3dof9musc.osim" DESTINATION "${CMAKE_BINARY_DIR}/Examples/Moco/exampleSquatToStand") ``` -------------------------------- ### Define Example and Test Executables Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/MuscleExample/CMakeLists.txt Defines the source files for the example and test executables and adds them to the build. ```cmake set(EXAMPLE_TARGET exampleMuscle) set(EXAMPLE_DIR ${OpenSim_SOURCE_DIR}/OpenSim/Examples/MuscleExample) set(TEST_TARGET testMuscleExample) set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) file(GLOB SOURCE_FILES ${EXAMPLE_DIR}/*.h ${EXAMPLE_DIR}/*.cpp) add_executable(${EXAMPLE_TARGET} ${SOURCE_FILES}) add_executable(${TEST_TARGET} ${TEST_TARGET}.cpp) ``` -------------------------------- ### Install spdlog Dependency Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Installs the spdlog library by copying its directory structure. This is a general installation step that is not platform-specific. ```cmake install(DIRECTORY "${spdlog_DIR}/../../../" DESTINATION "${OPENSIM_INSTALL_SPDLOGDIR}") ``` -------------------------------- ### Download IK Setup File Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 5 - Scaling, Inverse Kinematics, and Inverse Dynamics.ipynb Downloads the XML configuration file required for the InverseKinematicsTool. ```python !gdown "1z1YGOTZlTCA4jpjRFbz0FlEaen1bETou&confirm=t" # subject01_Setup_IK.xml ``` -------------------------------- ### Copy Example Dependencies with GLOB Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/ExampleLuxoMuscle/CMakeLists.txt Copies various file types (obj, osim, xml, sto, mot) from an example directory to the test run directory using file GLOB. Ensure the example directory path is correctly set. ```cmake set(EXAMPLE_DIR "${OpenSim_SOURCE_DIR}/OpenSim/Examples/ExampleLuxoMuscle") file(GLOB TEST_FILES ${EXAMPLE_DIR}/*.obj ${EXAMPLE_DIR}/*.osim ${EXAMPLE_DIR}/*.xml ${EXAMPLE_DIR}/*.sto ${EXAMPLE_DIR}/*.mot *.obj *.osim *.xml *.sto *.mot) ``` -------------------------------- ### Define Example and Test Targets Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/OptimizationExample_Arm26/CMakeLists.txt Sets up variables for the example executable target name, its source directory, the test executable target name, and its build directory. ```cmake set(EXAMPLE_TARGET exampleOptimization) set(EXAMPLE_DIR ${OpenSim_SOURCE_DIR}/OpenSim/Examples/OptimizationExample_Arm26) set(TEST_TARGET testOptimizationExample) set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Simplest Moco Example (C++) Source: https://github.com/opensim-org/opensim-core/blob/main/doc/Moco/MocoExamples.dox Moco's simplest example. ```cpp @example exampleSlidingMass.cpp This is Moco's simplest example. ``` -------------------------------- ### Install Java Bindings JAR Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/CMakeLists.txt Installs the generated SWIG Java JAR to the specified installation directory. ```cmake install(FILES "${SWIG_JAVA_JAR_BUILD_OUTPUT_PATH}" DESTINATION ${OPENSIM_INSTALL_JAVAJARDIR}) ``` -------------------------------- ### Setup and Run AnalyzeTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 6 - Static Optimization.ipynb Configures the AnalyzeTool with the RRA-smoothed motion file and executes the analysis. ```python # Create analyze tool for static optimization. so_strong_RRA_analyze_tool = osim.AnalyzeTool() so_strong_RRA_analyze_tool.setName("SO_Strong_RRA") # Add actuators file. forceSet_files = osim.ArrayStr() forceSet_files.append("gait10dof18musc_Strong_actuators.xml") so_strong_RRA_analyze_tool.setForceSetFiles(forceSet_files) # Set model file, motion files and external load file names. so_strong_RRA_analyze_tool.setModelFilename("gait10dof18musc_simbody.osim") so_strong_RRA_analyze_tool.setCoordinatesFileName("subject_adjusted_Kinematics_q.sto") so_strong_RRA_analyze_tool.setExternalLoadsFileName("subject01_walk_grf.xml") # Add analysis. so_strong_RRA_analyze_tool.updAnalysisSet().cloneAndAppend(so_rra) # Configure analyze tool. so_strong_RRA_analyze_tool.setReplaceForceSet(False) so_strong_RRA_analyze_tool.setStartTime(start_time) so_strong_RRA_analyze_tool.setFinalTime(end_time) # Directory where results are stored. so_strong_RRA_analyze_tool.setResultsDir("SO_Strong_RRA_Results") # Print configuration of analyze tool to a xml file. so_strong_RRA_analyze_tool.printToXML("SO_Strong_RRA_AnalyzeTool_setup.xml") # Load configuration and run the analyses. so_strong_RRA_analyze_tool = osim.AnalyzeTool("SO_Strong_RRA_AnalyzeTool_setup.xml", True) ``` ```python # Run static optimization. so_strong_RRA_analyze_tool.run() ``` -------------------------------- ### Copy 2D Walking Example for Java/Matlab Bindings Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/Moco/example2DWalking/CMakeLists.txt Copies the 2D walking example files to the build directory for Java and Matlab bindings. ```cmake file(COPY ${EXAMPLE_2D_WALKING_FILES} DESTINATION "${CMAKE_BINARY_DIR}/Bindings/Java/Matlab/examples/Moco/example2DWalking") ``` -------------------------------- ### Install OpenSim CMake Files Source: https://github.com/opensim-org/opensim-core/blob/main/cmake/CMakeLists.txt Installs the generated configuration, version, and macro files to the designated CMake directory. ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/OpenSimConfigToInstall.cmake" DESTINATION "${OPENSIM_INSTALL_CMAKEDIR}" RENAME OpenSimConfig.cmake ) install( FILES "SampleCMakeLists.txt" "${CMAKE_CURRENT_BINARY_DIR}/OpenSimConfigVersion.cmake" DESTINATION "${OPENSIM_INSTALL_CMAKEDIR}" ) install(FILES OpenSimMacros.cmake DESTINATION "${OPENSIM_INSTALL_CMAKEDIR}" RENAME UseOpenSim.cmake) install(EXPORT OpenSimTargets DESTINATION "${OPENSIM_INSTALL_CMAKEDIR}") ``` -------------------------------- ### Copy 2D Walking Example for Python Bindings Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/Moco/example2DWalking/CMakeLists.txt Copies the 2D walking example files to the build directory for Python bindings. ```cmake file(COPY ${EXAMPLE_2D_WALKING_FILES} DESTINATION "${CMAKE_BINARY_DIR}/Bindings/Python/examples/Moco/example2DWalking") ``` -------------------------------- ### Install Simbody Headers and Libraries on Unix Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Installs Simbody header files and libraries on non-Windows systems. It calculates relative paths for installation directories and uses GLOB_RECURSE to find desired library files. ```cmake file(RELATIVE_PATH install_simbodyincludedir "${Simbody_ROOT_DIR}" "${Simbody_INCLUDE_DIR}") install(DIRECTORY "${Simbody_INCLUDE_DIR}/" DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}/${install_simbodyincludedir}") ``` ```cmake file(RELATIVE_PATH install_simbodylibdir "${Simbody_ROOT_DIR}/" "${Simbody_LIB_DIR}/" ) file(GLOB_RECURSE simbody_desired_lib_files RELATIVE "${Simbody_LIB_DIR}" "${Simbody_LIB_DIR}/*SimTK*" "${Simbody_LIB_DIR}/*Simbody*.cmake" "${Simbody_LIB_DIR}/*SampleCMakeLists.txt*") foreach(simbody_lib_file ${simbody_desired_lib_files}) get_filename_component(subdir "${simbody_lib_file}" DIRECTORY) install(FILES "${Simbody_LIB_DIR}/${simbody_lib_file}" DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}/${install_simbodylibdir}/${subdir}") endforeach() ``` ```cmake file(RELATIVE_PATH install_simbodyvizdir "${Simbody_ROOT_DIR}" "${Simbody_VIZ_DIR}") install(DIRECTORY "${Simbody_VIZ_DIR}/" DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}/${install_simbodyvizdir}" USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN "*simbody-visualizer*") ``` -------------------------------- ### Compile and Link OpenSim Examples with CMake Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/DataTable/CMakeLists.txt Use this script to automate the build process for multiple C++ example files. It requires Simbody and osimCommon libraries to be available in the environment. ```cmake set(EXAMPLES_TO_COMPILE example1.cpp example2.cpp ) foreach(EXAMPLE_PROG ${EXAMPLES_TO_COMPILE}) get_filename_component(EXAMPLE_ROOT ${EXAMPLE_PROG} NAME_WE) add_executable(${EXAMPLE_ROOT}DataTable ${EXAMPLE_PROG}) target_link_libraries(${EXAMPLE_ROOT}DataTable ${Simbody_LIBRARIES} osimCommon) set_target_properties(${EXAMPLE_ROOT}DataTable PROPERTIES FOLDER "Examples") endforeach(EXAMPLE_PROG ${EXAMPLES_TO_COMPILE}) ``` -------------------------------- ### Configure Installation Rules Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Moco/CMakeLists.txt Defines RPATH settings and installation paths for the Moco library and its header files. ```cmake OpenSimAddInstallRPATHSelf(TARGET osimMoco LOADER) OpenSimAddInstallRPATHSimbody(TARGET osimMoco LOADER FROM "${CMAKE_INSTALL_LIBDIR}") install(TARGETS EXPORT OpenSimTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # TODO do not install InverseMuscleSolverMotionData.h b/c it uses Eigen. install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/OpenSim/Moco FILES_MATCHING PATTERN "*.h*" PATTERN "Archive" EXCLUDE PATTERN "doc" EXCLUDE PATTERN "Test" EXCLUDE ) ``` -------------------------------- ### Configure and Install configureOpenSim.m Script Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/CMakeLists.txt Configures the 'configureOpenSim.m.in' template file using CMake variables to set correct installation paths, then installs the generated 'configureOpenSim.m' script to the MATLAB export directory. This script helps users set up their MATLAB environment to find OpenSim. ```cmake # The configureOpenSim.m script contains paths into the OpenSim installation # that may be different on different platforms, so we configure it with CMake # variables. file(RELATIVE_PATH matlabexdir_to_install_dir "${CMAKE_INSTALL_PREFIX}/${OPENSIM_INSTALL_MATLABEXDIR}" "${CMAKE_INSTALL_PREFIX}") configure_file(configureOpenSim.m.in "${CMAKE_CURRENT_BINARY_DIR}/configureOpenSim.m" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/configureOpenSim.m" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}") ``` -------------------------------- ### Install Simbody DLLs on Windows Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Installs Simbody DLLs and the simbody-visualizer executable on Windows. It specifically targets Simbody DLLs for the SDK installation and the visualizer executable for the main binary directory. ```cmake install(DIRECTORY "${Simbody_ROOT_DIR}/" DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}" FILES_MATCHING PATTERN "*SimTK*.dll") ``` ```cmake install(DIRECTORY "${Simbody_ROOT_DIR}/" DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}" # There's no need to install Simbody examples or docs. PATTERN "*examples/*" EXCLUDE PATTERN "*doc/*" EXCLUDE # Don't copy lapack, blas, etc. into sdk/Simbody/bin/; they are # already copied into bin/. PATTERN "*.dll" EXCLUDE PATTERN "*.exe" EXCLUDE) ``` ```cmake install(DIRECTORY "${Simbody_BIN_DIR}/" DESTINATION "${CMAKE_INSTALL_BINDIR}" FILES_MATCHING PATTERN "*.exe") ``` -------------------------------- ### Install EZC3D Libraries on Unix Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Installs EZC3D shared library files (.so on Linux, .dylib on macOS) to the installation's library directory. This is only performed on non-Windows systems. ```cmake # LIB: .so files on Linux, .dylib on macOS file(GLOB ezc3d_desired_lib_files "${ezc3d_LIBRARY_DIR}/*ezc3d*") install(FILES ${ezc3d_desired_lib_files} DESTINATION "${CMAKE_INSTALL_LIBDIR}") ``` -------------------------------- ### Run OpenSim-Core Container Source: https://github.com/opensim-org/opensim-core/blob/main/scripts/docker/ubuntu18.04/README.md Starts the container with a mounted volume for artifact persistence. ```bash docker run -i -v opensim_volume:/root/artifacts/ -t opensim-ubuntu:ubuntu-18.04 ``` -------------------------------- ### Configure Installation Prefix Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Sets the default installation prefix for the project. It includes logic to override the default on Windows and Linux for permission and filesystem hierarchy reasons. ```cmake if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # On Windows, we override the default value because Visual Studio does # not, by default, have permission to write to the Program Files # directory. # On Linux, we override the default value because our installation does # not yet conform to the Filesystem Hierarchy Standard (FHS). set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}-install" CACHE PATH "The directory in which to install this project." FORCE) endif() ``` -------------------------------- ### Define Example Files for 2D Walking Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/Moco/example2DWalking/CMakeLists.txt Defines a CMake variable to hold a list of files associated with the 2D walking example. ```cmake set(EXAMPLE_2D_WALKING_FILES 2D_gait.osim referenceCoordinates.sto referenceGRF.sto referenceGRF.xml) ``` -------------------------------- ### Add 2D Walking Example to Moco Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/Moco/example2DWalking/CMakeLists.txt Adds the 2D walking example to the Moco subdirectory, specifying executables and resources. ```cmake OpenSimAddExampleCXX(NAME example2DWalking SUBDIR Moco EXECUTABLES example2DWalking example2DWalkingMetabolics RESOURCES "${EXAMPLE_2D_WALKING_FILES}") ``` -------------------------------- ### Configure OpenSim Example and Test Targets Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/ControllerExample/CMakeLists.txt Locates the Catch2 dependency and defines executable targets for an example controller and its corresponding test suite. ```cmake find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") # Variable definitions set(EXAMPLE_TARGET exampleController) set(EXAMPLE_DIR ${OpenSim_SOURCE_DIR}/OpenSim/Examples/ControllerExample) set(TEST_TARGET testControllerExample) set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) file(GLOB SOURCE_FILES ${EXAMPLE_DIR}/*.h ${EXAMPLE_DIR}/*.cpp) add_executable(${EXAMPLE_TARGET} ${SOURCE_FILES}) add_executable(${TEST_TARGET} ${TEST_TARGET}.cpp) target_link_libraries(${EXAMPLE_TARGET} osimTools) target_link_libraries(${TEST_TARGET} osimTools Catch2::Catch2WithMain) ``` -------------------------------- ### Marker Tracking Goal (C++) Source: https://github.com/opensim-org/opensim-core/blob/main/doc/Moco/MocoExamples.dox A simple example of using a marker tracking goal. ```cpp @example exampleMarkerTracking.cpp This is a simple example of using a marker tracking goal. ``` -------------------------------- ### Configure SWIG Java ExampleComponents Interface Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/CMakeLists.txt Sets the SWIG interface, C++, and header file paths for the Java example components bindings. This configuration is for generating Java wrappers for example components within OpenSim. ```cmake set(SWIG_JAVA_EXAMPLECOMPONENTS_INTERFACE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/swig/java_examplecomponents.i") set(SWIG_JAVA_EXAMPLECOMPONENTS_CXX_FILE "${CMAKE_CURRENT_BINARY_DIR}/OpenSimJNI/java_examplecomponents.cxx") set(SWIG_JAVA_EXAMPLECOMPONENTS_H_FILE "${CMAKE_CURRENT_BINARY_DIR}/OpenSimJNI/java_examplecomponents.h") ``` -------------------------------- ### Set Target Properties Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/MuscleExample/CMakeLists.txt Organizes the example and test targets into folders within the build system. ```cmake set_target_properties(${EXAMPLE_TARGET} PROPERTIES FOLDER "Examples") set_target_properties(${TEST_TARGET} PROPERTIES FOLDER "Example tests") ``` -------------------------------- ### Import OpenSim and verify version Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 1 - Introduction to OpenSim.ipynb Imports the OpenSim module and prints the current version and build date to verify successful installation. ```python import opensim as osim osim.GetVersionAndDate() ``` -------------------------------- ### Configure and Run AnalyzeTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 6 - Static Optimization.ipynb Sets up the AnalyzeTool with model, motion, and external load files, then saves the configuration to an XML file and initializes the tool. ```python so_normal_RRA_spring_analyze_tool.setModelFilename("gait10dof18musc_simbody_spring.osim") so_normal_RRA_spring_analyze_tool.setCoordinatesFileName("subject_adjusted_Kinematics_q.sto") so_normal_RRA_spring_analyze_tool.setExternalLoadsFileName("subject01_walk_grf.xml") # Add analysis. so_normal_RRA_spring_analyze_tool.updAnalysisSet().cloneAndAppend(so_rra) # Configure analyze tool. so_normal_RRA_spring_analyze_tool.setReplaceForceSet(False) so_normal_RRA_spring_analyze_tool.setStartTime(start_time) so_normal_RRA_spring_analyze_tool.setFinalTime(end_time) # Directory where results are stored. so_normal_RRA_spring_analyze_tool.setResultsDir("SO_Normal_RRA_Spring_Results") # Print configuration of analyze tool to a xml file. so_normal_RRA_spring_analyze_tool.printToXML("SO_Normal_RRA_Spring_AnalyzeTool_setup.xml") # Load configuration and run the analyses. so_normal_RRA_spring_analyze_tool = osim.AnalyzeTool("SO_Normal_RRA_Spring_AnalyzeTool_setup.xml", True) ``` -------------------------------- ### Process and Install Hopper Device MATLAB Scripts Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/CMakeLists.txt Processes MATLAB scripts for the Hopper device example by removing specific answer blocks marked with '% ANSWER{ ... % }'. The modified scripts are then written to the build directory and installed. ```cmake foreach(fname RunHopper RunHopperWithDevice) set(file_contents "") file(STRINGS Hopper_Device/${fname}_answers.m file_contents_answers) list(LENGTH file_contents_answers num_lines) set(line_num 0) while(${line_num} LESS ${num_lines}) list(GET file_contents_answers ${line_num} current_line) if("${current_line}" MATCHES "% ANSWER{") while(NOT "${current_line}" MATCHES "% }") math(EXPR line_num "${line_num} + 1") list(GET file_contents_answers ${line_num} current_line) endwhile() # Add an empty line in place of the ANSWERS block. set(file_contents "${file_contents}\n") else() set(file_contents "${file_contents}${current_line}\n") endif() math(EXPR line_num "${line_num} + 1") endwhile() file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/Hopper_Device/${fname}.m" "${file_contents}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Hopper_Device/${fname}.m" DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Hopper_Device") endforeach() ``` -------------------------------- ### Check Simbody Found Status Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt This snippet checks if Simbody was successfully found by CMake. If not, it prints a fatal error message guiding the user to install Simbody and set the SIMBODY_HOME variable. ```cmake if(NOT Simbody_FOUND) message(FATAL_ERROR " Simbody ${SIMBODY_VERSION_TO_USE} not found. Install Simbody and set SIMBODY_HOME to the installation directory of Simbody.") endif() ``` -------------------------------- ### Initialize Synergy Optimization Environment Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 8 - Creating Muscle-driven Simulations with OpenSim Moco.ipynb Imports necessary libraries (ipywidgets, IPython.display, numpy) for creating interactive elements and performing numerical operations. This setup is required before running the synergy-driven squat-to-stand optimization. ```python # @title Run a synergy-driven squat-to-stand optimization { display-mode: "form" } # @markdown Execute the cell to load the menu for specifying the number of synergies. import ipywidgets as widgets from IPython.display import display, Markdown import numpy as np ``` -------------------------------- ### Configure and Run AnalyzeTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 6 - Static Optimization.ipynb Sets up the AnalyzeTool with model, motion, and external load files, then executes the analysis. ```python # Create analyze tool for static optimization. so_analyze_tool = osim.AnalyzeTool() so_analyze_tool.setName("SO") # Set model file, motion files and external load file names. so_analyze_tool.setModelFilename("gait10dof18musc_simbody.osim") so_analyze_tool.setCoordinatesFileName("subject01_walk_IK.mot") so_analyze_tool.setExternalLoadsFileName("subject01_walk_grf.xml") # Add analysis. so_analyze_tool.updAnalysisSet().cloneAndAppend(so) # Configure analyze tool. so_analyze_tool.setReplaceForceSet(False) so_analyze_tool.setStartTime(start_time) so_analyze_tool.setFinalTime(end_time) # Directory where results are stored. so_analyze_tool.setResultsDir("SO_Results") # Print configuration of analyze tool to a xml file. so_analyze_tool.printToXML("SO_AnalyzeTool_setup.xml") # Load configuration and run the analyses. so_analyze_tool = osim.AnalyzeTool("SO_AnalyzeTool_setup.xml", True) ``` ```python # Run static optimization. so_analyze_tool.run(); ``` -------------------------------- ### Set State Info in MocoProblem Source: https://github.com/opensim-org/opensim-core/blob/main/doc/Moco/MocoCheatSheet.tex Configure the bounds for a specific state variable (coordinate value) over the phase and its initial/final values. For example, '/jointset/j0/q0/value' must be between 0 and pi, starting at 0 and ending at pi/2. ```matlab problem.setStateInfo('/jointset/j0/q0/value', [0, pi], 0, pi/2); ``` -------------------------------- ### Configure and Run AnalyzeTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 6 - Static Optimization.ipynb Sets up the AnalyzeTool with model, motion, and force files, then saves the configuration to XML and executes the analysis. ```python forceSet_files = osim.ArrayStr() forceSet_files.append("gait10dof18musc_Actuators_Normal.xml") so_normal_RRA_analyze_tool.setForceSetFiles(forceSet_files) # Set model file, motion files and external load file names. so_normal_RRA_analyze_tool.setModelFilename("gait10dof18musc_simbody.osim") so_normal_RRA_analyze_tool.setCoordinatesFileName("subject_adjusted_Kinematics_q.sto") so_normal_RRA_analyze_tool.setExternalLoadsFileName("subject01_walk_grf.xml") # Add analysis. so_normal_RRA_analyze_tool.updAnalysisSet().cloneAndAppend(so_rra) # Configure analyze tool. so_normal_RRA_analyze_tool.setReplaceForceSet(False) so_normal_RRA_analyze_tool.setStartTime(start_time) so_normal_RRA_analyze_tool.setFinalTime(end_time) # Directory where results are stored. so_normal_RRA_analyze_tool.setResultsDir("SO_Normal_RRA_Results") # Print configuration of analyze tool to a xml file. so_normal_RRA_analyze_tool.printToXML("SO_Normal_RRA_AnalyzeTool_setup.xml") # Load configuration and run the analyses. so_normal_RRA_analyze_tool = osim.AnalyzeTool("SO_Normal_RRA_AnalyzeTool_setup.xml", True) ``` ```python # Run static optimization. so_normal_RRA_analyze_tool.run() ``` -------------------------------- ### Install OpenSim Conda Package Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 3 - Loading and Modifying OpenSim Models.ipynb Installs the OpenSim conda package. Ensure condacolab is installed and the session has restarted before running this. ```python !conda install opensim-org::opensim ``` -------------------------------- ### Install Python Wheels Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Installs Python wheels if the BUILD_PYTHON_WHEELS option is enabled. It uses a custom script 'buildWheel.cmake' for the installation process. ```cmake if (BUILD_PYTHON_WHEELS) install (CODE "set(OPENSIM_INSTALL_PYTHONDIR \"${OPENSIM_INSTALL_PYTHONDIR}\")") install (SCRIPT "${CMAKE_SOURCE_DIR}/buildWheel.cmake") endif() ``` -------------------------------- ### Install Python Module and Compiled Library Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/CMakeLists.txt Installs the compiled Python extension module and its .py wrapper file to the OpenSim installation's Python directory. Uses install(TARGETS) to ensure the build-tree RPATH is removed from the library. ```cmake install(TARGETS ${_libname} DESTINATION "${OPENSIM_INSTALL_PYTHONDIR}/opensim") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${OSIMSWIGPY_MODULE}.py" DESTINATION "${OPENSIM_INSTALL_PYTHONDIR}/opensim") ``` -------------------------------- ### Set Dependency Installation Directory Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Defines the directory where OpenSim dependencies are installed. This is primarily used when dependencies are installed via a Superbuild procedure. ```cmake set(OPENSIM_DEPENDENCIES_DIR "${CMAKE_SOURCE_DIR}/../opensim_dependencies_install" CACHE PATH "Directory containing installed binaries of OpenSim dependencies. Set this only if you used the Superbuild procedure to install dependencies. ") ``` -------------------------------- ### Initialize and Configure InverseKinematicsTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 5 - Scaling, Inverse Kinematics, and Inverse Dynamics.ipynb Creates an IK tool instance from a configuration file and prints its parameters and task weights. ```python # Create an IK object using the configuration file. inverse_kinematics_tool = osim.InverseKinematicsTool('subject01_Setup_IK.xml') # Print some information of the config file to check that everything is correct. print("Name:", inverse_kinematics_tool.getName()) print("Model File:", inverse_kinematics_tool.get_model_file()) print("Marker File:", inverse_kinematics_tool.get_marker_file()) print("Accuracy:", inverse_kinematics_tool.get_accuracy()) print("Time Range: [", inverse_kinematics_tool.get_time_range(0), ",", inverse_kinematics_tool.get_time_range(1), "]") print("Constraint Weight:", inverse_kinematics_tool.get_constraint_weight()) print() # Print weights information print("Weights:") task_set = inverse_kinematics_tool.get_IKTaskSet() for i in range(task_set.getSize()): task = task_set.get(i) print(task.getName()) print(task.getWeight()) print() ``` -------------------------------- ### Install Executable Conditionally Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/Environment/CMakeLists.txt Installs the 'checkEnvironment' executable to the binary directory if the 'OPENSIM_BUILD_INDIVIDUAL_APPS' option is enabled. This controls whether the utility is installed as part of the application build. ```cmake if(OPENSIM_BUILD_INDIVIDUAL_APPS) install(TARGETS ${TEST_ENVIRONMENT} DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() ``` -------------------------------- ### Create Static Optimization Analysis Tool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 6 - Static Optimization.ipynb Initializes an AnalyzeTool for static optimization, specifying actuator files. This is a setup step before running the analysis. ```python # Create analyze tool for static optimization. so_normal_RRA_spring_analyze_tool = osim.AnalyzeTool() so_normal_RRA_spring_analyze_tool.setName("SO_Normal_RRA_Spring") # Add actuators file. forceSet_files = osim.ArrayStr() forceSet_files.append("gait10dof18musc_Actuators_Normal.xml") so_normal_RRA_spring_analyze_tool.setForceSetFiles(forceSet_files) ``` -------------------------------- ### Install condacolab and OpenSim Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 7 - Introduction to OpenSim Moco.ipynb Installs the condacolab package for managing conda environments and then installs the OpenSim conda package. The first step requires a session restart. ```python !pip install -q condacolab import condacolab condacolab.install() ``` ```python !conda install opensim-org::opensim ``` -------------------------------- ### Download Model and Configuration Files Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 5 - Scaling, Inverse Kinematics, and Inverse Dynamics.ipynb Downloads the required model, setup, marker set, and static trial files from Google Drive using gdown. ```bash !gdown "1roNo6te-wyNk-4UPqfmV7SmUfef4Bfq3&confirm=t" # gait2354_simbody.osim ``` ```bash !gdown "1c0P8cN1zUmVFJxqvcpHZEDacyAoa6lQy&confirm=t" # gait2354_Setup_Scale.xml ``` ```bash !gdown "1VNDVGM-MKVrYs9w3aTPCLHOfwK-s2Nn8&confirm=t" # gait2354_Scale_MarkerSet.xml ``` ```bash !gdown "19-ouxBQN-XUOJ-K8lRe16DUs8fqaN1Yz&confirm=t" # subject01_static.trc ``` -------------------------------- ### Copy Dependencies and Add Test (Example 1) Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/BodyDragExample/CMakeLists.txt Copies necessary files for 'Example1_ThreeMasses' and adds a test that executes an OpenSim command using the built plugin library. ```cmake # Copy dependencies from BodyDragExample into the run directory. set(TEST_FILES_DIR "${EXAMPLE_DIR}/TestPlugin/Example1_ThreeMasses") set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/Example1_ThreeMasses") OpenSimCopyTestFiles(${TEST_FILES_DIR} ${TEST_DIR}) # Add test. add_test(NAME ${TEST_TARGET}_Example1 COMMAND opensim-cmd -L $ run-tool forward.xml WORKING_DIRECTORY ${TEST_DIR}) ``` -------------------------------- ### List Python Examples for Testing Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/CMakeLists.txt Specifies a list of Python example modules to be included in unit tests. Excludes examples that are too long or require additional libraries. ```cmake set(PYTHON_EXAMPLES_UNITTEST_ARGS build_simple_arm_model extend_OpenSim_Vec3_class posthoc_StatesTrajectory_example wiring_inputs_and_outputs_with_TableReporter ) if(OPENSIM_WITH_CASADI) list(APPEND PYTHON_EXAMPLES_UNITTEST_ARGS Moco.exampleKinematicConstraints Moco.exampleSlidingMass Moco.exampleOptimizeMass Moco.examplePredictAndTrack ) endif() ``` -------------------------------- ### Copy Dependencies and Add Test (Example 2) Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/BodyDragExample/CMakeLists.txt Copies necessary files for 'Example2_Pendulum_Drag' and adds a test that executes an OpenSim command using the built plugin library. ```cmake set(TEST_FILES_DIR "${EXAMPLE_DIR}/TestPlugin/Example2_Pendulum_Drag") set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/Example2_Pendulum_Drag") OpenSimCopyTestFiles(${TEST_FILES_DIR} ${TEST_DIR}) # Add test. add_test(NAME ${TEST_TARGET}_Example2 COMMAND opensim-cmd -L $ run-tool forward.xml WORKING_DIRECTORY ${TEST_DIR}) ``` -------------------------------- ### Initialize MocoStudy for squat-to-stand Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 8 - Creating Muscle-driven Simulations with OpenSim Moco.ipynb Sets up a MocoStudy, processes the model with specific muscle modifications, and defines time bounds for the simulation. ```python # Part 1: Create a new MocoStudy. study = osim.MocoStudy() study.setName('squat_to_stand_prediction') # Part 2: Initialize the problem. problem = study.updProblem() # Part 3: Construct a model using the function-based paths. To simplify # the problem, we will ignore tendon compliance, activation dynamics, # and passive fiber forces. modelProcessor = osim.ModelProcessor('squatToStand_3dof9musc.osim') modelProcessor.append(osim.ModOpScaleMaxIsometricForce(2.0)) modelProcessor.append(osim.ModOpReplaceMusclesWithDeGrooteFregly2016()) modelProcessor.append(osim.ModOpIgnorePassiveFiberForcesDGF()) modelProcessor.append(osim.ModOpIgnoreTendonCompliance()) modelProcessor.append(osim.ModOpIgnoreActivationDynamics()) modelProcessor.append(osim.ModOpScaleActiveFiberForceCurveWidthDGF(1.5)) modelProcessor.append(osim.ModOpReplacePathsWithFunctionBasedPaths( os.path.join('path_fitting', 'squatToStand_FunctionBasedPathSet.xml'))) model = modelProcessor.process() problem.setModel(model) # Part 4: Set bounds on the problem. # # problem.setTimeBounds(initial_bounds, final_bounds) # problem.setStateInfo(path, trajectory_bounds, inital_bounds, final_bounds) # # All *_bounds arguments can be set to a range, [lower upper], or to a # single value (equal lower and upper bounds). Empty brackets, [], indicate # using default bounds (if they exist). You may set multiple state infos at # once using setStateInfoPattern(): # # problem.setStateInfoPattern(pattern, trajectory_bounds, inital_bounds, ... # final_bounds) # # This function supports regular expressions in the 'pattern' argument; # use '.*' to match any substring of the state/control path # For example, the following will set all coordinate value state infos: # # problem.setStateInfoPattern('/path/to/states/.*/value', ...) # Time bounds problem.setTimeBounds(0, 1) # Position bounds: the model should start in a squat and finish ``` -------------------------------- ### Generate Build Information File Source: https://github.com/opensim-org/opensim-core/blob/main/CMakeLists.txt Creates a buildinfo.txt file containing product version, compiler, and platform information. This file is installed and useful for troubleshooting. ```cmake # Create buildinfo.txt file and place under sdk to include product version, # platform and compiler for troubleshooting purposes set(VERSION_FILE_PATH ${CMAKE_BINARY_DIR}/OpenSim_buildinfo.txt) # message("version file=">${VERSION_FILE_PATH}) file(WRITE ${VERSION_FILE_PATH} "Product Version=${OPENSIM_MAJOR_VERSION}.${OPENSIM_MINOR_VERSION}") file(APPEND ${VERSION_FILE_PATH} "\n") file(APPEND ${VERSION_FILE_PATH} "Compiler=${CMAKE_GENERATOR}-${CMAKE_CXX_COMPILER_ID}") file(APPEND ${VERSION_FILE_PATH} "\n") file(APPEND ${VERSION_FILE_PATH} "Platform=${PLATFORM_NAME}-${PLATFORM_ABI}") file(APPEND ${VERSION_FILE_PATH} "\n") install(FILES ${VERSION_FILE_PATH} DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}") ``` -------------------------------- ### Remove Default Install Directory Source: https://github.com/opensim-org/opensim-core/blob/main/dependencies/CMakeLists.txt Ensures the default installation directory is removed if it is empty. ```cmake RemoveDefaultInstallDirIfEmpty("${DEFAULT_CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Configure Visualizer Source: https://github.com/opensim-org/opensim-core/wiki/OpenSim-API-Example Set up the Simbody visualizer properties. ```python viz = arm.updVisualizer().updSimbodyVisualizer() viz.setBackgroundColor(osim.Vec3(0)) # white viz.setGroundHeight(-2) ``` -------------------------------- ### Advanced Sliding Mass Example (C++) Source: https://github.com/opensim-org/opensim-core/blob/main/doc/Moco/MocoExamples.dox Shows setting solver settings, customizing an initial guess, and defining a custom goal (cost term). ```cpp @example exampleSlidingMassAdvanced.cpp This example shows setting solver settings, customizing an initial guess, and defining a custom goal (cost term). See @ref mococustomgoal. ``` -------------------------------- ### Configure SimpleOptimizationExample Project with CMake Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Examples/SimpleOptimizationExample/CMakeLists.txt This CMakeLists.txt file sets up a C++ project to use OpenSim. It specifies the C++ standard, finds the OpenSim installation, builds an executable from source files, links against OpenSim libraries, and copies necessary data files to the build directory. ```cmake project(SimpleOptimizationExample) cmake_minimum_required(VERSION 3.2) # Settings. # --------- set(TARGET simpleOptimizationExample CACHE TYPE STRING) # OpenSim uses C++20 language features. set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Find and hook up to OpenSim. # ---------------------------- find_package(OpenSim REQUIRED PATHS "${OPENSIM_INSTALL_DIR}") # Configure this project. # ----------------------- file(GLOB SOURCE_FILES *.h *.cpp) add_executable(${TARGET} ${SOURCE_FILES}) target_link_libraries(${TARGET} ${OpenSim_LIBRARIES}) # This block copies the additional files into the running directory # For example vtp, obj files. Add to the end for more extentions file(GLOB DATA_FILES *.vtp *.obj *.osim) foreach(dataFile ${DATA_FILES}) add_custom_command( TARGET ${TARGET} COMMAND ${CMAKE_COMMAND} ARGS -E copy ${dataFile} ${CMAKE_BINARY_DIR}) endforeach(dataFile) ``` -------------------------------- ### Install condacolab Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 3 - Loading and Modifying OpenSim Models.ipynb Installs the condacolab package to set up the environment for OpenSim. This may require a session restart. ```python !pip install -q condacolab import condacolab condacolab.install() ``` -------------------------------- ### Add Python Examples Test Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/CMakeLists.txt Adds a test for Python example files using unittest. It specifies the working directory and the Python executable, along with arguments for the unittest module. The PYTHONPATH environment variable is set to include the examples directory. ```cmake add_test(NAME python_examples WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$" COMMAND "${Python3_EXECUTABLE}" -m unittest ${PYTHON_EXAMPLES_UNITTEST_ARGS} --verbose ) set_tests_properties(python_examples PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/examples") ``` -------------------------------- ### Copy Example Files to Run Directory Source: https://github.com/opensim-org/opensim-core/blob/main/OpenSim/Tests/ExampleLuxoMuscle/CMakeLists.txt Iterates through a list of files and copies them to the specified destination directory. This is useful for preparing test environments. ```cmake foreach(dataFile ${TEST_FILES}) file(COPY ${dataFile} DESTINATION ${TEST_DIR}) endforeach(dataFile) ``` -------------------------------- ### Create Reference Trajectory with Forward Integration Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 8 - Creating Muscle-driven Simulations with OpenSim Moco.ipynb Loads a model, sets an initial pose, and runs a forward simulation to create a reference trajectory for path fitting. The states are saved to a file. ```python # Load the model and initialize the multibody system model = osim.Model('squatToStand_3dof9musc.osim') state = model.initSystem() # Set an initial pose. coordSet = model.updCoordinateSet() coordSet.get('hip_flexion_r').setValue(state, -40 * (np.pi / 180)) coordSet.get('knee_angle_r').setValue(state, -45 * (np.pi / 180)) coordSet.get('ankle_angle_r').setValue(state, -25 * (np.pi / 180)) # Run a 0.4 second forward simulation. manager = osim.Manager(model, state) manager.integrate(0.4) # Save the states to a file. table = manager.getStatesTable() sto = osim.STOFileAdapter() if not os.path.exists('path_fitting'): os.mkdir('path_fitting') sto.write(table, os.path.join('path_fitting', 'reference_states.sto')) ``` -------------------------------- ### Remove Empty Install Directory Source: https://github.com/opensim-org/opensim-core/blob/main/dependencies/CMakeLists.txt Removes an installation directory if it is empty. This helps prevent confusion by cleaning up unused directories. ```cmake function(RemoveDefaultInstallDirIfEmpty DIR) file(GLOB CONTENTS ${DIR}/*) if(NOT CONTENTS) file(REMOVE_RECURSE ${DIR}) endif() endfunction() ``` -------------------------------- ### Install Java source files with CMake Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/OpenSimJNI/CMakeLists.txt Configures the installation of Java source files while excluding compiled .class files. ```cmake install(DIRECTORY ${SWIG_JAVA_SOURCE_BUILD_OUTPUT_DIR}/ DESTINATION "${OPENSIM_INSTALL_JAVASRCDIR}/${SWIG_JAVA_PACKAGE_PATH}" PATTERN "*.class" EXCLUDE ) ``` -------------------------------- ### Initialize AnalyzeTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 6 - Static Optimization.ipynb Creates an instance of the OpenSim AnalyzeTool for static optimization. ```python # Create analyze tool for static optimization. so_normal_RRA_analyze_tool = osim.AnalyzeTool() so_normal_RRA_analyze_tool.setName("SO_Normal_RRA") ``` -------------------------------- ### Configure Platform-Specific Dependency Installation Source: https://github.com/opensim-org/opensim-core/blob/main/cmake/CMakeLists.txt Handles the installation of dependencies for CasADi on Unix systems, specifically targeting macOS and Linux differences. ```cmake if(UNIX AND OPENSIM_COPY_DEPENDENCIES AND OPENSIM_WITH_CASADI) # Temporary hack to package dependencies on Macs. # TODO if we're building a standalone binary distribution, we should # use superbuild to build the dependencies. # TODO install(FILES # TODO /usr/local/opt/llvm/lib/libc++.1.dylib # TODO DESTINATION ${CMAKE_INSTALL_LIBDIR}) # This command must be invoked from the cmake subdirectory so that the # editing of libcasadi's link libraries is done after libcasadi.dylib # is installed (add_subdirectory(cmake) must be after # add_subdirectory(Moco)). if (OPENSIM_WITH_CASADI) get_target_property(CASADI_LIBRARY_LOCATION casadi LOCATION) get_filename_component(CASADI_LIBDIR "${CASADI_LIBRARY_LOCATION}" DIRECTORY) endif() if(APPLE) set(script ${CMAKE_CURRENT_BINARY_DIR}/OpenSimMocoInstallMacDependencyLibraries.cmake) configure_file(OpenSimMocoInstallMacDependencyLibraries.cmake.in "${script}" @ONLY) else() set(script ${CMAKE_CURRENT_BINARY_DIR}/OpenSimMocoInstallLinuxDependencyLibraries.cmake) configure_file(OpenSimMocoInstallLinuxDependencyLibraries.cmake.in "${script}" @ONLY) endif() # Variables are not forwarded to the install script, so add a line # to set the OPENSIM_WITH_CASADI variable during the install step. install(CODE "set(OPENSIM_WITH_CASADI \"${OPENSIM_WITH_CASADI}\")") install(SCRIPT "${script}") endif() ``` -------------------------------- ### Initialize InverseDynamicsTool Source: https://github.com/opensim-org/opensim-core/blob/main/Bindings/Python/tutorials/Tutorial 5 - Scaling, Inverse Kinematics, and Inverse Dynamics.ipynb Creates an instance of the InverseDynamicsTool using a specified configuration file. ```python # Create an ID object using the configuration file. inverse_dynamics_tool = osim.InverseDynamicsTool('subject01_Setup_InverseDynamics.xml') ```