Created
December 9, 2018 13:39
-
-
Save TheProjectsGuy/c09dc32ac0e662af29350ed36d1badc8 to your computer and use it in GitHub Desktop.
Simple Subscriber made using Python in ROS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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