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

Executing Python codes inside ROS

asked 2020-10-11 19:28:06 -0500

Dalsallum gravatar image

Hello everyone.

I'm new in the ROS and Linux world, I'm still learning but I'm confused with some aspects regarding ROS nodes and how it's related to execute Python code with it. I've already written a Python code in Windows, if I want to run it in ROS should I have a package for it and nodes and catkin_make every time I make a changes in the code ? I'm following the ROS tutorial from ROS.org but I feel it's mostly " this will do this do this and that" , I'm using ROS kinetic with Ubuntu 16.04.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-10-12 05:02:45 -0500

Weasfas gravatar image

@Dalsallum Welcome to the forum!

To answer your question you will need to understand several things:

  1. If you want your code to interat with any ROS utility or tool you will need to include you code inside a node inside a catkin package in your workspace src folder. Take into account that you can execute your script in any location of your machine, however it is advisable to implement it inside a package in order to let ROS know the location of the script and several enviromental things. If you want to know more about this topic, there is a nice tutorial about that here.
  2. Once your code is inside a node, you will need to configure your enviroment first and then use catkin_make once to let ROS process all your packages in you src folder and set up important enviromental variables.
  3. Since you are using python (rospy), you do not need to compile every time you change your node because python is interpreted (it needs and interpreter not a compiler). Hence, you can change any line in your script and still be able to execute it without the need of a catkin_make. However if you are working with C++ (roscpp), you will need to compile (catkin_make) every time to generate the executables, libs etc. with the changes performed.

If you have doubts regarding rospy you can check the official tutorials page, that also exists for roscpp.

Hope this solve all your doubts.

Regards.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-10-11 19:28:06 -0500

Seen: 143 times

Last updated: Oct 12 '20