Ask Your Question
1

robot_upstart: Nodes using third party libraries are ignored [Python]

asked 2018-01-10 07:22:43 -0600

mohsen gravatar image

updated 2018-01-10 08:01:19 -0600

mgruhler gravatar image

I'm using ROS on raspberry pi 3. I'm using two third party libraries, one for reading sensor registers from I2C (FaBo9AXIS-MPU9250-Python) and one for generating PWM signal on pins (pigpio).
Any node importing one won't start by ros_upstart as if it doesn't exist in the launch file (also no log file is generated). What's wrong?
Here's one of the nodes:

import rospy
import FaBo9Axis_MPU9250
from sensor_msgs.msg import Imu


rospy.init_node('imu')

mpu9250 = FaBo9Axis_MPU9250.MPU9250()

pub = rospy.Publisher('imu/data_raw',Imu, queue_size = 1)
msg = Imu()
msg.orientation_covariance[0] = -1
msg.header.frame_id = 'imu'
rate = rospy.Rate(100)

while not rospy.is_shutdown():
    accel = mpu9250.readAccel()
    gyro = mpu9250.readGyro()

    msg.header.stamp = rospy.Time.now()

    msg.linear_acceleration.x = accel['x'] * 9.81
    msg.linear_acceleration.y = accel['y'] * 9.81
    msg.linear_acceleration.z = accel['z'] * 9.81

    msg.angular_velocity.x = (gyro['x'] - 0.9) * 0.01745329251
    msg.angular_velocity.y = (gyro['y'] - 0.5) * 0.01745329251
    msg.angular_velocity.z = gyro['z'] * 0.01745329251

    pub.publish(msg)
    rate.sleep()
edit retag flag offensive close merge delete

Comments

Well, it is hard to say. But as you are trying this with HW, this ist most often an issue with permissions. Check the documentation and consider setting the ports you are using to world read/writeable...

mgruhler gravatar imagemgruhler ( 2018-01-10 08:05:18 -0600 )edit

Thanks. What do you mean by "ports" ?

mohsen gravatar imagemohsen ( 2018-01-10 08:55:38 -0600 )edit

Also check PYTHONPATH of the user that runs the service and see the directory of your python file is included.

130s gravatar image130s ( 2018-01-10 09:06:42 -0600 )edit

By port I mean the GPIO device and the I2C device. Typically (well, on Ubuntu, Ubuntu Mate, ...) you Need to be in the group dialout to get access to those devices. As the docu states, you don't have the group membership when at the point of time that robot_upstart starts the scripts...

mgruhler gravatar imagemgruhler ( 2018-01-10 09:52:28 -0600 )edit

So as I understand,root starts the service and the unprivileged user executes the launch file. I have to make sure the user has access to GPIO.

mohsen gravatar imagemohsen ( 2018-01-10 10:45:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-10 15:45:43 -0600

mohsen gravatar image

updated 2018-01-10 15:46:25 -0600

I tracked down the problem to these two lines in the libraries:

import pigpio

and

bus = smbus.SMBus(1)

Running this command solved the first problem

sudo chown root.gpio /dev/gpiomem && sudo chmod a+x /dev/gpiomem

To fix the second one, I had to modify 99-com.rules .

/etc/udev/rules.d/99-com.rules

It was only necessary to change the mode corresponding to i2c-dev to 0777 (read/write for all).

SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0777"

Come to think of it, I could do the same for the gpio line and probably fix both issues using this file.

edit flag offensive delete link more

Comments

1

That's what I'm talking about :-) There are several ways to fix the Group permissions. Using udev is IMO the best one.

mgruhler gravatar imagemgruhler ( 2018-01-11 01:07:50 -0600 )edit

Thanks for 130s and your support. It was my first time ever hearing about udev :) so it took a while to get there.

mohsen gravatar imagemohsen ( 2018-01-11 01:47:58 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-01-10 07:22:43 -0600

Seen: 386 times

Last updated: Jan 10 '18