We use the Navio2 sensor hat from Emlid. These boards are used for a class where students develop flight software (not using Ardupilot or PX4). We roll our own framework which provides some basic communications/timing to simplify the programming for the students. We are migrating to ROS and have been porting our existing code but I am running into problems with the PWM module.
The current method for writing to the PWM pins requires sudo. This seems to be taboo for ROS so we are trying to get access to PWM output without root.
There are older posts about this being a Kernel version issue. We are stuck with an older Kernel since our firmware is provided by Emlid.
pi@navio2:~ $ uname -r 4.14.95-emlid-v7+
However, I think udev is being triggered correctly according to output from udevadm monitor:
pi@navio2:~ $ sudo udevadm monitor --property monitor will print the received events for: UDEV - the event which udev sends out after rule processing KERNEL - the kernel uevent KERNEL[362.821543] change /devices/platform/soc/3f215080.spi/spi_master/spi1/spi1.0/pwm/pwmchip0 (pwm) ACTION=change DEVPATH=/devices/platform/soc/3f215080.spi/spi_master/spi1/spi1.0/pwm/pwmchip0 EXPORT=pwm1 SEQNUM=1233 SUBSYSTEM=pwm UDEV [362.827413] change /devices/platform/soc/3f215080.spi/spi_master/spi1/spi1.0/pwm/pwmchip0 (pwm) ACTION=change DEVPATH=/devices/platform/soc/3f215080.spi/spi_master/spi1/spi1.0/pwm/pwmchip0 EXPORT=pwm1 SEQNUM=1233 SUBSYSTEM=pwm USEC_INITIALIZED=362827030
That output occurs after running the Servo example provided by Emlid with sudo. The example simply enables PWM output then sends commands. If the example is run without sudo then no information is displayed by udevadm monitor.
I have tried variations on udev rules but nothing seems to be modifying the permissions on the directories as required. My changes to the rules file are shown below:
SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\ chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\ chown -R root:gpio /sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770 /sys/devices/platform/soc/*.pwm/pwm/pwmchip*\ '"
I have been able to get non-root access for sending PWM commands using the following procedure but it seems like a hack. If I first run the Servo example with sudo the directories which need chown and chmod are created (they do not exist before calling the Servo program with sudo). I can then manually call chmod and chown on those directories (the same ones specified in the rules file). Then I can shut down the Servo example running with sudo and restart that example with no elevation and everything works fine.
I have posted to the Emlid forum (thinking this was a Navio2 specific issue). However, they have not provided any support and I am hoping that this is a more generic issue.