Topic not subscribed to properly [closed]
I'm writing a new node and am following examples on how to do that in python.
This node subscribes to a topic being published from another node (this other node's published topic is being published correctly as verified by "rostopic echo /topicname").
However, the subscriber node doesn't seem to be subscribing correctly to this topic (although the Callback is displaying the information to the command line correctly that it should be taking as input).
I'm in ROS Groovy.
The code is here:
#!/usr/bin/python
#JOE
#August 2014
#publishes topic ilimb_grip_pub
#subscribes topic ilimb_define_pos
import rospy
from std_msgs.msg import String
import socket
#UDP_IP = "129.107.3.95"
UDP_IP = "127.0.0.1" #debug
UDP_PORT = 9000
Program_Name = "./handcontrol"
def callback(data):
rospy.loginfo(rospy.get_caller_id()+"I heard %s",data.data)
def ilimb_grip_pub():
# this listens to a user input for a user-defined hand configuration
rospy.init_node('ilimb_grip_pub', anonymous=True)
rospy.Subscriber("ilimb_define_pos", String, callback)
#this creates the publisher topic
#pub = rospy.Publisher('ilimb_grip_pub', String) #needs to publish to a IP addr/ port
#rospy.init_node('ilimb_move', anonymous=True)
r = rospy.Rate(10) # 10hz
#this loop needs to be modified to publish hand configurations
#based on user input
while not rospy.is_shutdown():
print ilimb_define_pos.msg
#~ define_pos= ilimb_define_pos.split(" ")
#~ print define_pos
#~ Digit_ID = define_pos[0]
#~ Command = define_pos[1]
#~
#~ Message = "%s %d %s\n"%(Program_Name, Digid_ID, Command)
#~
#~ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#~ sock.sendto(Message, (UDP_IP, UDP_PORT))
#~
#~ rospy.loginfo(Message)
#~ #pub.publish(str)
#~ r.sleep()
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
#~
if __name__ == '__main__':
try:
ilimb_grip_pub()
except rospy.ROSInterruptException:
pass
I'm getting the error:
NameError: global name 'ilimb_define_pos' is not defined.
This is strange as this is the topic to which I am subscribing... any ideas? I'm drawing a blank.