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)
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().
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)
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.
I have also attached the python file as a text file, in case my question is not clear.
Best wishes,
Fengtao.