MocoTrack will not initialize

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Madison Wissman
Posts: 5
Joined: Wed Aug 23, 2023 12:04 pm

MocoTrack will not initialize

Post by Madison Wissman » Tue May 28, 2024 10:25 am

Hi!

I am learning to work with Moco and trying to run MocoTrack based on the tracking_walking.py file from the paper code. I started with the code in the folder and then changed the types of tracking scenarios I'd like to run, and tried to change little else about the code other than to not include EMG data.

Code: Select all

import os
import numpy as np
import copy
import re
import matplotlib
import matplotlib.transforms as mtransforms
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.cm as cm
import cv2

import opensim as osim
os.add_dll_directory('C:/OpenSim 4.5/bin/')
print('Added directory')

from moco_paper_result_noEMG import MocoPaperResult

import utilities
from utilities import plot_joint_moment_breakdown
from utilities import toarray

root_dir=os.getcwd()

class MocoTrackConfig:
    def __init__(self, name, legend_entry, tracking_weight, effort_weight,
                 color, linestyle='-',
                 mesh_interval=0.014, guess=None, flags=[]):
        self.name = name
        self.legend_entry = legend_entry
        self.tracking_weight = tracking_weight
        self.effort_weight = effort_weight
        self.color = color
        self.linestyle = linestyle
        self.mesh_interval = mesh_interval
        # If guess is 'None', we use the solution from the inverse problem.
        self.guess = guess
        self.flags = flags
        self.tracking_solution_relpath_prefix = 'moco_results/motion_tracking_walking_solution'

    def get_solution_path(self, root_dir):
        return os.path.join(root_dir,
                            f'{self.tracking_solution_relpath_prefix}_'
                            f'{self.name}.sto')

    def get_solution_path_fullcycle(self, root_dir):
        return os.path.join(root_dir,
                            f'{self.tracking_solution_relpath_prefix}_'
                            f'{self.name}_fullcycle.sto')

    def get_solution_path_grfs(self, root_dir):
        return os.path.join(root_dir,
                            f'{self.tracking_solution_relpath_prefix}_'
                            f'{self.name}_fullcycle_grfs.sto')
    
    print('Configured MocoTrack')


class MotionTrackingWalking(MocoPaperResult):
    def __init__(self):
        super(MotionTrackingWalking, self).__init__()
        print('initialized')
        self.initial_time = 0.50
        self.half_time = 1.10
        self.final_time = 1.70
        print('final time set')
        duration = self.half_time - self.initial_time
        num_mesh_intervals = 40
        mesh_interval = duration / num_mesh_intervals
        self.passive_forces = False
        self.inverse_solution_relpath = \
            'moco_results/motion_tracking_walking_inverse_solution.sto'
        self.cmap = cm.get_cmap('nipy_spectral')
        self.config_track = MocoTrackConfig(
            name='track',
            legend_entry='normal',
            tracking_weight=10,
            effort_weight=10,
            mesh_interval=mesh_interval,
            color='black')
        self.config_weakhipabd = MocoTrackConfig(
            name='weakhipabd',
            legend_entry='weak hip abductors',
            tracking_weight=10,
            effort_weight=10,
            mesh_interval=mesh_interval,
            color=self.cmap(0.5),
            guess='track',
            flags=['weakhipabd'])
        self.configs = [
            self.config_track,
            self.config_weakhipabd
        ]
        self.config_map = {config.name: config for config in self.configs}
No error message is thrown, but I've debugged the code and have found that it stops running after the class MotionTrackingWalking(MocoPaperResult) line. Any help anyone has for working with the code from the Moco paper or this specific file would be great, thanks!

User avatar
Nicholas Bianco
Posts: 1050
Joined: Thu Oct 04, 2012 8:09 pm

Re: MocoTrack will not initialize

Post by Nicholas Bianco » Tue May 28, 2024 10:48 pm

Hi Madison,

I need a little more information to help debug.

What OpenSim version are you using? And how are you creating your Python environment?

-Nick

User avatar
Madison Wissman
Posts: 5
Joined: Wed Aug 23, 2023 12:04 pm

Re: MocoTrack will not initialize

Post by Madison Wissman » Wed May 29, 2024 9:22 am

Thanks for the quick response!

I am using OpenSim 4.5 and running Python in VS Code via Anaconda. I am able to get other files to run including the Moco Track and Moco Inverse example codes included in the OpenSim download.

User avatar
Nicholas Bianco
Posts: 1050
Joined: Thu Oct 04, 2012 8:09 pm

Re: MocoTrack will not initialize

Post by Nicholas Bianco » Thu May 30, 2024 9:28 am

Hi Madison,

Thanks for the information, but I think I see the issue now. The script you've provided is only implementing the classes that define the tracking problem. You need to instantiate an object of MotionTrackingWalking in order to actually run the problem.

This file in the Moco paper repo will be helpful as a guide: https://github.com/stanfordnmbl/mocopap ... copaper.py.

Best,
Nick

POST REPLY