-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'InverseKinematicsSolver' object has no attribute 'addOrientationValuesToTrack' #3415
Comments
The API referred to here is obsolete and was only used during the development of 4.3 but then got subsumed by more recent versions. Please point to the code base using this interface so we can upgrade or use it with pre-built version of the libraries consistent with this API. |
Hi @aymanhab thanks for the reply, this makes sense. The code base that was using it was the Github Repo of OpensenseRT By any chance, would you know how i could replace that line? Thank you! |
@aymanhab I would like to provide an update. It seems as though that the Error 1 - BufferedOrientationsReference object DeclarationquatTable = osim.TimeSeriesTableQuaternion(sto_filename)
orientationsData = osim.OpenSenseUtilities.convertQuaternionsToRotations(quatTable)
oRefs = osim.BufferedOrientationsReference(orientationsData) #error
I am not sure why Error 2 - putValues methodquatTable = osim.TimeSeriesTableQuaternion(sto_filename)
orientationsData = osim.OpenSenseUtilities.convertQuaternionsToRotations(quatTable)
rowVecView = orientationsData.getNearestRow(time_s)
rowVec = osim.RowVectorRotation(rowVecView)
oRefs.putValues(time_s+dt, rowVecView)
I find this strange as well, because there was a very similar line that was one in the testLiveIK.cpp file, in this line here. From what i understand, the reason why this error is thrown is due to I'm not sure the reason for these errors. After debugging, I have a feeling there might be an issue with the python build, perhaps the SWIG script had some errors leading to some public methods not being exported when the python version was built. Hope you can provide some assistance by clarifying if there is indeed a bug with SWIG, a problem with my python build or a misunderstanding of the C++ API. Thank you. |
This is still a problem. I have tried changing to Swig version 4.0.2 to see if it is a problem with the newest version. I also noticed that the real time part of opensense (specifically the bufferedOrientationReference part) is not part of the test suite. |
I found the problem. Evidentially there were some missing types. While it might have worked for c++, I think that it confused Swig. I fixed it here: b6862e9. I will plan on making a PR this week. I might add some tests related to this when building so that we can catch some of these problems in the future. |
Good catch @RTnhN! Happy to review your PR whenever it comes in. |
Thanks, @nickbianco! The PR is #3644. |
We should be able to close this issue now that the PR is merged, right? |
Sure, closing! |
I realized that this is not completely solved. SWIG has a problem with initializing constructors from base classes using You can see where they fixed the problem here: https://www.swig.org/Doc4.2/CPlusPlus11.html#CPlusPlus11_object_construction_improvement (notice that they say that using the So I think the solution would be to change to SWIG 4.2.0, but this is kind of a headache. I have done a little work with it, and it looks like they made a bunch of changes, so it is not as easy as changing all references of SWIG 4.1.1 to 4.2.0. For example, they removed an interface file
|
@RTnhN Thanks for reporting, with that should this issue be reopened? Also did the previous commit make any difference to justify patching into 4.5 release as it stands? Thank you |
@aymanhab Maybe it might be good to open up another issue and reference this one. This issue had a bunch of different problems, some of which were resolved. The previous commit does make a difference. It resolved one of the problems in this issue, so I think it justifies patching into 4.5. |
Acutally, I think it would be good to open it again. |
I tried manually changing the // CONSTRUCTION
//--------------------------------------------------------------------------
BufferedOrientationsReference();
+ // Constructor with orientation file name and model units
+ BufferedOrientationsReference(const std::string& orientationFileName,
+ Units modelUnits=Units(Units::Radians))
+ : OrientationsReference(orientationFileName, modelUnits) {}
+ // Constructor with TimeSeriesTable and optional OrientationWeightSet
+ BufferedOrientationsReference(const TimeSeriesTable_<SimTK::Rotation_<double>>& orientationData,
+ const Set<OrientationWeight>* orientationWeightSet=nullptr)
+ : OrientationsReference(orientationData, orientationWeightSet) {}
BufferedOrientationsReference(
const BufferedOrientationsReference&) = default;
BufferedOrientationsReference(BufferedOrientationsReference&&) = default;
BufferedOrientationsReference& operator=(
const BufferedOrientationsReference&) = default;
- // Use OrientationsReference convenience costructor from TimeSeriesTable
- using OrientationsReference::OrientationsReference;
virtual ~BufferedOrientationsReference() {} Using this as a reference, I made some tweaks to Patrick's code, and while I was able to create a copy of BufferedOrientationsReference with a data table so that I could get the names of the segments, I ran into a problem. When I ran approximately these commands, I got the following runtime error: quatTable = osim.TimeSeriesTableQuaternion(sto_filename)
orientationsData = osim.OpenSenseUtilities.convertQuaternionsToRotations(quatTable)
oRefs = osim.BufferedOrientationsReference(orientationsData)
oRefs.setDefaultWeight(1.0)
init_state = model.initSystem()
mRefs = osim.MarkersReference()
coordinateReferences = osim.SimTKArrayCoordinateReference()
model.initSystem()
s0 = init_state
ikSolver = osim.InverseKinematicsSolver(model, mRefs, oRefs, coordinateReferences, constraint_var)
ikSolver.setAccuracy = accuracy
s0.setTime(0.)
ikSolver.setAdvanceTimeFromReference(True)
ikSolver.assemble(s0)
This is exactly what is expected if I was using the "OrientationsReference" object in the opensim-core/OpenSim/Simulation/OrientationsReference.h Lines 129 to 134 in 98c70b1
I was explicitly not using the base As a sanity check, the I also tried not using "setAdvanceTimeFromReference" and manually adjusting the time, but that just gave me a "key not found" error which is what is expected if it was calling the base method and was trying to find a value in the table just used to construct the Do you have any idea why the inheritance is not working as expected? |
Thanks for investigating this, I'd try a constructor for the solver that takes the shared_ptr to BufferedOrientationsReference to test if this is a swig issue or something else as handling of smart pointers across the interface is rather fragile. Let me know what you find out. Thank you |
That's a great point. I can try that and see if that fixes it. Thanks for the idea. |
That does fix the problem. I found out that I also needed to update the swig interface file to allow both shared pointers and regular pointers like what is done with the MarkerReference and the regular OrientationReference. opensim-core/Bindings/simulation.i Lines 224 to 240 in 120db03
The problem that I have now is that the ikSolver gets hung whenever I use the Edit: I wanted to recompile the project without the java bindings and in the RelwithDebInfo in case I needed to directly debug the c++ code, so I did a totally clean build. This gave me a chance to test the regular OrientationsReference. Using the following code after running the import opensim as osim
from math import pi
# Set variables to use
modelFileName = 'calibrated_Rajagopal_2015.osim'; # The path to an input model
orientationsFileName = 'MT_012005D6_009-001_orientations.sto'; # The path to orientation data for calibration
model = osim.Model(modelFileName)
quatTable = osim.TimeSeriesTableQuaternion(orientationsFileName)
orientationsData = osim.OpenSenseUtilities.convertQuaternionsToRotations(quatTable)
oRefs = osim.BufferedOrientationsReference(orientationsData)
init_state = model.initSystem()
mRefs = osim.MarkersReference()
coordinateReferences = osim.SimTKArrayCoordinateReference()
model.initSystem()
s0 = init_state
ikSolver = osim.InverseKinematicsSolver(model, mRefs, oRefs, coordinateReferences, 0.1)
s0.setTime(0.)
ikSolver.setAccuracy(0.1)
ikSolver.assemble(s0)
for t in oRefs.getTimes():
s0.setTime(t)
ikSolver.track(s0) I'm going to go back and add the BufferedOrientaitonsReference changes back and see if it will work with the values being added with the Edit again: I am going though adding logging to see where it is getting hung. So far, it seems that there might be a problem with the data queue. |
Okay, I added the right constructor and it works somewhat. I can put data into the data queue for the bufferedOrientationsReference, but it still hangs at the When digging into how Swig deals with smart pointers, I did see some things that might need to change in the interface files for it to work. This is all from the SWIG documentation on smart pointers
When I compiled with the right order (macro before definition), it gave me the expected warnings:
The macro is seemingly used correctly in most of the repo except for below where they should be moved up: opensim-core/Bindings/simulation.i Lines 213 to 223 in f291e0b
Actually, when I rearrange it, I get this error:
When I researched it, it turned out to be the problem of not having all of the base classes defined as smart pointers based off of this stack overflow question. I think the solution to this will be a lot harder than expected. I am still trying things, but I just wanted to get an update out. |
I don't think that using smart pointers will be a viable solution since the swig support for them is lacking and is causing major problems. It seems that the only way to get real-time inverse kinematics going is to do something similar to how the iksolver did real time in the past. This involves using a method connected to the iksolver object rather than the directly on the orientaionsReference object. I have tested the following addition into the InverseKinematicsSolver class, and it is able to run the RealTimeKin code. void InverseKinematicsSolver::updateOrientationData(double time, const SimTK::RowVectorView_<SimTK::Rotation_<double>>& dataRow)
{
_orientationsReference->putValues(time, dataRow);
} What do you think are next steps? I could just use my fork of the repo for my work, but I would rather find a workable solution for the main repo. |
Thanks for your work on this @RTnhN much appreciated 👍 It would be good to take a look before lifting the API to the solver (because this type of call is supported only for the special BufferedOrientationReference and not any other Reference type so could be confusing to users). I totally agree that SWIG handling of shared_ptr is poorly documented, but hopefully we can figure out the issue/learn something from it for wider use before changing the API on the c++ side. Maybe a PR wit the problem code would help. Thanks again |
Okay, I created a PR so that you can see the code so far. I did find out that the namespace was missing. Once I added it, I did not have any problems with it compiling, but it still does not work. I put data in the queue, but the queue is empty when I go to get data. |
I am currently attempting to recreate the OpenSenseRT. I have successfully flashed a microsd card with Ubuntu Server 20.04, built opensim on Linux and prepared it for scripting in python.
However, while following the file ik_streaming.py, I got stuck, and was unable to run the full program due to the error as written in the title.
I'm not too sure why Im facing such an error. From looking through the documentation, I do not find any methods that mention addOrientationValuesToTrack. However, OpenSenseRT is based on a research paper and its weird there is a function that does not exist. Are there other alternatives to that line which I could consider to continue on with the OpenSenseRT code?
The text was updated successfully, but these errors were encountered: