ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Global variable x is not defined

asked 2014-06-24 07:36:30 -0500

jashanvir gravatar image

updated 2014-06-24 07:46:15 -0500

Hello guy ! I am getting a following error Global variable x is not defined.

def where1(msg):
    global x1
    x1 = msg.data
def where2(msg):
    global y1
    y1 = msg.data

def ground():
    global cmd
    cmd = rospy.Publisher("/atrv/motion", Twist)
    rospy.init_node("ground")   
    rospy.Subscriber("/box_positiona", Float64, where1)
    rospy.Subscriber("/box_positionb", Float64, where2)
    print x1
    print y1
    rospy.spin() # this will block untill you hit Ctrl+C
if __name__ == '__main__':
    ground()

Thanks, looking forward for answers

edit retag flag offensive close merge delete

Comments

Please copy and paste error message directly.

dornhege gravatar image dornhege  ( 2014-06-24 07:48:01 -0500 )edit

NameError: global name 'x1' is not defined

jashanvir gravatar image jashanvir  ( 2014-06-24 10:06:09 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-06-24 13:42:28 -0500

dornhege gravatar image

Is there any code that sets this variable globally?

edit flag offensive delete link more
0

answered 2014-06-24 07:41:08 -0500

ct2034 gravatar image

updated 2014-06-24 07:41:55 -0500

Hi I don't know whether this solves your problem. But please try first to solve you spacing:

def where1(msg):
    global x1
    x1 = msg.data
def where2(msg):
    global y1
    y1 = msg.data

def ground():
    global cmd
    cmd = rospy.Publisher("/atrv/motion", Twist)
    rospy.init_node("ground")   
    rospy.Subscriber("/box_positiona", Float64, where1)
    rospy.Subscriber("/box_positionb", Float64, where2)
    print x1 # <-- *here* !!!!
    print y1 # <-- *here* !!!!
    rospy.spin() # this will block untill you hit Ctrl+C
if __name__ == '__main__':
    ground() # <-- *and here* !!!!
edit flag offensive delete link more

Comments

Thanks for editing! I made that mistake while writing the question !

jashanvir gravatar image jashanvir  ( 2014-06-24 10:07:09 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-24 07:36:30 -0500

Seen: 1,675 times

Last updated: Jun 24 '14