ScheiklP / sofa_env

Reinforcement learning environments for robot-assisted laparoscopic surgery
MIT License
53 stars 15 forks source link

Run mr_env error #25

Closed Yangon0620 closed 7 months ago

Yangon0620 commented 7 months ago

Hi, It`s me again. When I run the mcr_env.py with "python sofa_env/scenes/magnetic_continuum_robot/mcr_env.py" it came out the following error:

(sofa23_12) yangyang@yangyang-pc:~/conda_env/sofa_env/sofa_env$ python sofa_env/scenes/magnetic_continuum_robot/mcr_env.py 
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: /home/yangyang/conda_env/SOFA_v23.12.01_Linux
---------------------------------------
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.GL.Component.Shader.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Visual.so
[WARNING] [InteractiveCamera(camera)] Too many missing parameters ; taking default ...
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/STLIB/lib/libSTLIB.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/SoftRobots/lib/libSoftRobots.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/BeamAdapter/lib/libBeamAdapter.so
[INFO]    [SofaPython3] Initializing with python version 3.10.14 (main, Mar 21 2024, 16:24:04) [GCC 11.2.0]
[INFO]    [SofaPython3] Added '/home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/SofaPython3/lib/python3/site-packages' to sys.path
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/SofaPython3/lib/libSofaPython3.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.AnimationLoop.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Constraint.Lagrangian.Solver.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Collision.Response.Contact.so
[ERROR]   [SofaRuntime] ValueError: Object type CollisionPipeline<> was not created  
The object 'CollisionPipeline' is not in the factory.  
But the following exits:  
                      : CollisionResponse (64% match)  
                      : RayCollisionModel (64% match)  
                      : CubeCollisionModel (62% match)  
                      : LineCollisionModel (62% match)  
                      : PointCollisionModel (61% match)  

Traceback (most recent call last):
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py", line 268, in <module>
    env.reset()
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py", line 146, in reset
    super().reset(seed)
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/base.py", line 206, in reset
    self._init_sim()
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py", line 259, in _init_sim
    super()._init_sim()
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/base.py", line 280, in _init_sim
    self.scene_creation_result = getattr(self._scene_description_module, "createScene")(self._sofa_root_node, **self.create_scene_kwargs)
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/scene_description_3d.py", line 141, in createScene
    mcr_simulator.Simulator(root_node=root_node)
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_sim/mcr_simulator.py", line 52, in __init__
    self.root_node.addObject("CollisionPipeline", draw="0", depth="6", verbose="1")

It seems that the CollisionPipeline object was not created. I think maybe there are something wrong with the CollisionPipeline in the sofa framework, but i don`t know how to fix it. Looking forward to your reply . Thanks

Yangon0620 commented 7 months ago

And I want to ask some other questions. When I read the scene_description.py, I find that there are a lot root_node.addObject() function which made me confused. Why we add this object? Why pass these parameters?If I want to describe a new scene, how could I know which object should be added, and what the parameters should I pass to the root_node.addObject() function. I am a beginner in SOFA framework,and these questions confused me a lot. Looking forward to your advice. Thanks a lot. Here is a part of scene_description.py which contains a lot root_node.addObject() function:

self.root_node.addObject("RequiredPlugin", name="Sofa.Component.AnimationLoop") self.root_node.addObject("FreeMotionAnimationLoop") self.root_node.addObject("RequiredPlugin", name="Sofa.Component.Constraint.Lagrangian.Solver") self.lcp_solver = self.root_node.addObject("LCPConstraintSolver", mu=str(friction_coef), tolerance="1e-6", maxIt="10000", build_lcp="false") self.root_node.addObject("RequiredPlugin", name="Sofa.Component.Collision.Response.Contact")

add "Sofa.Component.Collision.Detection.Algorithm", then CollisionPipeline works

self.root_node.addObject("RequiredPlugin", name="Sofa.Component.Collision.Detection.Algorithm") self.root_node.addObject("CollisionPipeline", draw="0", depth="6", verbose="1")

ScheiklP commented 7 months ago

Hi @Yangon0620 , thanks for the feedback, I updated the files. Please pull the most recent commit and try again.

Each call to the addObject function adds a simulation object to the simulation tree under the node from which the function is called, in this case the root node.

So for example self.root_node.addObject("CollisionPipeline", draw="0", depth="6", verbose="1") adds a CollisionPipeline object to the simulation tree under the root node. The Collision Pipeline is responsible for managing the collision detection method (in this scene example the LocalMinDistance), and figure out what to do (in this case adding friction for the CollisionResponse). How to build sofa simulations and all the required objects is quite a bit of work to get into. You can read more about that in the official documentation. But you can also look through other scenes, that heavily use my sofa_templates to abstract a lot of that. For example https://github.com/ScheiklP/sofa_env/blob/main/sofa_env/scenes/deflect_spheres/scene_description.py

Cheers, Paul

Yangon0620 commented 7 months ago

Thanks so much for your kindly help

Yangon0620 commented 7 months ago

Hi, I found another error after I pulled the latest commit, here is the log:

