ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Don't know about the rest, but we see this:
class GoForward():
def __init__(self):
...
rospy.Timer(rospy.Duration(2), self.my_callback)
you're not assigning the Timer
to anything, causing the temporary object to go out of scope immediately and being destroyed.
So the Timer
never really does anything.
You'll probably wan to do something like this:
self.my_timer = rospy.Timer(rospy.Duration(2), self.my_callback)
2 | No.2 Revision |
Don't know about the rest, but we see this:
class GoForward():
def __init__(self):
...
rospy.Timer(rospy.Duration(2), self.my_callback)
you're not assigning the Timer
to anything, causing the temporary object to go out of scope immediately and being destroyed.
So the Timer
never really does anything.
You'll probably wan to do something like this:
self.my_timer = rospy.Timer(rospy.Duration(2), self.my_callback)
And the same issue here:
if __name__ == '__main__': try: GoForward()
GoForward
is not a function, but a class
.
You're calling the constructor of the class, but don't store the returned object anywhere.
So your program creates an instance of GoForward
, which is then immediately destroyed as it's not assigned to a variable in scope.
In the end, your program does nothing as it terminates immediately after calling the GoForward
constructor and destroying the object.
You'll probably want to do something like this:
obj = GoForward()
And then also add this afterwards:
rospy.spin()
Because without it -- or something similar -- your program again exits immediately.
3 | No.3 Revision |
Don't know about the rest, but we see this:
class GoForward(): def __init__(self): ... rospy.Timer(rospy.Duration(2), self.my_callback)
you're not assigning the Timer
to anything, causing the temporary object to go out of scope immediately and being destroyed.
So the Timer
never really does anything.
You'll probably wan to do something like this:
self.my_timer = rospy.Timer(rospy.Duration(2), self.my_callback)
And the same issue here:
if __name__ == '__main__': try: GoForward()
GoForward
is not a function, but a class
.
You're calling the constructor of the class, but don't store the returned object anywhere.
So your program creates an instance of GoForward
, which is then immediately destroyed as it's not assigned to a variable in scope.
In the end, your program does nothing as it terminates immediately after calling the GoForward
constructor and destroying the object.
You'll probably want to do something like this:
obj = GoForward()
And then also add this afterwards:
rospy.spin()
Because without it -- or something similar -- your program again exits immediately.
Edit: in your updated code, you:
Timer
in a member variableGoForward
instance in a variableYour script still has the same problems as the original version.