1.3.2 HelloWorld
This section builds upon section 1.3.1. Assuming you have already created a ROS workspace and a ROS package, you can now proceed to the core steps. Use Python to implement the program as follows:
1. Navigate to the ROS package, add a scripts directory, and edit the Python file
text
cd ros_package
mkdir scriptsCreate a new Python file: (The filename can be customized)
python
#! /usr/bin/env python
"""
Python Version HelloWorld
"""
import rospy
if __name__ == "__main__":
rospy.init_node("Hello")
rospy.loginfo("Hello World!!!!")2. Add execute permissions to the Python file
text
chmod +x custom_filename.py3. Edit the CMakeLists.txt file in the ROS package
text
catkin_install_python(PROGRAMS scripts/custom_filename.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)4. Navigate to the workspace directory and compile
text
cd custom_workspace_name
catkin_make5. Navigate to the workspace directory and execute
First, start command line 1:
text
roscoreThen start command line 2:
text
cd workspace
source ./devel/setup.bash
rosrun package_name custom_filename.pyOutput result: Hello World!!!!