ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Is a Python 3 Subscriber Node in ROS Melodic Simple to Make?

asked 2021-03-26 03:16:37 -0600

DauntingROS gravatar image

Im brand new to ROS (just about a day of self learning through the wiki) and I'm trying to figure out whether or not I can make a python3 subscriber node in ROS Melodic.

I have, in searching for an answer, seen mixed responses and I think some of the nuances of the answers I have seen are going over my head.

I guess a way to simplify my question, is to ask whether or not all it would take to make a Python3 Subscriber node on a standard, apt installation (no compiling from source), is changing the

!/usr/bin/env python

header at the top to

!/usr/bin/env python3

Of course, I do realize this may be an XY problem, so I will also include some details about why I'm trying to accomplish this.

I am using ROS Melodic rather than ROS2 or a newer version of ROS because I am using the latest Jetpack (Ubuntu 18.04) with a Jetson Nano 2Gb as that seems to be the latest version that is supported on this platform without a lot of headache.

I already have some python3 code that uses adafruit_servokit (Which requires circuit python (and blinka for that)) to operate a robotic arm via a standard PCA9685 I2C PWM driver board, and was hoping I could more or less drop it in place to have some ROS modules control it instead.

I imagine the alternative is to look into other PCA9685 drivers and mostly do the same thing but in python 2.7, but well, python3 is nicer so if it was possible and it was just a simple change I was unaware of in my way, i'd like to go that route instead.

For reference to where I'm at with ROS, I finished about 14 of the 21 beginner tutorials (choose the python path for more rapid results and skipped a few of the last tasks to come back to if necessary/later), and have gotten to a point where I have made a custom URDF for my robot arm and have the virtual arm controllable via joint_state_publisher_gui.


Summary Question: Is it a simple task to make a Python 3 Subscriber Node in ROS Melodic?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-03-26 10:59:39 -0600

DauntingROS gravatar image

So, I figured it out. Turns out its not quite as easy as I posited, but it is quite easy.

Thank goodness I did not go through with the whole building from source routine and happened upon this guide.

Because things disappear from the internet, I'll copy the relevant section here:

All it took was making sure that some things were installed via:

sudo apt-get install python3-pip python3-yaml
sudo pip3 install rospkg catkin_pkg

I really wish this was more obvious

The way I tested this was by simply adding a print (sys.version) somewhere in the example listener and seeing that it printed my python version. (Make sure you rebuild your package)

edit flag offensive delete link more

Comments

1

I really wish this was more obvious

the thing is: it you want to do this properly, it's not that easy.

You most likely only use Python-only dependencies, and in that case, it can work, but there are no guarantees.

Additionally, if you start to use anything which also has a compiled part to it (OpenCV fi or MoveIt) just switching the shebang to python3 and pip install-ing some ROS packages (which is not a good idea regardless of the goal) will not work.

That's one of the reasons why this is not 'marketed' as a solution.

gvdhoorn gravatar image gvdhoorn  ( 2021-03-26 11:26:25 -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

Stats

Asked: 2021-03-26 03:16:37 -0600

Seen: 683 times

Last updated: Mar 26 '21