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.
Spatial Vectors in Python
- Juan Beret
- Posts: 2
- Joined: Tue Dec 13, 2016 11:26 pm
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Spatial Vectors in Python
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).
- Juan Beret
- Posts: 2
- Joined: Tue Dec 13, 2016 11:26 pm
Re: Spatial Vectors in Python
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?
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?
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Spatial Vectors in Python
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.