from std_msgs.msg import Bool # Creating a boolean message object msg = Bool() # Initializing the message with a boolean value msg.data = True # Publishing the message to the '/bool_topic' topic publisher = rospy.Publisher('/bool_topic', Bool, queue_size=10) publisher.publish(msg)
from std_msgs.msg import Bool def callback(msg): # Printing the value of the received message print(msg.data) # Subscribing to the '/bool_topic' topic subscriber = rospy.Subscriber('/bool_topic', Bool, callback) # Waiting for new messages rospy.spin()In this example, we are subscribing to the '/bool_topic' topic using a `rospy.Subscriber`. Whenever a new `Bool` message is received on this topic, the `callback` function is called with the received message as an argument. The `callback` function simply prints the value of the received message. These examples give an idea about how to create, publish, and subscribe to `std_msgs.msg Bool` messages in a ROS system.