Subscriber fails to reach published data
Publisher seems to be workable but when I do a rosrun on receiver script the error exists. as very new on this field I have no idea how to fix. thank you in advance.
1. Error Details
Traceback (most recent call last):
File "/home/------/proto_one/src/sensors_unit/scripts/first_sensor.py", line 28, in <module>
first_sensor()
File "/home/------/proto_one/src/sensors_unit/scripts/first_sensor.py", line 23, in first_sensor
pub.publish(testnum)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 886, in publish
raise ROSSerializationException(str(e))
rospy.exceptions.ROSSerializationException: field data must be an integer type
2. Receiver code(Subscriber)
#!/usr/bin/env python3
import rospy as R
from std_msgs.msg import Int16
import random
def callback(data):
R.loginfo(data.data)
def reciever():
R.init_node("reciever", anonymous=True)
R.Subscriber("commuline1", Int16, callback)
R.spin()
if __name__ =="__main__":
reciever()
3. Sender code (Publisher)
#!/usr/bin/env python3
import rospy as R
from std_msgs.msg import Int16
import random
global x
x = 0
def first_sensor():
x=0
pub = R.Publisher("commuline1", Int16, queue_size=10)
R.init_node("first_sensor", anonymous=True)
rate =R.Rate(10)
while not R.is_shutdown() and x <1000000 :
x += 1
t = x
testnum = "helloooo %s" %R.get_time()
##testnum2 = print(testnum)
##print(testnum2)
##pub.publish(testnum2)
print(t)
pub.publish(testnum)
rate = R.Rate(10)
if __name__ == "__main__":
try:
first_sensor()
except R.ROSInterruptException:
pass