ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The issue is resolved now. I had to add "self." as prefix to all of the variables that I wanted to consider as "global" in a specific class.
Here's the modified code:
class node():
def __init__(self):
rosInstance = rospy
self.pub = rosInstance.Publisher('cmd_vel', Twist)
r = rosInstance.Rate(1)
self.ctrlArgs = Twist()
self.iteration = 0
speed = -0.1
while not rospy.is_shutdown():
self.iterate()
if iteration < 20:
self.cntrlArgs.linear.x = 0.2
self.pub.publish(ctrlArgs)
r.sleep()
def iterate(self):
self.iteration = self.iteration + 1