import rospy from geometry_msgs.msg import Point rospy.init_node('point_publisher') pub = rospy.Publisher('point_topic', Point, queue_size=10) point_msg = Point() point_msg.x = 1.0 point_msg.y = 2.0 point_msg.z = 3.0 rate = rospy.Rate(10) while not rospy.is_shutdown(): pub.publish(point_msg) rate.sleep()
import rospy from geometry_msgs.msg import Point def callback(point_msg): # do something with point_msg pass rospy.init_node('point_subscriber') sub = rospy.Subscriber('point_topic', Point, callback) rospy.spin()In this example, a node is created to subscribe to a `Point` message on the `point_topic`. The `callback` function is called whenever a `Point` message is received. The received message can be accessed through the `point_msg` argument of the `callback` function. The `rospy.spin()` function is used to keep the node running indefinitely. Overall, the `geometry_msgs.msg` package is a useful library for working with geometric data in ROS using Python.