| Title: | Native OpenSim C++ Integration for PhysioExperiment |
|---|---|
| Description: | Provides a native OpenSim C++ bridge for R via Rcpp. The package exposes OpenSim model-level operations to support biomechanics workflows in the Physio ecosystem. OpenSim linkage is optional at build time; when OpenSim is not detected, the package installs with informative runtime errors for OpenSim-dependent calls. |
| Authors: | Yusuke Matsui [aut, cre] |
| Maintainer: | Yusuke Matsui <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-16 05:25:17 UTC |
| Source: | https://github.com/x-biosignal/PhysioOpenSim |
Returns whether this package was compiled with OpenSim headers and libraries linked into the native code.
opensimAvailable()opensimAvailable()
TRUE if OpenSim native support is available, otherwise FALSE.
opensimAvailable()opensimAvailable()
Show Build Configuration for OpenSim Native Bridge
opensimBuildConfig()opensimBuildConfig()
A list containing compilation status and build metadata.
cfg <- opensimBuildConfig() cfg$package cfg$opensim_enabledcfg <- opensimBuildConfig() cfg$package cfg$opensim_enabled
Check Whether OpenSim CLI Is Available
opensimCLIAvailable(cli = NULL)opensimCLIAvailable(cli = NULL)
cli |
Optional command or absolute path. |
TRUE if CLI command is resolvable, otherwise FALSE.
opensimCLIAvailable()opensimCLIAvailable()
Resolves the command path used to invoke OpenSim CLI.
opensimCLIPath(cli = NULL)opensimCLIPath(cli = NULL)
cli |
Optional command or absolute path. Defaults to |
A character scalar path to executable command.
## Not run: opensimCLIPath() opensimCLIPath("/usr/local/bin/opensim-cmd") ## End(Not run)## Not run: opensimCLIPath() opensimCLIPath("/usr/local/bin/opensim-cmd") ## End(Not run)
Finalize OpenSim Model Connections
opensimFinalizeConnections(model)opensimFinalizeConnections(model)
model |
A |
The input model handle (invisibly).
## Not run: model <- opensimLoadModel("gait2392.osim") opensimFinalizeConnections(model) ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimFinalizeConnections(model) ## End(Not run)
Load an OpenSim Model as a Native External Pointer
opensimLoadModel(path)opensimLoadModel(path)
path |
Path to an OpenSim model file ( |
A PhysioOpenSimModel external pointer handle.
## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelName(model) ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelName(model) ## End(Not run)
List Core OpenSim Model Component Names
opensimModelComponents(model)opensimModelComponents(model)
model |
A |
Named list with vectors for body, joint, marker, muscle, and coordinate names.
## Not run: model <- opensimLoadModel("gait2392.osim") comps <- opensimModelComponents(model) comps$bodies comps$muscles ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") comps <- opensimModelComponents(model) comps$bodies comps$muscles ## End(Not run)
Initialize OpenSim Model System State
opensimModelInitialize(model)opensimModelInitialize(model)
model |
A |
The input model handle (invisibly).
## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelInitialize(model) opensimModelIsInitialized(model) # TRUE ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelInitialize(model) opensimModelIsInitialized(model) # TRUE ## End(Not run)
Check Whether an OpenSim Model Handle Is Initialized
opensimModelIsInitialized(model)opensimModelIsInitialized(model)
model |
A |
TRUE when model state has been initialized by OpenSim.
## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelIsInitialized(model) ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelIsInitialized(model) ## End(Not run)
Get OpenSim Model Name
opensimModelName(model)opensimModelName(model)
model |
A |
Character scalar model name.
## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelName(model) ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimModelName(model) ## End(Not run)
Loads an .osim model (or uses a loaded model handle) and returns
structural summary information.
opensimModelSummary(path)opensimModelSummary(path)
path |
Path to an OpenSim model file ( |
A named list with model metadata (model_name, n_bodies,
n_joints, n_markers, n_muscles, n_coordinates, total_mass,
initialized).
## Not run: info <- opensimModelSummary("gait2392.osim") info$model_name info$n_muscles # Also works with a loaded model handle model <- opensimLoadModel("gait2392.osim") opensimModelSummary(model) ## End(Not run)## Not run: info <- opensimModelSummary("gait2392.osim") info$model_name info$n_muscles # Also works with a loaded model handle model <- opensimLoadModel("gait2392.osim") opensimModelSummary(model) ## End(Not run)
Run OpenSim Analyze Tool
opensimRunAnalyze( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )opensimRunAnalyze( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
See opensimRunTool().
## Not run: result <- opensimRunAnalyze("analyze_setup.xml") result$status ## End(Not run)## Not run: result <- opensimRunAnalyze("analyze_setup.xml") result$status ## End(Not run)
Run OpenSim Computed Muscle Control Tool
opensimRunCMC( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )opensimRunCMC( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
See opensimRunTool().
## Not run: result <- opensimRunCMC("cmc_setup.xml") result$status ## End(Not run)## Not run: result <- opensimRunCMC("cmc_setup.xml") result$status ## End(Not run)
Run OpenSim Inverse Dynamics Tool
opensimRunID( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )opensimRunID( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
See opensimRunTool().
## Not run: result <- opensimRunID("id_setup.xml") result$status ## End(Not run)## Not run: result <- opensimRunID("id_setup.xml") result$status ## End(Not run)
Run OpenSim Inverse Kinematics Tool
opensimRunIK( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )opensimRunIK( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
See opensimRunTool().
## Not run: result <- opensimRunIK("ik_setup.xml") result$status ## End(Not run)## Not run: result <- opensimRunIK("ik_setup.xml") result$status ## End(Not run)
Run OpenSim Residual Reduction Algorithm Tool
opensimRunRRA( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )opensimRunRRA( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
See opensimRunTool().
## Not run: result <- opensimRunRRA("rra_setup.xml") result$status ## End(Not run)## Not run: result <- opensimRunRRA("rra_setup.xml") result$status ## End(Not run)
Run OpenSim Static Optimization Tool
opensimRunSO( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )opensimRunSO( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
See opensimRunTool().
## Not run: result <- opensimRunSO("so_setup.xml") result$status ## End(Not run)## Not run: result <- opensimRunSO("so_setup.xml") result$status ## End(Not run)
Executes a setup XML through native OpenSim bindings (when available) or through OpenSim CLI.
opensimRunTool( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli"), tool_type = c("tool", "ik", "id", "so", "analyze", "cmc", "rra") )opensimRunTool( setup_file, workdir = NULL, cli = NULL, extra_args = character(), timeout_sec = 0L, fail_on_error = TRUE, execution = c("auto", "native", "cli"), tool_type = c("tool", "ik", "id", "so", "analyze", "cmc", "rra") )
setup_file |
Path to OpenSim tool setup XML. |
workdir |
Optional working directory. |
cli |
Optional command or absolute path (CLI mode only). |
extra_args |
Optional extra CLI args appended after setup file. |
timeout_sec |
Timeout in seconds for CLI execution (0 disables timeout). |
fail_on_error |
If |
execution |
Execution backend: |
tool_type |
Tool flavor token: |
A named list with command metadata and logs.
## Not run: result <- opensimRunTool("ik_setup.xml") result$status result$stdout # Force CLI backend with extra arguments opensimRunTool("ik_setup.xml", execution = "cli", extra_args = "--visualize") ## End(Not run)## Not run: result <- opensimRunTool("ik_setup.xml") result$status result$stdout # Force CLI backend with extra arguments opensimRunTool("ik_setup.xml", execution = "cli", extra_args = "--visualize") ## End(Not run)
Save OpenSim Model to File
opensimSaveModel(model, output_file)opensimSaveModel(model, output_file)
model |
A |
output_file |
Output path for model XML. |
Normalized output path.
## Not run: model <- opensimLoadModel("gait2392.osim") opensimSetModelName(model, "modified") opensimSaveModel(model, "gait2392_modified.osim") ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimSetModelName(model, "modified") opensimSaveModel(model, "gait2392_modified.osim") ## End(Not run)
Set OpenSim Model Name
opensimSetModelName(model, name)opensimSetModelName(model, name)
model |
A |
name |
New model name. |
The input model handle (invisibly).
## Not run: model <- opensimLoadModel("gait2392.osim") opensimSetModelName(model, "my_model") opensimModelName(model) # "my_model" ## End(Not run)## Not run: model <- opensimLoadModel("gait2392.osim") opensimSetModelName(model, "my_model") opensimModelName(model) # "my_model" ## End(Not run)
Convenience wrapper around opensimWriteToolSetupFromTemplate() for
common AnalyzeTool tags.
opensimWriteAnalyzeSetupFromTemplate( template_file, output_file, model_file, coordinates_file = NULL, external_loads_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )opensimWriteAnalyzeSetupFromTemplate( template_file, output_file, model_file, coordinates_file = NULL, external_loads_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )
template_file |
Path to Analyze template XML. |
output_file |
Path to output Analyze setup XML. |
model_file |
Path to |
coordinates_file |
Optional path to coordinates/motion file. |
external_loads_file |
Optional path to external loads XML. |
time_range |
Optional numeric length-2 vector ( |
results_directory |
Optional output directory. |
extra_fields |
Optional named list of additional XML tag replacements. |
strict |
Passed to |
See opensimWriteToolSetupFromTemplate().
## Not run: opensimWriteAnalyzeSetupFromTemplate( template_file = "analyze_template.xml", output_file = "analyze_setup.xml", model_file = "gait2392.osim", coordinates_file = "ik_output.mot" ) ## End(Not run)## Not run: opensimWriteAnalyzeSetupFromTemplate( template_file = "analyze_template.xml", output_file = "analyze_setup.xml", model_file = "gait2392.osim", coordinates_file = "ik_output.mot" ) ## End(Not run)
Convenience wrapper around opensimWriteToolSetupFromTemplate() for
common CMCTool tags.
opensimWriteCMCSetupFromTemplate( template_file, output_file, model_file, desired_kinematics_file = NULL, external_loads_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )opensimWriteCMCSetupFromTemplate( template_file, output_file, model_file, desired_kinematics_file = NULL, external_loads_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )
template_file |
Path to CMC template XML. |
output_file |
Path to output CMC setup XML. |
model_file |
Path to |
desired_kinematics_file |
Optional path to desired kinematics file. |
external_loads_file |
Optional path to external loads XML. |
time_range |
Optional numeric length-2 vector ( |
results_directory |
Optional output directory. |
extra_fields |
Optional named list of additional XML tag replacements. |
strict |
Passed to |
See opensimWriteToolSetupFromTemplate().
## Not run: opensimWriteCMCSetupFromTemplate( template_file = "cmc_template.xml", output_file = "cmc_setup.xml", model_file = "gait2392.osim", desired_kinematics_file = "ik_output.mot" ) ## End(Not run)## Not run: opensimWriteCMCSetupFromTemplate( template_file = "cmc_template.xml", output_file = "cmc_setup.xml", model_file = "gait2392.osim", desired_kinematics_file = "ik_output.mot" ) ## End(Not run)
Convenience wrapper around opensimWriteToolSetupFromTemplate() for
common Inverse Dynamics tags.
opensimWriteIDSetupFromTemplate( template_file, output_file, model_file, coordinates_file, output_gen_force_file, external_loads_file = NULL, time_range = NULL, lowpass_cutoff_frequency_for_coordinates = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )opensimWriteIDSetupFromTemplate( template_file, output_file, model_file, coordinates_file, output_gen_force_file, external_loads_file = NULL, time_range = NULL, lowpass_cutoff_frequency_for_coordinates = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )
template_file |
Path to ID template XML. |
output_file |
Path to output ID setup XML. |
model_file |
Path to |
coordinates_file |
Path to coordinates/motion file (typically |
output_gen_force_file |
Path to generalized force output file ( |
external_loads_file |
Optional path to external loads XML. |
time_range |
Optional numeric length-2 vector ( |
lowpass_cutoff_frequency_for_coordinates |
Optional numeric cutoff. |
results_directory |
Optional output directory. |
extra_fields |
Optional named list of additional XML tag replacements. |
strict |
Passed to |
See opensimWriteToolSetupFromTemplate().
## Not run: opensimWriteIDSetupFromTemplate( template_file = "id_template.xml", output_file = "id_setup.xml", model_file = "gait2392.osim", coordinates_file = "ik_output.mot", output_gen_force_file = "id_output.sto", time_range = c(0.5, 2.0) ) ## End(Not run)## Not run: opensimWriteIDSetupFromTemplate( template_file = "id_template.xml", output_file = "id_setup.xml", model_file = "gait2392.osim", coordinates_file = "ik_output.mot", output_gen_force_file = "id_output.sto", time_range = c(0.5, 2.0) ) ## End(Not run)
Convenience wrapper around opensimWriteToolSetupFromTemplate() for
common Inverse Kinematics tags.
opensimWriteIKSetupFromTemplate( template_file, output_file, model_file, marker_file, output_motion_file, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )opensimWriteIKSetupFromTemplate( template_file, output_file, model_file, marker_file, output_motion_file, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )
template_file |
Path to IK template XML. |
output_file |
Path to output IK setup XML. |
model_file |
Path to |
marker_file |
Path to marker trajectory file (typically |
output_motion_file |
Path to IK output motion file ( |
time_range |
Optional numeric length-2 vector ( |
results_directory |
Optional output directory. |
extra_fields |
Optional named list of additional XML tag replacements. |
strict |
Passed to |
See opensimWriteToolSetupFromTemplate().
## Not run: opensimWriteIKSetupFromTemplate( template_file = "ik_template.xml", output_file = "ik_setup.xml", model_file = "gait2392.osim", marker_file = "walking.trc", output_motion_file = "ik_output.mot", time_range = c(0.5, 2.0) ) ## End(Not run)## Not run: opensimWriteIKSetupFromTemplate( template_file = "ik_template.xml", output_file = "ik_setup.xml", model_file = "gait2392.osim", marker_file = "walking.trc", output_motion_file = "ik_output.mot", time_range = c(0.5, 2.0) ) ## End(Not run)
Convenience wrapper around opensimWriteToolSetupFromTemplate() for
common RRATool tags.
opensimWriteRRASetupFromTemplate( template_file, output_file, model_file, desired_kinematics_file = NULL, external_loads_file = NULL, output_model_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )opensimWriteRRASetupFromTemplate( template_file, output_file, model_file, desired_kinematics_file = NULL, external_loads_file = NULL, output_model_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )
template_file |
Path to RRA template XML. |
output_file |
Path to output RRA setup XML. |
model_file |
Path to |
desired_kinematics_file |
Optional path to desired kinematics file. |
external_loads_file |
Optional path to external loads XML. |
output_model_file |
Optional path to adjusted model output ( |
time_range |
Optional numeric length-2 vector ( |
results_directory |
Optional output directory. |
extra_fields |
Optional named list of additional XML tag replacements. |
strict |
Passed to |
See opensimWriteToolSetupFromTemplate().
## Not run: opensimWriteRRASetupFromTemplate( template_file = "rra_template.xml", output_file = "rra_setup.xml", model_file = "gait2392.osim", desired_kinematics_file = "ik_output.mot", output_model_file = "gait2392_rra.osim" ) ## End(Not run)## Not run: opensimWriteRRASetupFromTemplate( template_file = "rra_template.xml", output_file = "rra_setup.xml", model_file = "gait2392.osim", desired_kinematics_file = "ik_output.mot", output_model_file = "gait2392_rra.osim" ) ## End(Not run)
Convenience wrapper around opensimWriteToolSetupFromTemplate() for
common Static Optimization tags.
opensimWriteSOSetupFromTemplate( template_file, output_file, model_file, coordinates_file, external_loads_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )opensimWriteSOSetupFromTemplate( template_file, output_file, model_file, coordinates_file, external_loads_file = NULL, time_range = NULL, results_directory = NULL, extra_fields = list(), strict = TRUE )
template_file |
Path to SO template XML. |
output_file |
Path to output SO setup XML. |
model_file |
Path to |
coordinates_file |
Path to coordinates/motion file (typically |
external_loads_file |
Optional path to external loads XML. |
time_range |
Optional numeric length-2 vector ( |
results_directory |
Optional output directory. |
extra_fields |
Optional named list of additional XML tag replacements. |
strict |
Passed to |
See opensimWriteToolSetupFromTemplate().
## Not run: opensimWriteSOSetupFromTemplate( template_file = "so_template.xml", output_file = "so_setup.xml", model_file = "gait2392.osim", coordinates_file = "ik_output.mot", time_range = c(0.5, 2.0) ) ## End(Not run)## Not run: opensimWriteSOSetupFromTemplate( template_file = "so_template.xml", output_file = "so_setup.xml", model_file = "gait2392.osim", coordinates_file = "ik_output.mot", time_range = c(0.5, 2.0) ) ## End(Not run)
Replaces tag values in an existing OpenSim setup XML template. This function is tool-agnostic and can be used for IK/ID/SO/RRA/CMC templates.
opensimWriteToolSetupFromTemplate( template_file, output_file, fields, strict = TRUE )opensimWriteToolSetupFromTemplate( template_file, output_file, fields, strict = TRUE )
template_file |
Path to template XML. |
output_file |
Path to output XML. |
fields |
Named list of replacement values keyed by XML tag name. |
strict |
If |
A named list with output_file, applied_tags, and missing_tags.
# Create a minimal template in a temp file tpl <- tempfile(fileext = ".xml") writeLines(c( "<OpenSimDocument>", " <model_file>Unassigned</model_file>", " <time_range>0 1</time_range>", "</OpenSimDocument>" ), tpl) out <- tempfile(fileext = ".xml") result <- opensimWriteToolSetupFromTemplate( template_file = tpl, output_file = out, fields = list(model_file = "my_model.osim", time_range = "0.5 2.0") ) result$applied_tags readLines(result$output_file)# Create a minimal template in a temp file tpl <- tempfile(fileext = ".xml") writeLines(c( "<OpenSimDocument>", " <model_file>Unassigned</model_file>", " <time_range>0 1</time_range>", "</OpenSimDocument>" ), tpl) out <- tempfile(fileext = ".xml") result <- opensimWriteToolSetupFromTemplate( template_file = tpl, output_file = out, fields = list(model_file = "my_model.osim", time_range = "0.5 2.0") ) result$applied_tags readLines(result$output_file)