Understanding ROS with Python

asked 2021-10-20 13:46:31 -0500

oroshimaru gravatar image

Hello! I have been using ROS for quite a while now with C++. Now I also started devloping ROS-Nodes with Python, even my code is somehow working I just do not understand what the general approach of using python with ros is?

So I am working on Kinetic and Melodic right now which do not support Python3 officially. These are my Questions:

  1. How do you build a package, which purely uses Python correctly?

    • I could create the package, create all my nodes.py inside that package, rosrun and it seems to work.
    • But I have also seen the option where people use catkin_python_setup() and a setup.py. Why? So in the stuff that I tried both approaches seem to work fine and I could not see an advantage of one of them. So when do you use which approach?
  2. How to correctly use Python3 with Kinetic/Melodic?

    • So the first approach which I have seen and which seesms to work is to add the following line to the beginning of your node.py: #!/usr/bin/env python3
    • I could tell ros before building to use python3 like this: -DPYTHON_EXECUTABLE=/usr/bin/python3

Here The second approach make the whole ws usw Python3 where the first one only that one script. Is that the only difference here? Is the first approach here recommended to use?

edit retag flag offensive close merge delete

Comments

If python3 is important to you, it would be much easier to simply use noetic.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-10-20 16:11:35 -0500 )edit

@Mike Of course I will update in the future but for now updating is not an option. And also Python is not important, I just started using it with ROS, it has some advantages regarding ml tasks. As I tried to made clear in my question my Python packages all work fine so far, I just want to understand it better.

oroshimaru gravatar image oroshimaru  ( 2021-10-20 19:35:05 -0500 )edit