cd ~/my_ws/src
catkin_create_pkg my_package rospy
cd my_package
mkdir launch
cd src
vim simple.py
In src folder, create the python script simple.py,
#! /usr/bin/env python
import rospy
rospy.init_node('ObiWan')
print("Help me Obi-Wan Kenobi, you're my only hope")
'''loops
rate = rospy.Rate(2) # We create a Rate object of 2Hz
while not rospy.is_shutdown(): # Endless loop until Ctrl + C
print("Help me Obi-Wan Kenobi, you're my only hope")
rate.sleep() # We sleep the needed time to maintain the Rate fixed above
'''
Allow execution permission,
chmod +x simple.py
In launch folder, create my_package_launch_file.launch,
<launch>
<!-- My Package launch file -->
<node pkg="my_package" type="simple.py" name="ObiWan" output="screen">
</node>
</launch>
Then run by,
roscore # T1
roslaunch my_package my_package_launch_file.launch # T2
# or
# rosrun my_package simple.py