ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Writing to GPIO pins on Raspberry Pi from ROS2 node

asked 2022-03-03 10:38:51 -0500

max11gen gravatar image

I'm trying to write to my RPi's GPIO pins using the pigpiolibrary (http://abyz.me.uk/rpi/pigpio/index.html) from within a ROS2 node. The problem is, that in order to use a pigpio program you need sudo rights. If I try running my node as sudo with sudo ros2 run package node I get an error saying sudo: ros2: command not found. It is definitely not because I forgot to source my workspace. So can anyone tell me how to run my node with sudo? Or does anyone know about a workaround?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-04 03:28:49 -0500

dannee gravatar image

By using sudo you are using a different set of environmental variables. So you have to source the ros environment for the root user. This can be done by:

sudo su

source </path/to/ros>

source </path/to/your/workspace>

ros2 run <package node>

Then it should work

edit flag offensive delete link more

Comments

1

Using the root user for everything is generally a bad idea. I would rather try something like the following: https://forums.raspberrypi.com/viewto...

lukicdarkoo gravatar image lukicdarkoo  ( 2022-03-06 04:04:46 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-03-03 10:38:51 -0500

Seen: 799 times

Last updated: Mar 03 '22