Cannot publish a list to a rostopic using a class in Python
Hello, I have created a class and defined a publisher in the __init__
. i have defined a function in the class and would like to publish a list into the topic but it seems that the data doesn't get published at all. It works fine when I remove classes and just define a single function but I want to work this out using a class.
Here is the code,
#!/usr/bin/python
#from std_msgs.msg import String
import rospy
from trajectory_msgs.msg import JointTrajectoryPoint
import random
class TrialPublisher:
def __init__(self):
self.pub = rospy.Publisher('trialtopic', JointTrajectoryPoint, queue_size=10)
self.node = rospy.init_node('talker', anonymous=True)
def talker(self):
#rate = rospy.Rate(10) # 10hz
action1 = [0.10972262, 0.46574646, 0.74584746, -0.79732597, -0.17833593, -0.74599963]
action2 = [0.1372262, 0.40574646, 0.64584746, -0.69732597, -0.1633593, -0.7299963]
action3 = [0.11972262, 0.46574646, 0.70584746, -0.73732597, -0.15833593, -0.73599963]
action4 = [0.12972262, 0.46574646, 0.72584746, -0.72732597, -0.14833593, -0.74999963]
action5 = [0.12972262, 0.46574646, 0.73584746, -0.71732597, -0.13833593, -0.8599963]
action6 = [0.14972262, 0.46574646, 0.6584746, -0.70732597, -0.12833593, -0.44599963]
action = random.choice([action1, action2, action3, action4, action5, action6])
x = JointTrajectoryPoint()
x.positions = action #rospy.loginfo(hello_str)
self.pub.publish(x)
s = TrialPublisher()
s.talker
I get the error as, WARNING: no messages received and simulated time is active. Is /clock being published?