adding std_msgs Int16 and int ?
i made a simple publisher which publish a Int16. the problem is in the subscriber i try to receive the int16 and add a constant number to it for example 2 the publisher code:
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import Int16
import random
def ty():
pub = rospy.Publisher('to', Int16, queue_size=10)
rospy.init_node('talker1')
r = rospy.Rate(1) # 1hz
while not rospy.is_shutdown():
value=random.randint(0, 100)
print(value)
pub.publish(value)
r.sleep()
if __name__ == '__main__':
try:
ty()
except rospy.ROSInterruptException:
pass
the subscriber code:
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import Int16
def cb(x):
rospy.loginfo(x+2)
def listener():
# In ROS, nodes are uniquely named. If two nodes with the same
# node are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("to", Int16, cb)
rospy.spin()
if __name__ == '__main__':
listener()
i got this error :
TypeError: unsupported operand type(s) for +: 'Int16' and 'int'
how can i solve this problem