(sofa23_12) yangyang@yangyang-pc:~/conda_env/SOFA_v23.12.01_Linux/bin$ python3 /home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py
---------------------------------------
Checking SOFA_ROOT and SOFAPYTHON3_ROOT
Using environment variable SOFA_ROOT: /home/yangyang/conda_env/SOFA_v23.12.01_Linux
---------------------------------------
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.GL.Component.Shader.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Visual.so
[WARNING] [InteractiveCamera(camera)] Too many missing parameters ; taking default ...
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/STLIB/lib/libSTLIB.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/SoftRobots/lib/libSoftRobots.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/BeamAdapter/lib/libBeamAdapter.so
[INFO]    [SofaPython3] Initializing with python version 3.10.14 (main, Mar 21 2024, 16:24:04) [GCC 11.2.0]
[INFO]    [SofaPython3] Added '/home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/SofaPython3/lib/python3/site-packages' to sys.path
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/plugins/SofaPython3/lib/libSofaPython3.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.AnimationLoop.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Constraint.Lagrangian.Solver.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Collision.Response.Contact.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Collision.Detection.Algorithm.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Collision.Detection.Intersection.so
[DEPRECATED] [SofaMiscCollision] SofaMiscCollision is deprecated. It will be removed at v23.06. Use Sofa.Component.Collision.Geometry, Sofa.Component.Collision.Detection.Intersection and Sofa.Component.Collision.Response.Contact instead.
[DEPRECATED] [SofaMiscCollision] If you are looking for OBB and Capsule-related components, please use the external plugin CollisionOBBCapsule.
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Collision.Geometry.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/collections/SofaMiscCollision/lib/libSofaMiscCollision.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Setting.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.IO.Mesh.so
[WARNING] [MeshSTLLoader(meshLoader)] Could not read value for data field translation: 0.0 -0.45 
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.Topology.Container.Constant.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.Component.StateContainer.so
[INFO]    [PluginManager] Loaded plugin: /home/yangyang/conda_env/SOFA_v23.12.01_Linux/lib/libSofa.GL.Component.Rendering3D.so
[ERROR]   [SofaRuntime] TypeError: Unknown Attribute(s):   
  - Unable to set attribute 'length' with value: 0.534. Possible misspelling of attribute 'listening' ?  
  - Unable to set attribute 'numEdges' with value: 600. Possible misspelling of attribute 'name' ?  
  - Unable to set attribute 'numEdgesCollis' with value: 30 3 .  
  - Unable to set attribute 'radius' with value: 0.00032103957355245104.  
  - Unable to set attribute 'radiusExtremity' with value: 0.00032103957355245104.  
  - Unable to set attribute 'spireDiameter' with value: 250.0. Possible misspelling of attribute 'wireMaterials' ?  
  - Unable to set attribute 'spireHeight' with value: 0.0.  
  - Unable to set attribute 'straightLength' with value: 0.5.  
  - Unable to set attribute 'youngModulus' with value: 170000000.0.  
  - Unable to set attribute 'youngModulusExtremity' with value: 21000000.0.  

Traceback (most recent call last):
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py", line 268, in <module>
    env.reset()
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py", line 146, in reset
    super().reset(seed)
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/base.py", line 206, in reset
    self._init_sim()
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_env.py", line 259, in _init_sim
    super()._init_sim()
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/base.py", line 281, in _init_sim
    self.scene_creation_result = getattr(self._scene_description_module, "createScene")(self._sofa_root_node, **self.create_scene_kwargs)
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/scene_description_3d.py", line 158, in createScene
    instrument = mcr_instrument.Instrument(
  File "/home/yangyang/conda_env/sofa_env/sofa_env/sofa_env/scenes/magnetic_continuum_robot/mcr_sim/mcr_instrument.py", line 90, in __init__
    topoLines_guide.addObject(

Yangon0620 commented 7 months ago

This error is about the mcr_instrument.py, trying to add the WireRestShape component to topoLines_guide subnode. I read the document about WireRestShape and learned that this ccomponent is trying to defining the initial shape and mechanical properties of wire-like structures in SOFA simulations. But I have some questions, what`s the relationship between other component under the same subnode,such as the Sofa.Component.Topology.Container.Dynamic, EdgeSetTopologyContainer and the EdgeSetGeometryAlgorithms. Why we combine these component together? And the subnode InstrumentCombined build the mechanic too, why the mechanic built twice? Here are my confuses. Looking forward to your reply, thanks

ScheiklP commented 7 months ago

Hi @Yangon0620 , sadly I am not very familiar with the scene. We ported the scene from the original repo (https://github.com/ethz-msrl/mCR_simulator) to show, that sofa_env allows easy integration of existing scenes. The original repo seems to be actively maintained. Maybe you could check what changed, since we ported it, and open a PR to sofa_env.

The EdgeSetTopologyContainer is part of the Sofa.Component.Topology.Container.Dynamic module and holds the info about the topology of a MechanicalObject. The MechanicalObject is just a collection of points, so the Topology explains how these points are connected. In this case, as a set of edges -> point--edge--point--edge--... The EdgeSetGeometryAlgorithms exposes additional functions on this topology, that other components might need. If you want to know more about these connections, I recommend reading https://inria.hal.science/hal-00681539/document (but be aware, that some of the names have changed, for example MechanicalState -> MechanicalObject).

Yangon0620 commented 7 months ago

I`m really thankful for your recommendation, it makes me more clear about the sofa framework. By the way, I found that it it the version of BeamAdapter plugin that I compiled does not match this mcr_env. After I change this plugin to a lower version, the error solved, and this scene works fine. Thanks a lot!

ScheiklP commented 7 months ago

Perfect, glad I could help!

If you want to update the scene to a newer version of the BeamAdapter plugin, I would really welcome a PR. :)