Skip to content

Python Moco 2D walking examples#4019

Merged
nickbianco merged 8 commits intoopensim-org:mainfrom
nicos1993:python_examples
Feb 25, 2025
Merged

Python Moco 2D walking examples#4019
nickbianco merged 8 commits intoopensim-org:mainfrom
nicos1993:python_examples

Conversation

@nicos1993
Copy link

@nicos1993 nicos1993 commented Feb 20, 2025

Building on PR #3242

Nicos


This change is Reviewable

@nickbianco
Copy link
Member

@nicos1993 you can test the examples on using the latest version of OpenSim via conda install -c opensim-org opensim (this will include Moco).

Copy link
Member

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start @nicos1993! I did a pass through and left a few comments.

It would be good to confirm that all the scripts produce the same results as the Matlab scripts.

# limitations under the License. #
# -------------------------------------------------------------------------- #

# This is a Matlab implementation of an example optimal control
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is a Python implementation..."

# Define the optimal control problem
# ==================================
track = osim.MocoTrack()
track.setName("gaitTracking")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is use single for strings, e.g., 'gaitTracking'.

# -------------------------------------------------------------------------- #
# OpenSim Moco: example2DWalking.py #
# -------------------------------------------------------------------------- #
# Copyright (c) 2019 Stanford University and the Authors #
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could set the copyright year to 2025 for all the files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be set to 2025.

# limitations under the License. #
# -------------------------------------------------------------------------- #

# This is a Matlab implementation of an example optimal control
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...Python implementation..."

# 'setContactForceThreshold()'.
#
# Users must provide the target asymmetry value via 'setTargetAsymmetry()'.
# Asymmetry values ranges from -1.0 to 1.0. For example, 0.20 is 20# positive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...0.20 is 20% positive..."

@nicos1993
Copy link
Author

Thanks for the quick review! @nickbianco Will take on board the changes!

I definitely agree that ensuring the results between python/matlab is paramount.

@nicos1993
Copy link
Author

Hey @nickbianco

I have implemented the suggestions you made! I have also confirmed that the results from these python examples match with the equivalent matlab examples.

Thanks,

Nicos

Copy link
Member

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @nicos1993!

A couple minor things left: 1) you need to update the copyright year on two of the files and 2) can you confirm that the reference files install correctly? You could either install locally or download a GitHub Actions artifact to check.

# -------------------------------------------------------------------------- #
# OpenSim Moco: example2DWalking.py #
# -------------------------------------------------------------------------- #
# Copyright (c) 2019 Stanford University and the Authors #
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be set to 2025.

# -------------------------------------------------------------------------- #
# OpenSim Moco: example2DWalkingMetabolics.py #
# -------------------------------------------------------------------------- #
# Copyright (c) 2021 Stanford University and the Authors #
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set to 2025.

install(FILES ${EXAMPLE_2D_WALKING_FILES}
DESTINATION "${OPENSIM_INSTALL_MATLABEXDIR}/Moco/example2DWalking")

file(COPY ${EXAMPLE_2D_WALKING_FILES}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that you tested that this CMake code correctly installs the reference files in the Python example directory?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that it installs the reference files except the Geometry folder. The CMake file doesn't seem to mention anything about the Geometry folder for the equivalent matlab examples, so I am wondering if there is another file that needs to be tweaked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no Geometry folder for this example, so no worries.

Copy link
Member

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Good work @nicos1993!

@nickbianco nickbianco merged commit a7f7439 into opensim-org:main Feb 25, 2025
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants