ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
At the very minimum, you should make x
a global
variable. For example, at the top of your program
x = None
to bring it into the global scope and in your function
def callback(msg):
global x
x = msg.pose.position.x
Now, this is ok for small, toy programs but you will quickly run into problems with anything more significant. Therefore, should look into how classes work in Python or into event-driven programming.
2 | No.2 Revision |
At the very minimum, you should make x
a global
variable. For example, at the top of your program
x = None
to bring it into the global scope and in your function
def callback(msg):
global x
x = msg.pose.position.x
Now, this using global
s is ok for small, toy programs but you will quickly run into problems with anything more significant. Therefore, should look into how classes work in Python or into event-driven programming.
3 | No.3 Revision |
At the very minimum, you should make x
a global
variable. For example, at the top of your program
x = None
to bring it into the global scope and in your function
def callback(msg):
global x
x = msg.pose.position.x
Now, using global
s is ok for small, toy programs but you will quickly run into problems with anything more significant. Therefore, should look into how classes work in Python or into event-driven programming.
Edit:
Part of the issue that you're having is that rospy.spin()
just blocks until the node is shutdown and the other part is you're only printing once. If you want to print more than once, either put the print
inside your callback or switch to a loop in your main.
4 | No.4 Revision |
At the very minimum, you should make x
a global
variable. For example, at the top of your program
x = None
to bring it into the global scope and in your function
def callback(msg):
global x
x = msg.pose.position.x
Now, using global
s is ok for small, toy programs but you will quickly run into problems with anything more significant. Therefore, should look into how classes work in Python or into event-driven programming.
Edit:
Part of the issue that you're having is that rospy.spin()
just blocks until the node is shutdown and the other part is you're only printing once. If you want to print more than once, either put the print
inside your callback or switch to a loop in your main.