Inquiry of CustomJoint and coordinate

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Fengtao Zhang
Posts: 1
Joined: Thu Oct 19, 2023 2:03 am

Inquiry of CustomJoint and coordinate

Post by Fengtao Zhang » Thu Aug 15, 2024 12:10 pm

Hi,

I am using OpenSim 4.5 and the Conda packages for Python.
I was trying to create a CustomJoint using Python. But I could not get the code to work.

I tried to use the convenience constructor to create the <coordinates> for the CustomJoint as shown below:

Code: Select all

right_hip_coord_z_r = osim.Coordinate('hip_flexion',
                                      osim.Coordinate.Rotational,
                                      2.3320524949126999e-09,
                                      -0.52359878000000004,
                                      2.0943950999999998)
right_hip_coord_z_r.setDefaultSpeedValue(0)
right_hip_coord_z_r.set_clamped(True)
right_hip_coord_z_r.set_locked(False)
right_hip_coord_z_r.set_prescribed(False)

right_hip_joint.set_coordinates(0, right_hip_coord_z_r)
However, it seemed that the motion type is not correctly assign to the coordinate. I got a error from the terminal:

Code: Select all

RuntimeError: std::exception in 'void OpenSim::Model::addJoint(OpenSim::Joint *)': Joint::getMotionType() given an invalid CoordinateIndex
        Thrown at Joint.cpp:225 in getMotionType().
And when I used the default constructor for <coordinates>, there is no attribute for assigning MotionType.


I have also tired to use upd_coordinate instead of using the coordinate constructor and set_coordinates()

Code: Select all

right_hip_coord_z_r = right_hip_joint.upd_coordinates(0)
Another error showed up:

Code: Select all

RuntimeError: std::exception in 'OpenSim::Coordinate & OpenSim::Joint::upd_coordinates(int)': SimTK Exception thrown at Array.h:563:
  Index out of range in ArrayViewConst_<T>::at(): expected 0 <= size_type(i) < 0 but size_type(i)=0.
How should I create a custom with coordinates, which has valid motion type assigned to it?
I have also attached the python file as a text file, in case my question is not clear.

Best wishes,
Fengtao.
Attachments
customjoint.txt
(6.96 KiB) Downloaded 59 times

Tags:

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Inquiry of CustomJoint and coordinate

Post by Thomas Uchida » Thu Aug 15, 2024 5:40 pm

A CustomJoint is created in Python at line 126 in test_swig_additional_interface.py here: https://github.com/opensim-org/opensim- ... ce.py#L126. Note that a SpatialTransform (https://simtk.org/api_docs/opensim/api_ ... sform.html) is created first and passed in as the last argument. The signatures of the constructors (there are two in addition to the default) can be found in the doxygen documentation here: https://simtk.org/api_docs/opensim/api_ ... Joint.html. Once the CustomJoint has been created, you should be able to access the underlying Coordinates.

POST REPLY