







Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!








talking to each other, and what topics are being used to pass the information (messages) between nodes.
So far, we learned how to find our way around, "given" a ROS application. But this is not always going to be the case in the real world, as we will soon be requiredto develop our own ROS applications. So, what is a ROS application? What components constitute a ROS application? How do we build our own ROS application? We will learn how to do so in this module.
will focus on publisher and subscriber" ROS nodes. The words publisher and subscriber do seem somewhat familiar already to us although we didn't explicitly study them yet!
We will first start with the publisher node. We studied that nodes are information or data processing units. Sure, but where does the information come from? Who generates the information?
Subsequently, the subscriber node is initialized with the rospy.init_node() function. Following the node initialization, the subscriber object is created using the rospy.Subscriber() function call. This function takes the topic to which the node subscribes to, the topic type and the subscriber callback function as arguments.
import rospy from std_msgs.msg import String def simplePublisher(): simple_publisher = rospy.Publisher('topic_1', String, queue_size = 10) rospy.init_node('node_1', anonymous = False) rate = rospy.Rate(10)
topic1_content = "my first ROS topic" while not rospy.is_shutdown(): simple_publisher.publish(topic1_content) rate.sleep() if name== 'main': try: simplePublisher() except rospy.ROSInterruptException: pass
import rospy from std_msgs.msg import String
def stringListenerCallback(data): rospy.loginfo(' The contents of topic1: %s', data.data) def stringListener(): rospy.init_node('node_2' , anonymous = False) rospy.Subscriber('topic_1' , String, stringListenerCallback)
rospy.spin() if name == 'main': stringListener()
Explored some utility commands for finding information regarding a running ROS application. In order to be able to build our own application, we will have to write our own code files. Where do we put these files? How are they organized? Let's find out!
2.2.1 SRC Folder: Now that we know what's inside a ROS workspace and how to create a catkin workspace for a ROS application, let's go one step further into the source space.
field for the sensor part number. This is implemented in code in the SensorInformation.msg file as shown in this code snippet.