Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by NormandC »

AFAIK the Ubuntu PPA package is compiled with spacenav support. I'll test when I get the chance and report back.
albert.emil
Posts: 8
Joined: Sat Jul 14, 2018 9:59 pm

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by albert.emil »

PrzemoF wrote: Mon Jul 16, 2018 5:43 pm I don't use AppImage. There is possible wayland-x11 problem or the spacenavigator was not compiled in FreeCAD. Anyone has spacenavihator working properly? That would be a good starting point.
Do you mean getting the SpaceNavigator running in general or on Fedora in specific? I am not sure how quickly I could do this, but I might be able try this on a Debian-based Raspberry Pi 3 (the only other Linux-based machine I have access to, despite of my Fedora production system). Which however, could lead to totally different problems because of the ARM-architecture and could lead to the general issues described here.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by PrzemoF »

On linux, any flavour. I want to narrow the problem down. I won't be able to do any tests myself for a next 2 weeks.
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by tanderson69 »

PrzemoF wrote: Tue Jul 17, 2018 8:27 am On linux, any flavour. I want to narrow the problem down. I won't be able to do any tests myself for a next 2 weeks.
I have been using my serial magellan for years in freecad on debian and kubuntu. The best thing you can do is get the 'simple_x11' test program working that I mentioned in my previous post. If that test program works, the problem is with freecad. If that test program doesn't work, the problem is with spacenav.
albert.emil
Posts: 8
Joined: Sat Jul 14, 2018 9:59 pm

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by albert.emil »

tanderson69 wrote: Tue Jul 17, 2018 10:59 am The best thing you can do is get the 'simple_x11' test program working that I mentioned in my previous post. If that test program works, the problem is with freecad. If that test program doesn't work, the problem is with spacenav.
Tried to use simple_x11 after compiling from source which does not work either. See terminal snippets below for further information:

Code: Select all

# download source code, extract, configure and compile test program
$ wget -O liblibspnav.tar https://sourceforge.net/projects/spacenav/files/spacenav%20library%20%28SDK%29/libspnav%200.2.3/libspnav-0.2.3.tar.gz/download
$ tar xf libspnav.tar
$ cd libspnav-0.2.3
$ ./configure
$ cd examples/simple/ ; make


