import rospy from std_msgs.msg import Bool rospy.init_node('my_bool_publisher') pub = rospy.Publisher('my_bool_topic', Bool, queue_size=10) rate = rospy.Rate(10) while not rospy.is_shutdown(): pub.publish(True) rate.sleep()
import rospy from std_msgs.msg import Bool def callback(msg): print("Received bool value: " + str(msg.data)) rospy.init_node('my_bool_subscriber') sub = rospy.Subscriber('my_bool_topic', Bool, callback) rospy.spin()Brief Explanation: The first example creates a publisher that publishes the boolean value of True at a rate of 10 times per second to the topic named "my_bool_topic". The second example creates a subscriber that listens to the topic named "my_bool_topic" and prints the received boolean value to the console. The callback function is invoked every time a message is received on the topic. Package Library: This message type is part of the std_msgs package, which is a standard ROS package that provides basic message types used across different ROS systems.