Trying to access information from another function
Here is my code
def callback(data):
#rospy.loginfo(data.position[1])
print(data.position[0])
x = data.position[0]
return x
def listener():
rospy.init_node('listener')
rospy.Subscriber('/rrbot/joint_states', JointState, callback)
rospy.spin()
def talker():
pub = rospy.Publisher('/rrbot/joint1_position_controller/command', Float64, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(1) # 10hz
while not rospy.is_shutdown():
#hello_str = "hello world %s" % rospy.get_time()
force = random.choice([-1,1])
#force = 0
rospy.loginfo(force)
pub.publish(force)
rate.sleep()
return force
def trainer():
force = talker()
x = callback(data)
print(force)
print(x)
if __name__ == '__main__':
try:
trainer()
except rospy.ROSInterruptException:
pass
this is my error when i try to run the code
NameError: name 'data' is not defined