Ask Your Question
0

Python Class for simple subscriber

asked 2018-12-11 04:34:38 -0500

kk2105 gravatar image

Hi Guys,

Can anybody help me in getting the python class program for simple subscriber using Python.

Thank you, KK

edit retag flag offensive close merge delete

Comments

3

The tutorial page is here. Can you tell us exactly which part you need help with?

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-12-11 05:40:33 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-12-11 21:46:53 -0500

hamid gravatar image

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)
edit flag offensive delete link more

Comments

@hamid Thank you for the solution. Will try the same and post the updates.

kk2105 gravatar image kk2105  ( 2018-12-16 22:16:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-12-11 04:34:38 -0500

Seen: 1,084 times

Last updated: Dec 11 '18