Keep getting that Rate is not defined
I am having some strange problem. When I run the python program I get an error that Rate is not defined:
line 30, in EncoderNodeLeft
rate.sleep()
NameError: name 'rate' is not defined
Here is my code:
import time
#import ASUS.GPIO as GPIO
import rospy
from geometry_msgs.msg import PoseStamped
from nav_msgs.msg import Path
from std_msgs.msg import Int16
class EncoderNodeLeft:
def __init__(self,encoder):
self.tick = 0
self.encoder = encoder
self.pub = rospy.Publisher("lwheel", Int16, queue_size=1000)
def tick_callback(self,channel):
self.tick += 1
if self.tick > 32766:
self.tick = 0
self.pub.publish(self.tick)
def run(self):
#GPIO.add_event_detect(self.encoder, GPIO.RISING, callback=self.tick_callback)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
rate.sleep()
if __name__ == "__main__":
try:
rospy.init_node("encoder_node_left")
encoder = 224
encoder_node_left = EncoderNodeLeft(encoder)
encoder_node_left.run()
except rospy.ROSInterruptException:
rospy.loginfo("There was an exception in encoder_node_left")
Both
tick_callback(..)
andrun()
are functions, not methods of classEncoderNodeLeft
: they are missing theself
argument. Soself.tick
(in the cb) will fail fi.Not saying that is necessarily the cause, but it's a potential problem in any case.
@gvdhoorn yes you are right, stupid mistake. But this is not a cause