Skip to content

Instantly share code, notes, and snippets.

@TheProjectsGuy
Created December 9, 2018 13:39
Show Gist options
  • Save TheProjectsGuy/c09dc32ac0e662af29350ed36d1badc8 to your computer and use it in GitHub Desktop.
Save TheProjectsGuy/c09dc32ac0e662af29350ed36d1badc8 to your computer and use it in GitHub Desktop.
Simple Subscriber made using Python in ROS
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64
# Function callback
def msgReceived(msg):
# Parse the received message as Float 64 type
message = Float64(msg)
# Log that as INFO
rospy.loginfo("Received: {0}".format(message.data))
def main():
# Initialize the node
rospy.init_node("NumberSubscriber", anonymous=True)
# Setup the subscription
subscriberObject = rospy.Subscriber("floating_numbers", Float64, msgReceived)
# Wait for the messages forever
rospy.spin()
# Code entrypoint
if __name__ == "__main__":
try:
main()
except rospy.ROSInterruptException:
rospy.logerr("An error has occurred")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment