Home › Forum › SOFA › Programming with SOFA › [SOLVED] Input and Output in SOFA .scn file
- This topic has 20 replies, 3 voices, and was last updated 3 years, 1 month ago by Hugo.
-
AuthorPosts
-
10 March 2021 at 17:21 #18836eaparraBlocked
Hello every one.
I hope everybody is fine.
I’ve been workinf in SOFA and I could I’ve been able to do a few simulations in it.
SOFA is a great platform that helps a lot.
Now I want to be able to enter de values from outsite of SOFA and take, if it’s possible, to take the values of the simulation.
I don’t know if I can program a SOFA script and, for example, connect to another program by serial or TCP/IP.Thank you very much for you help and I’m attentive to your response.
Greetings.
12 March 2021 at 11:25 #18845GuillaumeKeymasterHi eaparra,
I would suggest you take a look at this pull-request, which is an unfinished work about adding communication protocols to SOFA within a plugin.
Even though this work is not merged in SOFA (yet), I think it could be a good starting point for what you want to do.Cheers,
Guillaume.18 March 2021 at 12:39 #18911eaparraBlockedHi @Guillaume
Thank you for you help.
I have some questions, the plugin you suggested to me, I don’t know where I can clone?
and I dont know where I can find the example.
I also read that I could use two protocols, OSC and ZMQ , so I don’t if you suggest to me to use one of this, but I don’t know how connect with our simulation because I want to use .scn format but this protocols are explained in java or python.Sorry for me inexperience, I’m a little confused with the information.
Again, thank you very much for you help and I’m attentive to your response.
Greetings.
18 March 2021 at 14:36 #18913HugoKeymasterHey @eaparra
What @guillaumeparan meant is that you can test the pull-request within which a Communication plugin was integrated within SOFA. However, this work in not integrated within the current/recent version of SOFA.
To download it and test it:
git clone -b sofaCommunication https://github.com/SofaDefrost/sofa
But – as explained – this corresponds to an old version of SOFA.
Best,Hugo
18 March 2021 at 15:49 #18915eaparraBlockedHi @Hugo
Thanks for you help.
ue
But if I work with the V20.xx version and use python to program the scene, Could I stablish the communication outside the SOFA using this language or I must use the plugin?.Thank you very much for you help and I’m attentive to your response.
Greetings.
18 March 2021 at 16:30 #18916HugoKeymasterHey @eaparra
Only using the v20.12(.01) which allows to use SOFA from a native python environment.
Once you have compiled SOFA and the SofaPython3 plugin, you will have to :
export SOFA_ROOT=/path/to/SOFA
export PYTHONPATH=$path/to/build/of/SofaPython3/lib/python3/site-packages
then you will be able to run any simulation (written as a python script) from a python environment as follows:
python3.7 $path/to/your/scene/simulation.py
I hope this helps.
FYI, I will make sure the doc on SofaPython3 (and its usage) will improve.Best,
Hugo
18 March 2021 at 16:31 #18917eaparraBlockedAnd one more thing, sorry bother you.
When you sent me the link git clone -b sofaCommunication https://github.com/SofaDefrost/sofa, this is the src or the plugin.
Because I’ve tried to find the sofaCommunication plugin but I haven’t found it.Thank you.
Greetings.
18 March 2021 at 16:41 #18918HugoKeymasterHey @eaparra
My link wasn’t good I guess.
Here is the repo: https://github.com/SofaDefrost/sofa/tree/sofaCommunication
The Communication plugin will be included in SOFA as a plugin (to activate in the CMake configuration phase)Best
Hugo
18 March 2021 at 18:08 #18920eaparraBlockedHi @Hugo
It is great that python that the v20.12(.01) allows to use native python environment.
But my question is if I can output or input values in SOFA. For example, take the position values from my simulation and send them to another program. And since I do not have the plugin for .scn, in the latest version of SOFA, I wanted to know if with python I can obtain these output/input values over SOFA.TThank you very much for your valuable help and I’m attentive to your response.
Greetings.
18 March 2021 at 19:33 #18921HugoKeymasterHey @eaparra
Sorry for my misunderstanding.
Yes, you can input/output data from a SOFA simulation within your native python environment, to possibly send them to another program.Best wishes,
Hugo
18 March 2021 at 20:19 #18923eaparraBlockedHi @Hugo
Don’t worry.
Now I understand that I can use python3 to program a simulation and communicate, output/input values, from SOFA.But the problem now is that I can’t configure the SofaPytho3 plugin. Follow the instruccions from https://sofapython3.readthedocs.io/en/latest/menu/install.html# the CMake doesn’t recognize the python3.7.
I update the python, pynbin11, cmake and numpy. But when I uncheck python and I ckeck python3 plugin the cmake popup a windows error.
At the end, I follow out-of-tree build but I don’t understand how I can execute the cmake example.Instructions I made:
### In-tree build
Add this directory path inCMAKE_EXTERNAL_DIRECTORIES
.NB: This plugin cannot be build through in-build process when the old SofaPython plugin is activated. To have both SofaPython3 and SofaPython you need to use out-of-tree build.
### Out-of-tree build — I don’t understand what I have to put in cmake and make -j12
This plugin should compile with out-of-tree builds.
You might need to add the Sofa’s installation path to the CMake prefix path. If you compiled Sofa in directory _$SOFA_ROOT/build_, consider doing an install step (make install, ninja install, etc.) and adding this installation path (examplecmake -DCMAKE_PREFIX_PATH=$SOFA_ROOT/build/install/lib/cmake ..
).### Changing the python path — This is after the Python3 plugin is accepted?
The compilation of SofaPython3 plugin and bindings are tied to the python core library found during the CMake stage.
To change the python version used for the compilation, you can either:
1. Provide the python executable path withPython_EXECUTABLE
cmake -DPython_EXECUTABLE=/usr/local/bin/python3 ..
2. Provide the python root path withPython_ROOT_DIR
cmake -DPython_ROOT_DIR=/usr/local ..
Thank you very much for your valuable help and I’m attentive to your response.
Greetings.
31 March 2021 at 23:33 #19041HugoKeymasterHey @eaparra
Note that the SOFA binaries are including SofaPython3, already built for you.
Would these binaries work for you?Best wishes,
Hugo
5 April 2021 at 12:44 #19075eaparraBlockedHi @Hugo,
Now, I’m working with the v20.12.02 version.
When I executed the CMake checking the SofaPython3, it showed me an error. After that, I updated the libraries, but the error continues.So, what would you recommend me to do?
Thank you very much for you help and I’m attentive to your response.
Greetings.
8 April 2021 at 23:27 #19090HugoKeymasterHi @eaparra
You said: When I executed the CMake checking the SofaPython3, it showed me an error.
What is this error at the CMake configuration step please?
If the configuration is returning an error, you should not build the project and first solve this CMake error.
Best,
Hugo
8 September 2021 at 14:46 #20334eaparraBlockedHi @guillaumeparan.
Some time ago I wrote to know a way to communicate and be able to send and receive data, and thus achieve control of the simulated systems in SOFA.
You sent to me a link with a specifications of a various way to communicate https://github.com/sofa-framework/Communication. I’ve read the information again, and I wanna know if you have been updating the Communication Plugin.
Reading, I noticed that the communication rate is 2hz (aka 500ms). So, II would like to know if the transmission rate has increased or if it continues at 2hz.Thank you very much for you help.
Best,
9 September 2021 at 18:06 #20336eaparraBlockedHi @hugo and @guillaumeparan.
Until which version of SOFA the Communication plugin can work well?
Thank you very much for you help.
Best,
20 September 2021 at 12:36 #20381eaparraBlockedHi @hugo and @guillaumeparan.
Finally, I could take and send the values of the SOFA simulation in .scn, using ZMQ protocol and the Communication plugin that @guillaumeparan said to me.
Using SOFA v21.06 over Ubunto 20.04.3 LTS and installing libzmq3-dev I just had to comment using sofa::helper::vector in the ServerCommunication.h file.
But I have a drawback, when I simulate the scene a vibration appears that I didn’t model. I’m simulating the beam with a mass at the end free, later I attach a Femur with a mass. But I don’t know why the Femur vibrates and modifies the simulation, given a noise that affects the results.
This is the link of the repository https://github.com/eaparra01/Femur_Movement.git.
Thank you very much for your help and I am attentive to your response.
23 September 2021 at 19:40 #20423eaparraBlockedHi @hugo.
I’ve been waiting your response, due that I can’t progress in the SOFA simulation.
Please response because I have to understand that.
Thanks
6 October 2021 at 15:52 #20525HugoKeymasterHi @eaparra
I am so sorry for the delay of our reply.
I just tested your scene (without the Communication plugin), I do not have any instabilities/abnormal vibrations. Have you updated your scene?Best wishes,
Hugo
3 November 2021 at 15:29 #20735eaparraBlockedHi @hugo and @guillaumeparan.
Finally, I could control the torque to control de angle. I used a PID controller and the simulation runs very good, working with zmq sofaCommunication.
I update the last changes, if you want to see it.https://github.com/eaparra01/Femur_Movement
Thank you so much for your help.
3 November 2021 at 15:59 #20736 -
AuthorPosts
- You must be logged in to reply to this topic.