Ask Your Question
0

message_filter (Python 3) not working in ROS Melodic

asked 2019-08-26 11:03:23 -0500

rickstaa gravatar image

updated 2019-08-26 15:30:10 -0500

System information

  • OS: Ubuntu 18.04
  • ROS version: Melodic
  • Conda environment: python=3.7 (Needed for a python3 processing module)

Problem explanation

I try to create a message filter that subscribes to two sensor_msg topics after which a python3 module processes the Color and depth data in a callback function. To do this, I created the following script to achieve this:

#!/usr/bin/env python3

## Import standard library packages ##
import sys

## Import ROS python packages ##
import rospy
import sensor_msgs
from message_filters import ApproximateTimeSynchronizer, Subscriber

def gotimage(image, camerainfo):
    assert image.header.stamp == camerainfo.header.stamp
    print("got an Image and CameraInfo")

## Main script ##
# Only runs when this script is executed directly
if __name__ == "__main__":

    ## Initialize ros node ##
    rospy.init_node('grasp_planner', anonymous=True)
    image_sub = Subscriber("/kinect2/hd/image_color", sensor_msgs.msg.Image)
    camera_sub = Subscriber("/kinect2/hd/camera_info", sensor_msgs.msg.CameraInfo)

    ## Create message_filter ##
    ats = ApproximateTimeSynchronizer([image_sub, camera_sub], queue_size=5, slop=0.1)
    ats.registerCallback(gotimage)
    rospy.spin()

Unfortunately, after trying to run this script, I get the following error message:

/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
[ERROR] [1566834367.342856]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7fb849e44f50>>
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750 ...
(more)
edit retag flag offensive close merge delete

Comments

1

Does anybody know what is the best way to solve my problem?

build rospy with the patch in your Catkin workspace (it wouldn't really be building, as rospy is all Python, but you'll need to do it anyway for Catkin to properly overlay the apt version with the version in your workspace)?

Btw: you appear to be mixing Python 2.x and Python 3 PYTHONPATHs. That is probably not a good idea.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-26 11:30:47 -0500 )edit

@gvdhoorn Thanks a lot for your answer. You mean that I have to build the ros_comm package (which includes the rospy module) from the source from within my catkin workspace as you explained in #252478 and #295012?

Btw: you appear to be mixing Python 2.x and Python 3 PYTHONPATHs. That is probably not a good idea.

My PYTHONPATH currently is /opt/ros/melodic/lib/python2.7/dist-packages since I sourced the devel/setup.bash of my workspace before running the python node. Do I need to remove this line when using a python3 ROS package?

rickstaa gravatar imagerickstaa ( 2019-08-26 13:41:03 -0500 )edit

Btw: you appear to be mixing Python 2.x and Python 3 PYTHONPATHs. That is probably not a good idea.

Ah, I now see what goes wrong. When I try to run the node in the python 3 virtual environment it gives me the No module named 'rospy' not found error.

rickstaa gravatar imagerickstaa ( 2019-08-26 13:55:51 -0500 )edit
1

You don't need to build all of ros_comm most likely. Copying out just the rospy client library package should be sufficient (not very maintainable, but it should work).

gvdhoorn gravatar imagegvdhoorn ( 2019-08-26 14:15:55 -0500 )edit

@gvdhoorn Thanks for your explanation. I tried building the rospy module from source but I now get a new attribute error. The steps I performed while doing this can be found appended to the question above.

The other strange thing is that the python3 package still ends up in the /home/ricks/panda_autograsp_ws/devel/lib/python2.7/dist-packages folder instead of the /home/ricks/panda_autograsp_ws/devel/lib/python3.7/dist-packages.

rickstaa gravatar imagerickstaa ( 2019-08-26 15:30:14 -0500 )edit
1

I don't believe that is strange: from what you show here it would appear you're still mixing Python 2 and Python 3 (your Conda environment). Without special care, Catkin will use Python 2. sourceing a workspace from inside your Conda environment will not change that.

Note that the patch only makes that particular part of rospy language-compatible with Python 3, if you're still using Python 2, Python 2 will still be used.

You may try the procedure outlined here, but from within your Conda environment instead of a plain venv.

No guarantees, but it could work.

gvdhoorn gravatar imagegvdhoorn ( 2019-08-27 03:15:12 -0500 )edit

@gvdhoorn thanks a lot for the explanation. I will do some testing and report my solution back as an answer.

rickstaa gravatar imagerickstaa ( 2019-08-29 15:31:03 -0500 )edit

@gvdhoorn As I managed to use the package with python 2.7, after all, I didn't test the procedure you outlined in this topic. I, however, added an answer based on my current findings below so I can close this question. Although I know I saw a python 3 transitioning status REP for the ROS main packages (see the <reference> tag) somewhere I was unable to find it again. Do you maybe know where I can find such an overview? Feel free to correct me if I misunderstood something in my answer below.

rickstaa gravatar imagerickstaa ( 2019-08-31 07:37:01 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-31 07:32:10 -0500

rickstaa gravatar image

updated 2019-08-31 07:45:33 -0500

As a package I was using recommended python3 I tried to get ROS to work with Python3. Below I summarised my findings while doing this.

Overal ROS python 3 support status

A list of ROS distributions and their python-support status can be found here. A guide on how to use python3 with rose can be found in the UsingPython3 page of the Ros documentation.

ROS kinetic with python 3

Since at the time I started building my package the franka_ros wasn't released for melodic I had to use kinetic. However, since ROS kinetic does not fully support python3 getting the GQCNN to work under ubuntu 16.04 ROS Kinetic is not easy. I kept running into problem after problem. In the end, I decided to contribute python 2/python 3 compatibility fixed to the python 3 repositories and use python 2.7 instead. If other people really need to work with python 3 and ROS kinetic, please refer to this ros issue.

ROS melodic with python 3

As stated in the distribution list ROSROS Python packages starting with Melodic are highly encouraged to support both Python 2.7 and Python 3.5 or later. As a result, better ROS Melodic python 3 support is on its way. The core packages in ROS melodic are currently being ported from python 2 to python 3. An overview of which is core packages are already fully python 3 compatible can be found here [REFERENCE]. If you experience a python 2/3 incompatibility issue you can check the corresponding package repository at (https://github.com/ros)[https://githu... and file an issue. If you, have to use a package that is not yet ported to python 3 you have to build this package from source. As explained by @gvdhoorn the procedure of doing this can be found here.

Additional Resources

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-08-26 11:03:23 -0500

Seen: 41 times

Last updated: Aug 31