sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
893 stars 304 forks source link

Python2.7 & prebuilt SOFA19 & HID devices #2786

Open TumVink opened 2 years ago

TumVink commented 2 years ago

Heyy

I have a Spacemouse Haptic as a controller and also a python driver to read the input from it, which is based on raw HID input via package pywinusb. And I could read the input of Spacemouse when i execute "python input.py", the movement daten will be printed on screen. a1d433125bcc9c7788244275ff3ad57

However when i add a create_scene class on the python file and try to load the file from sofa, the terminal shows that the HID device could not be found and hence the input could not be read. 2efbbe34de273a3c4f949a2f4f3086b

Anyone have any idea about this issue? Thanks in advances.

fredroy commented 2 years ago

Hello @TumVink If I understood well, you are trying to use a code to use a haptic device written in python2.7 to be read in a python2.7 script controller in SOFA? Python2.7 support has been dropped and I personally never tried the Spacemouse Haptic so it would be a bit difficult to debug. But one hint would be about user permissions? Maybe the user account executing runSOFA needs to have admin privileges to call the Spacemouse Haptic SDK? This issue can happen with Geomagic sometimes so I am wondering. I can see you are trying on Windows so you try to execute with elevated privileges (right-click on exe, run as admin or something like that)

TumVink commented 2 years ago

Heyy @fredroy Yes, you got it correctly. I am trying to read a haptic device written in py2.7 into sofapython controller in SOFA. And thanks for your advice, I just tried run as admin when execute the runSofa.exe, and it just does not work. So usually the SofaPython could be compatible with other python packages installed from pip, right? I think I will try to debug into my python drivers and for now I am going to run these two python processes at the same time(1. a normal python console and 2. a sofapython one), and probably let the 1. console write into a .np array and let the 2. process read continuously read the array to pass the msg from haptic device. Will it work in sense of real-time property in your opinios? @fredroy Or do you have a better idea about such temporal solution. Thanks any way !!!

fredroy commented 2 years ago

Heyy @fredroy Yes, you got it correctly. I am trying to read a haptic device written in py2.7 into sofapython controller in SOFA. And thanks for your advice, I just tried run as admin when execute the runSofa.exe, and it just does not work. So usually the SofaPython could be compatible with other python packages installed from pip, right?

Hum it should be (it has been a long time I did not use the python2 plugin that I am not 100% sure)

I think I will try to debug into my python drivers and for now I am going to run these two python processes at the same time(1. a normal python console and 2. a sofapython one), and probably let the 1. console write into a .np array and let the 2. process read continuously read the array to pass the msg from haptic device. Will it work in sense of real-time property in your opinios? @fredroy Or do you have a better idea about such temporal solution. Thanks any way !!!

Hum I dont think it will work unfortunately, at least for the real-time aspect. Writting in a console is very time-consuming so the whole process serialize -> write in a console -> read the console -> deserialize will be too slow in my opinion. The other least bad way IMO ( because directly getting the value from the device would be much better 🙃) would be to pipe or open a comm channel between the two processes either RPC or TCP/IP or unix pipes.

TumVink commented 2 years ago

Heyy @fredroy

Thanks for your reply and i adopt a similar solution: multiprocessing in the python library, which basically allows two python processes to communicate through the sockets. And it works well for now, not so perfect as getting the value from the device directly tho.

And for sure I will also give SOFA 20 with python3 a try. I will update this post at that time.

Thanks again for your help! You are so great! ;)