Python Class for simple subscriber
Hi Guys,
Can anybody help me in getting the python class program for simple subscriber using Python.
Thank you, KK
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Hi Guys,
Can anybody help me in getting the python class program for simple subscriber using Python.
Thank you, KK
hi
this is an example code of simple python class that subscribe one topic:
#!/usr/bin/env python
import rospy
import sys
from std_msgs.msg import String
class simple_class:
def __init__(self):
self.sub = rospy.Subscriber("chatter",String,self.callback)
def callback(self,data):
print(data.data)
def main(args):
obc = simple_class()
rospy.init_node('simple_class', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
if __name__ == '__main__':
main(sys.argv)
Hey I tried something similar, with a callback function defined within the class for the subscriber. But I receive an error for positional arguments. It asks me to have 'self' first and not 'data'. When I make the changes it now says 'data' first and 'self' second. Do you know what this could be?
I need to see your code and error. Please ask a new question and put your code in it.
Asked: 2018-12-11 04:34:38 -0600
Seen: 6,937 times
Last updated: Dec 11 '18
The tutorial page is here. Can you tell us exactly which part you need help with?