MAVProxy icon indicating copy to clipboard operation
MAVProxy copied to clipboard

Joystick module will not load on macOS

Open srmainwaring opened this issue 2 years ago • 1 comments

The joystick module does not load correctly on macOS, raising an error if there is a matching joystick found.

System

  • Mac Pro 2019 x86_64 (also MacBook Pro aarch64)
  • macOS Ventura 13.5
  • Python 3.11.5

Details

Install additional dependencies

python -m pip install pygame

Add joystick definition to ~/.mavproxy/joysticks/frsky_x10.yaml

description: FrSky X10 Joystick definition
match:
  - FrSky X10 Joystick

controls:
  
  # map axis id 2 to rc channel 1 (AILERON)
  - channel: 1
    type: axis
    id: 2

  # map axis id 3 to rc channel 2 (ELEVATOR)
  - channel: 2
    type: axis
    id: 3

  # map axis id 1 to rc channel 3 (THROTTLE)
  - channel: 3
    type: axis
    id: 1
    invert: true

  # map axis id 0 to rc channel 4 (YAW)
  - channel: 4
    type: axis
    id: 0

  # map switch SA id 6 to rc channel 5
  - channel: 5
    type: axis
    id: 6

  # map switch SA and SB id 7 to rc channel 5 (RC5_OPTION=0 Default Flight Mode)
  - channel: 5
    type: axis
    id: 7

  # map switch id 6 to rc channel 7 (RC7_OPTION=153 Arm/Disarm)
  - channel: 7
    type: axis
    id: 6

  # map toggle switch id 0 to rc channel 9 (RC9_OPTION=31 Motor Emergency Stop)
  - channel: 9
    type: button
    id: 0

Run SITL and load joystick module:

$ sim_vehicle.py -D -v ArduCopter -f quad --console --map

STABILIZE> module load joystick
STABILIZE> pygame 2.5.2 (SDL 2.28.3, Python 3.11.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
MAVProxy.modules.mavproxy_joystick: Found joystick (FrSky X10 Joystick)
MAVProxy.modules.mavproxy_joystick: Using /Users/rhys/.mavproxy/joysticks/frsky_x10.yaml ("FrSky X10 Joystick" matches pattern "FrSky X10 Joystick")
Loaded module joystick
2023-12-01 12:44:04.754 Python[12468:57426665] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007ff81275318a __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff81227942b objc_exception_throw + 48
	2   AppKit                              0x00007ff815775b50 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3848
	3   libSDL2-2.0.0.dylib                 0x00000002324bc3f7 Cocoa_PumpEventsUntilDate + 103
	4   libSDL2-2.0.0.dylib                 0x00000002324bc6db Cocoa_PumpEvents + 59
	5   libSDL2-2.0.0.dylib                 0x00000002323e7c51 SDL_PumpEvents_REAL + 33
	6   event.cpython-311-darwin.so         0x00000002302cff70 pg_event_get + 160
	7   Python                              0x000000010ffea067 cfunction_call + 50
	8   Python                              0x000000010ffa6e28 _PyObject_MakeTpCall + 126
	9   Python                              0x000000011007aa7d _PyEval_EvalFrameDefault + 45620
	10  Python                              0x000000011007f553 _PyEval_Vector + 92
	11  Python                              0x000000011007cd2b _PyEval_EvalFrameDefault + 54498
	12  Python                              0x000000011007f553 _PyEval_Vector + 92
	13  Python                              0x000000010ffaa33e method_vectorcall + 439
	14  Python                              0x000000011012c5b6 thread_run + 148
	15  Python                              0x00000001100d18b6 pythread_wrapper + 36
	16  libsystem_pthread.dylib             0x00007ff8126001d3 _pthread_start + 125
	17  libsystem_pthread.dylib             0x00007ff8125fbbd3 thread_start + 15
)
libc++abi: terminating due to uncaught exception of type NSException
SIM_VEHICLE: MAVProxy exited
SIM_VEHICLE: Killing tasks

Looks like it may be similar to previous issues observed on macOS concerning GUI / threading.

srmainwaring avatar Dec 01 '23 12:12 srmainwaring

Investigation

Exception occurs at L144 when attempting to access the pygame event:

https://github.com/ArduPilot/MAVProxy/blob/f37c415714be21b4bf2f6a19bf9914aed19b5004/MAVProxy/modules/mavproxy_joystick/init.py#L140-L153

srmainwaring avatar Dec 01 '23 14:12 srmainwaring