# start spacenavd and double-check status
$ sudo systemctl start spacenavd.service
$ sudo systemctl status spacenavd.service
● spacenavd.service - 3Dconnexion Input Devices Userspace Driver
   Loaded: loaded (/usr/lib/systemd/system/spacenavd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-07-17 21:07:52 CEST; 5min ago
  Process: 17596 ExecStart=/usr/bin/spacenavd (code=exited, status=0/SUCCESS)
 Main PID: 17597 (spacenavd)
    Tasks: 1 (limit: 4700)
   Memory: 576.0K
   CGroup: /system.slice/spacenavd.service
           └─17597 /usr/bin/spacenavd

Jul 17 21:07:52 localhost.localdomain systemd[1]: Starting 3Dconnexion Input Devices Userspace Driver...
Jul 17 21:07:52 localhost.localdomain systemd[1]: Started 3Dconnexion Input Devices Userspace Driver.


# execute test program `simple_x11`
$ ./simple_x11
failed to connect to the space navigator daemon


# however, accessing the unix socket works
$ ./simple_af_unix 
got motion event: t(0, -60, -61) r(0, 0, 0)
got motion event: t(0, -60, -61) r(-18, 0, 0)
got motion event: t(97, -66, 10) r(-18, 0, 0)
got motion event: t(97, -66, 10) r(-183, -23, 180)
got motion event: t(54, -57, -23) r(-183, -23, 180)


# connecting to daemon via x11 bindings with disabled access control not working as well
$ sudo xhost +
access control disabled, clients can connect from any host
$ sudo systemctl restart spacenavd.service
$ ./simple_x11
failed to connect to the space navigator daemon
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by tanderson69 »

albert.emil wrote: Tue Jul 17, 2018 7:27 pm Tried to use simple_x11 after compiling from source which does not work either.
Now we know that freecad is not the problem....or at least not the only problem.

I would try to run spacenav outside the service/daemon framework. like so:
shutdown the spacenavd service.
as root run, 'spacenavd -d'
run the simple x11 example again and see if it connects.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by wmayer »

Just some remarks:
  • When compiling FreeCAD on a Linux system it tries to find the package Spnav when running cmake configure
  • If the Spnav package was found the preprocessor define "-DSPNAV_FOUND" for the FreeCADGui target is set
  • GuiApplicationNativeEventAware.cpp is the only file where we use the C-API of the spnav package. On startup we e.g. use the function spnav_x11_open to try to connect to the device.
Now in the entry post you mentioned that you could see the message "Couldn't connect to spacenav daemon" which implies that your FreeCAD version is built with Spnav support.

The function call is:

Code: Select all

spnav_x11_open(QX11Info::display(), window->winId())
and the question is whether spnav_x11_open is the culprit or that QX11Info::display() returns something wrong/invalid.
albert.emil
Posts: 8
Joined: Sat Jul 14, 2018 9:59 pm

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by albert.emil »

According to
tanderson69 wrote: Tue Jul 17, 2018 8:22 pm as root run, 'spacenavd -d'
running spacenavd -d as root user:

Code: Select all

$ sudo spacenavd -d
Spacenav daemon 0.6
failed to open config file /etc/spnavrc: No such file or directory. using defaults.
adding device.
failed to open device: No such file or directory
removing device: 
adding device.
device name: 3Dconnexion SpaceNavigator
using device: /dev/input/event2

In a second terminal, I then ran simple_x11 again, which is working:

Code: Select all

$ ./simple_x11 
got motion event: t(21, -10, 4) r(-9, 4, 0)
got motion event: t(21, -10, 4) r(10, 4, 9)
got motion event: t(21, -19, -6) r(10, 4, 9)
got motion event: t(21, -19, -6) r(10, 4, 26)
got motion event: t(21, -25, -2) r(10, 4, 26)
got motion event: t(21, -25, -2) r(3, 4, 47)
got motion event: t(21, -34, -14) r(3, 4, 47)
got motion event: t(21, -34, -14) r(37, 4, 30)
got motion event: t(21, -50, -40) r(37, 4, 30)
I open FreeCAD 0.18_pre, where my SpaceNavigator still does not work (might be a issue due to unstable development version). So I downloaded the AppImage version of FreeCAD 0.17 another time, which according to
wmayer wrote: Wed Jul 18, 2018 4:18 pm Now in the entry post you mentioned that you could see the message "Couldn't connect to spacenav daemon" which implies that your FreeCAD version is built with Spnav support.
should have spnav support enabled. After all, my SpaceNavigator is shown in the Customize dialog with both motion and button settings available. I can use the SpaceNavigator for 3D navigation (zoom, pan, tilt ...) inside different workbenches as desired. Calling

Code: Select all

$ sudo xhost +
before starting both _spacenavd_ and _FreeCAD_ does not seem to be neccessary. As a last step I tried to use

Code: Select all

$ sudo systemctl start spacenavd.service
instead of the suggested

Code: Select all

$ sudo spacenavd -d
which does not work. Running spacenavd as a service seems to be a known issue, as you can see from the comments of the 0.6-1 package in the AUR (Arch Linux User Repository). Unfortunately, none of the suggested solutions worked for me.
All in all, regarding FreeCAD 0.17 AppImage running on Fedora 28 with spacenavd-0.6-7.fc28.src.rpm (installed via dnf) I would summarize our findings as:
  • AppImage is compiled with spacenavd support
  • Installing spacenavd by sudo yum install spacenavd works in general for using 3Dconnexion devices, but does not start the required service automatically (neither after installation nor after reboot)
  • Running spacenavd as a serice instead of an application leads to faulty behaviour with different solution discussed in the AUR (none of them worked for me)
  • Not working SpaceNavigator definitely is/was a issue related to spacenavd, not to FreeCAD (at least in version 0.17)
  • spacenavd issue is related to its service not to the application/driver itself (see links above)
  • spacenavd.service seems to be unable to connect to the X-Server because of permission issues
One of the solutions discussed at the links I provided as reference is to copy the user's Xauthority file to root user's home directory by

Code: Select all

sudo cp /run/user/1000/gdm/Xauthority /root/.Xuthority
in order to circumvent any permission issues when connecting to the X-Server. I tried this and rebooted the machine thereafter, but it did not solve the problem. Having a look at

Code: Select all

$ sudo spacenavd -d -v
Spacenav daemon 0.6
failed to open config file /etc/spnavrc: No such file or directory. using defaults.
Device detection, parsing /proc/bus/input/devices
found usb device [46d:c626]: "3Dconnexion SpaceNavigator" (/dev/input/leds) 
adding device.
failed to open device: No such file or directory
removing device: 
adding device.
device name: 3Dconnexion SpaceNavigator
  Number of axes: 6
using device: /dev/input/event2
trying to open X11 display ":1"
   XAUTHORITY=/run/user/1000/gdm/Xauthority
indicates that the Xauthority file used to access X11 is indeed the one I copied to root user's home directory. Despite being more a general Linux or even systemd related question, is there any way to solve this permission issue and being able to use systemd to start spacenavd as desired? I had a look at its service file located at /usr/lib/systemd/system/spacenavd.service, but did not find to get it running properly since the ExecStart command is pretty much the same as for sudo spacenavd:

Code: Select all

[Unit]
Description=3Dconnexion Input Devices Userspace Driver
After=syslog.target

[Service]
Type=forking
PIDFile=/var/run/spnavd.pid
ExecStart=/usr/bin/spacenavd
StandardError=syslog

[Install]
WantedBy=graphical.target
Using systemd to manage spacenavd with proper XAUTHORITY might work by creating a user-based service (see Arch Wiki or this SO question for further information), but I did not figure out how to do this properly...
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by tanderson69 »

albert.emil wrote: Wed Jul 18, 2018 7:35 pm related question, is there any way to solve this permission issue and being able to use systemd to start spacenavd as desired?
I am thinking maybe permissions are not your only problem with starting spacenavd with x11 as a service. According to: https://unix.stackexchange.com/question ... 685#360685 The xserver isn't running at the time of the spacenavd service launch, therefore can't connect to the xserver.





back in your original post:
albert.emil wrote: Sat Jul 14, 2018 10:24 pm

Code: Select all

$ spnavd_ctl x11 start
You must have an X server running before starting up spacenavd-X11 events.
did you try to start x11 manually as root?
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Unable to connect to SpaceNavigator with FreeCAD 0.17 on Fedora 28

Post by PrzemoF »

Related thread: https://forum.freecadweb.org/viewtopic.php?t=24650
I got the 3dconnexion device working with python:

Code: Select all

$ cat 3dconn_test.py 
import spnav

spnav.spnav_open()
while 1:
    event = spnav.spnav_poll_event()
    if event:
        print(event)
fedora:/home/przemo/software/3Dconnexion
$ python 3dconn_test.py 
SPNAV_EVENT_MOTION trans(-139,-58,27) rot(17,11,16)
SPNAV_EVENT_MOTION trans(-139,-58,27) rot(14,11,16)
SPNAV_EVENT_MOTION trans(-55,-58,51) rot(14,11,16)
SPNAV_EVENT_MOTION trans(-55,-58,51) rot(-47,11,-37)
SPNAV_EVENT_MOTION trans(-100,-23,30) rot(-47,11,-37)
SPNAV_EVENT_MOTION trans(-100,-23,30) rot(-47,20,-37)
SPNAV_EVENT_MOTION trans(-78,-23,6) rot(-47,20,-37)
SPNAV_EVENT_MOTION trans(-78,-23,6) rot(-3,20,-37)
SPNAV_EVENT_MOTION trans(-9,5,6) rot(-3,20,-37)
SPNAV_EVENT_MOTION trans(-9,5,6) rot(2,-3,-10)
but when I try to use spnav_x11_open (python) with pygame it dies with connection problem:

Code: Select all

$ cat 3dconn_test_pygame.py 
import spnav
import pygame

pygame.init()
pygame.event.set_grab(True)
screen = pygame.display.set_mode((400, 400))
spnav.spnav_open()
wm_info = pygame.display.get_wm_info()
print(wm_info["display"])
print(wm_info["window"])
spnav.spnav_x11_open(wm_info["display"], wm_info["window"])
fedora:/home/przemo/software/3Dconnexion
$ python 3dconn_test_pygame.py 
<capsule object "display" at 0x7f5dc2ed85a0>
39845903
Traceback (most recent call last):
  File "3dconn_test_pygame.py", line 11, in <module>
    spnav.spnav_x11_open(wm_info["display"], wm_info["window"])
  File "/usr/lib/python2.7/site-packages/spnav/__init__.py", line 216, in spnav_x11_open
    'failed to connect to the space navigator daemon')
spnav.SpnavConnectionException: failed to connect to the space navigator daemon
spnav_x11_open (python) is the same as C++

Code: Select all

spnav_x11_open(QX11Info::display(), window->winId()) 
mentioned by wmayer. It calls

Code: Select all

libspnav.spnav_x11_open(display_ptr, window)
where

Code: Select all

libspnav = cdll.LoadLibrary('libspnav.so')
Post Reply