This vignette connects OpenCap (markerless motion capture from smartphone video) to OpenSim musculoskeletal computation and on to downstream kinematic/kinetic analysis. There are two routes, and they differ in whether they need a local OpenSim install.
OpenCap already runs OpenSim in the cloud: it scales a
subject model and solves inverse kinematics, returning the joint angles
as a .mot file. If you only need kinematics, pull that
directly – no local OpenSim is required.
To go beyond kinematics – inverse dynamics (joint moments) or static optimization (muscle activations/forces) – you run OpenSim yourself. This is an optional path: it needs a working OpenSim backend and is off by default.
PhysioOpenSim selects a backend automatically: a native
library compiled in, or the opensim-cmd command-line tool.
The native bridge is disabled by default so ordinary
installs stay dependency-free; opt in one of these ways:
# (a) put the OpenSim CLI on your PATH (no rebuild) -- e.g. from a conda install:
# mamba install -c opensim-org opensim
# (b) build PhysioOpenSim against an OpenSim SDK (configure auto-detects it):
# OPENSIM_HOME=/opt/opensim-core R CMD INSTALL PhysioOpenSim
PhysioOpenSim::opensimDiagnostics() # backend: "native", "cli", or "none"runOpenSimFromOpenCap() downloads the session’s scaled
.osim model and marker .trc, then runs the
requested tools. Inverse dynamics and static optimization need
ground-reaction forces, which markerless OpenCap does not
record – supply a measured or estimated OpenSim
ExternalLoads XML via external_loads_file.
res <- runOpenSimFromOpenCap(
session_id = "abcd1234-5678-90ab-cdef-1234567890ab",
tools = c("ik", "id", "so"),
external_loads_file = "walk_grf.xml" # required for id/so
)
res$motion # IK joint angles as a PhysioExperiment
res$outputs # parsed .mot/.sto outputs (joint angles, moments, activations)If you already have the model and markers locally (or want to reuse a model across trials), call the lower half directly:
model <- downloadOpenCapModel("abcd1234-5678-90ab-cdef-1234567890ab")
res <- runOpenSimFromMarkers(
model_file = model,
trc_file = "walk.trc",
tools = c("ik", "id", "so"),
external_loads_file = "walk_grf.xml"
)Pass dry_run = TRUE to write and inspect the OpenSim
setup XMLs without a backend – useful for debugging or
customising a template before running.
The returned PhysioExperiment objects flow into the rest
of the ecosystem:
ExternalLoads file (measured GRF, or an
estimate). Without one, only inverse kinematics runs; set
require_external_loads = FALSE for kinematics-only inverse
dynamics, which is valid only for non-contact phases (e.g. swing).PhysioOpenSim has no
Scale tool; the subject-specific model comes from OpenCap
(downloadOpenCapModel()).run_opensim_toolchain() together with
PhysioOpenSim::opensimWriteCMCSetupFromTemplate() /
opensimWriteRRASetupFromTemplate().