smartavionics / RawMouse

Cura Plugin that lets you use a HID mouse to pan/rotate/zoom the view
94 stars 7 forks source link

Support for older serial based 3D mice? #2

Closed BenBergman closed 4 years ago

BenBergman commented 4 years ago

I've got a SpaceBall 5000 which is one of the older serial based devices. I've got it working with OpenSCAD, FreeCAD, and Blender using spacenav-plus (a fork of spacenavd), which implements libspnav bindings.

From the sounds of the readme, this Cura plugin only supports directly reading USB devices. Is that correct?

Would it be possible to add support for serial devices via libspnav?

smartavionics commented 4 years ago

Hi @BenBergman. I have added support for libspnav and if possible could you please try it out. To do that, in your cura plugins directory clone my RawMouse repo and then check out the libspnav branch.

The plugins directory on Linux is at ~/.local/share/cura/RELEASE/plugins

git clone https://github.com/smartavionics/RawMouse.git
cd RawMouse/RawMouse
git checkout libspnav

The config file now has a value for the location of the libspnav library, it assumes that you are using linux so it has a .so suffix, if you are using MacOS you need to change the suffix to .dylib

The config file also has a profile called libspnav which I have set up to be similar to the spacemouse profile, please edit the values to suit what you expect and if you want, I can take your edits and put them into the default config.

BenBergman commented 4 years ago

Wow, thanks for such a fast response.

I think I'm doing this right, but I'm not getting any response. Perhaps I didn't install the plugin correctly because I don't see the Extensions -> RawMouse menu entry.

For context, my config file is at ~.local/share/cura/4.5/plugins/RawMouse/RawMouse/config.json (I think that double RawMouse is as indended, but let me know if that looks wrong). I have also checked out the libspnav branch and edited the config to point to my libspnav.so. I confirmed that Blender is currently taking input from my SpaceBall, so the driver itself is working.

BenBergman commented 4 years ago

Ah, just found cura.log and it sounds like the plugin is crashing for me:

2020-04-04 22:55:50,429 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]: Exception: Import error loading module RawMouse                                                                                                           
2020-04-04 22:55:50,429 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]: Traceback (most recent call last):                                                                                                                        
2020-04-04 22:55:50,429 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/usr/lib/python3.8/site-packages/UM/PluginRegistry.py", line 606, in _findPlugin                                                                  
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:     module = imp.load_module(plugin_id, file, path, desc) #type: ignore #MyPy gets the wrong output type from imp.find_module for some reason.            
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/usr/lib/python3.8/imp.py", line 244, in load_module                                                                                              
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:     return load_package(name, filename)                                                                                                                   
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/usr/lib/python3.8/imp.py", line 216, in load_package                                                                                             
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:     return _load(spec)                                                                                                                                    
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "<frozen importlib._bootstrap>", line 702, in _load
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2020-04-04 22:55:50,430 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/home/ben/.local/share/cura/4.5/plugins/RawMouse/RawMouse/__init__.py", line 4, in <module>
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:     from . import RawMouse
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/home/ben/.local/share/cura/4.5/plugins/RawMouse/RawMouse/RawMouse.py", line 38, in <module>
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:     import hid
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "<frozen zipimport>", line 259, in load_module
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/home/ben/.local/share/cura/4.5/plugins/RawMouse/RawMouse/hidapi/hidapi-0.9.0-py3.5-linux-x86_64.egg/hid.py", line 7, in <module>
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/home/ben/.local/share/cura/4.5/plugins/RawMouse/RawMouse/hidapi/hidapi-0.9.0-py3.5-linux-x86_64.egg/hid.py", line 6, in __bootstrap__
2020-04-04 22:55:50,431 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:   File "/usr/lib/python3.8/imp.py", line 342, in load_dynamic
2020-04-04 22:55:50,432 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]:     return _load(spec)
2020-04-04 22:55:50,432 - ERROR - [MainThread] UM.PluginRegistry._findPlugin [608]: ImportError: libpython3.5.so.1.0: cannot open shared object file: No such file or directory

Python isn't my best language, but I'll poke around a bit and see if I can figure this out.

BenBergman commented 4 years ago

Looks like I just needed to do a sudo pip install hidapi. With some axis tweaking, my SpaceBall is working great!

Here is the config I'm using right now:

    "libspnav" : {
      "axes" : [
        { "offset": 0.0, "scale": 0.1, "threshold": 0.01, "target": "movx" },
        { "offset": 0.0, "scale": -0.1, "threshold": 0.01, "target": "movy" },
        { "offset": 0.0, "scale": -100.0, "threshold": 1.0, "target": "zoom" },
        { "offset": 0.0, "scale": 0.05 , "threshold": 0.01, "target": "rotpitch" },
        { "offset": 0.0, "scale": 0.1, "threshold": 0.01, "target": "rotyaw" },
        { "offset": 0.0, "scale": -0.05, "threshold": 0.01, "target": "rotroll" }
      ],
      "buttons" : {
        "0": { "value": [ "3d" ], "target": "resetview" },
        "1": { "value": 1,        "target": "toggleview" }
      }
smartavionics commented 4 years ago

Yes, the problem there was because you are using a different Python version (3.8) than the version used in the UM releases (3.5).

Anyway, glad you have it working OK now.

Looks like you have inverted most of the axes in your config. Is that because your libspnav config has already inverted them or because you really use your mouse in the opposite sense?

smartavionics commented 4 years ago

I should add that I have never used a spacemouse before with another app so what I find "normal" in terms of directions and sensitivity could be completely different to everyone else who is used to these things.

BenBergman commented 4 years ago

Yeah, I'm not sure about that one. I think my spnav config is basically default, but I'm also using a fairly old serial device that requires a patch on a fork of an old version of spacenavd, so it is possible that weird old driver has some stuff backwards. My SpaceBall 5000 is also designed so you can remove the wrist rest, rotate the main portion 180 degrees, and reattach it to convert between left and right handed modes, so maybe that is why I need to invert almost everything.

As for personal preference, the way I set it up in Cura is the way it defaulted in Blender without any special configuration. Pushing the ball pushes the model away. Twisting the ball clockwise spins the model clockingwise. Maybe you are using the ball to manipulate the camera instead of the model?

smartavionics commented 4 years ago

Hi, I have made some changes and incorporated your config. Could you please do a git pull and verify that it still works OK for you. Thanks.

BenBergman commented 4 years ago

Yeah, still looks good to me.

smartavionics commented 4 years ago

Thanks, I'll merge the libspnav branch to master and make a release. Please open another issue if you have any problems.