ROS Topic Subscriber

Follow along: ROS Topic Subscriber Example

The program launching process along with parameter settings are all simplified and set up on the Jupyter Notebook Environment.
  • Open the 01_02_ros_topic_subscriber.ipynb Jupyter Notebook
  • Import the necessary python libraries and modules
  • Follow and Execute the example codes
(The Jetson Board used for these examples are => Jetson Nano)

Open the following jupyter notebook:

  • 03_02_ros_topic_subscriber.ipynb

  • To run the cells within the notebook use Ctrl + Enter


Import the necessary python libraries and modules

import rospy
from std_msgs.msg import String
  • Create callback() function

  • Within the callback function:

    • Node id and message data output

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
  • Create listener() function

  • Within the listener function:

    • Create listener Node

    • Subscribe to Chatter Topic Message

    • Handle Subscriber Callback

def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("chatter", String, callback)
    rospy.spin()
  • Execute the listener() function with handler functions.

listener()