Page 1 of 1

study.visualize(predict_solution) show only a white background

Posted: Wed Oct 25, 2023 7:00 am
by anacsousa
Hello everyone,

I am facing an issue with visualize(predict_solution), it shows an all-white screen. I have run all Moco examples with the visualiser without any issues. Moreover, when I open the GUI, load the model and then load my solution (.sto), it works fine. The problem is with running the visualiser with my solution through python. Therefore, I can still visualise my solution, but not without the trouble of opening the GUI and loading the solution.

Code

Code: Select all


import os
os.add_dll_directory("C:/OpenSim 4.4/bin")
import opensim as osim
import moco_solve_cycling_helpers as helpers
import numpy as np

crank_torque_driven_model = helpers.get_crank_torque_driven_model()

study = osim.MocoStudy()

problem = study.updProblem()
problem.setModelAsCopy(crank_torque_driven_model)
problem.setTimeBounds(0.0, 2.0)
problem.setStateInfoPattern('/jointset/gear/gear/value', [], 0.0, np.deg2rad(-180.0))
problem.setStateInfoPattern('/jointset/.*/speed', [], 0.0, [])

controlGoal = osim.MocoControlGoal('myeffort')
problem.addGoal(controlGoal)

solver = study.initCasADiSolver()
solver.set_num_mesh_intervals(25)
solver.set_optim_convergence_tolerance(1e-3)
solver.set_optim_constraint_tolerance(1e-3)

predict_solution = study.solve()
predict_solution.write('Results/torque_driven_predicted_cycling_solution.sto')
study.visualize(predict_solution)

Expected behaviour
I expected to visualise my predicted solution once that is finished.

Actual behaviour
It just opens the visualiser with a white background (see Figure).
all_white.png
all_white.png (8.96 KiB) Viewed 265 times
Additional context

- Actually, I'm using OpenSim 4.4, not 4.3.
- I have some objects in the model. I've tried adding them to the main python script path. But no luck.
- I added my model in case someone wants to try, the one I'm playing with is the crank_torque_driven_model.

I would greatly appreciate any help or guidance you can provide. Thank you in advance for your assistance!

Best regards,
Ana

---

Re: study.visualize(predict_solution) show only a white background

Posted: Thu Oct 26, 2023 6:42 am
by kernalnet
Hi, I'm not sure whether this could be a solution. Have you tried defining the geometry path?

Code: Select all

osim.ModelVisualizer.addDirToGeometrySearchPaths('./geometry')

Re: study.visualize(predict_solution) show only a white background

Posted: Mon Oct 30, 2023 6:40 am
by anacsousa
Hi Mohammadreza,

That was a great suggestion, but unfortunetly it didn't work...

I tried:

Code: Select all

    osim.ModelVisualizer.addDirToGeometrySearchPaths('C:\OpenSim 4.4\Geometry')
and also

Code: Select all

    osim.ModelVisualizer.addDirToGeometrySearchPaths('C:\OpenSim 4.4\Geometry')
    current_directory = os.getcwd()
    data_folder_path = os.path.join(current_directory, "Model")
    osim.ModelVisualizer.addDirToGeometrySearchPaths(data_folder_path)
[edit] To be clear, the bone parts are in C:\OpenSim 4.4\Geometry, and the parts I created are in the 'current-path/Model'.

Everything is still all-white...