0

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.

  • It is difficult to find what's the question. I'm missing that sentence ending with a question mark. – Ingo Oct 10 at 0:00
  • @Shawn Herrington, Ah, let me see. (1) I agree roslaunch is a good starting point to do sudo things. (2) Emlid says the following on PWM servo: "cd Python / sudo python Servo.py / For further information see cource code ..." (3) I have the feeling that Navio2 is hacker friendly. So you need to mess around with Emlid's open source drivers. Good luck and cheers. – tlfong01 Oct 10 at 1:43
  • @Ingo, the question is how to get non-root access working for PWM output. This question has been asked here and elsewhere in the past but I have been unable to get it working on our hardware by following other solutions I have found online. – Shawn Herrington Oct 10 at 17:49
  • @tlfong01 I was under the impression that running nodes as sudo via roslaunch or rosrun was possible but not recommended. We have successfully "hacked" the Navio2 but I was under the impression that their drivers were not open-source. In any case, I have not been able to enable non-root access to the PWM output by following any of the other accepted solutions online. I was hoping to get some assistance figuring out why I haven't been able to get non-root PWM output working and/or suggestions on how to get it working in this specific case. – Shawn Herrington Oct 10 at 17:53
  • @Shawn Herrington, Ah, let me see. I have been using Thonny Python, and I can easily fiddle with PWM GPIO pins without worrying the sudo thing. Of course you can write your own drivers doing DMA hardware timer (I did it with Arduino, but not yet tried with Rpi4). PWM drivers, compared with more complex things, such as sensors, display drivers, are actually very easy. If your open source project is at all levels open source, except the drivers, then perhaps you could think about writing your own PWM drivers. Don't know how is intermingled with the RTOS, so perhaps it is mission impossible. – tlfong01 Oct 12 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.