Spatial Vectors in Python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Juan Beret
Posts: 2
Joined: Tue Dec 13, 2016 11:26 pm

Spatial Vectors in Python

Post by Juan Beret » Wed Aug 07, 2024 1:48 pm

Hello everyone!

I am writing to ask about the use of Spatial Vectors in Python. Specifically, I am trying to calculate Coriolis forces using the following function:
Vector calcCoriolis(const State& s, const Model& model) {
Vector c;
model.getMatterSubsystem().calcResidualForceIgnoringConstraints(
s, Vector(0), Vector_<SpatialVec>(0), Vector(0), c);
return c;
}
My problem is that I am not able to correctly define the SpatialVec in Python. I am defining the Vector(0) as opensim.Vec3(0).

I would be very grateful if someone could give me a hand with this.

Tags:

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

Re: Spatial Vectors in Python

Post by Thomas Uchida » Thu Aug 08, 2024 10:32 am

The third argument of calcResidualForceIgnoringConstraints() is a Vector of SpatialVecs (doxygen: https://simtk.org/api_docs/simbody/3.5/ ... d43db05df0), which is bound to "VectorOfSpatialVec" in Python (see https://github.com/opensim-org/opensim- ... ody.i#L222).

User avatar
Juan Beret
Posts: 2
Joined: Tue Dec 13, 2016 11:26 pm

Re: Spatial Vectors in Python

Post by Juan Beret » Thu Aug 08, 2024 11:56 am

Thank you very much for your answer Thomas!
I am trying to use:
opensim.VectorOfSpatialVec(size,osim.SpatialVec(osim.Vec3(0), osim.Vec3(0)))
and the data type seems correct, but when I use calcResidualForceIgnoringConstraints function the output is:
TypeError: in method 'SimbodyMatterSubsystem_calcResidualForceIgnoringConstraints', argument 3 of type 'SimTK::Vector const &'
Any idea how I could fix this and calculate the Coriolis forces? Or is there any other python implementation for this?

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

Re: Spatial Vectors in Python

Post by Thomas Uchida » Thu Aug 08, 2024 2:23 pm

The method takes a reference. I don't know what your code looks like, but I'm guessing that you're passing in "opensim.VectorOfSpatialVec(size,osim.SpatialVec(osim.Vec3(0), osim.Vec3(0)))" as the third argument. If so, I would instead try assigning this to a variable on the line above and passing in the variable when calling calcResidualForceIgnoringConstraints(). You are unlikely to find an example that does exactly what you are trying to do, but the examples under opensim-core/Bindings/Python/examples (https://github.com/opensim-org/opensim- ... n/examples) and opensim-core/Bindings/Python/tests (https://github.com/opensim-org/opensim- ... thon/tests) often use this strategy.

POST REPLY