In publish raise ROSSerializationException(str(e))
In my package that I created, there are 3 nodes currently. I also generate a custom message which is "AnchorScan".
First node does some stuff and only publishes from /IPS
topic.
Second node subscribes to the /IPS
topic, takes the information, do some stuff and publishes another information from /selectedAnchors
topic.
Until now everything works fine. But;
Third node subscribes to the /selectedAnchors
topic and does some calculations however does not publish anything from /position
topic.
After I run this command on terminal
rostopic echo /position
I received that kind of exception.
I tried to change the queue size, rate etc. but nothing worked fine.
All raised error is here:
Traceback (most recent call last):
File /home/user/my_ws/src/my_pkg/src/pkg_name/3rd_node.py", line 366, in <module>
position_pub_sub()
File "/home/user/my_ws/src/my_pkg/src/pkg_name/3rd_node.py", line 324, in position_pub_sub
pub.publish(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 886, in publish
raise ROSSerializationException(str(e))
rospy.exceptions.ROSSerializationException: field x must be a list or tuple type
Thank you in advance for any help!!!
https://github.com/ros/ros_comm/issue...
Edit:
Here is my code:
#!/usr/bin/env python
# license removed for brevity
import rospy
from math import sqrt
from random import randint
from random import uniform
from collections import OrderedDict
from std_msgs.msg import String
from my_pkg.msg import AnchorScan
class CalcPos2D3AIte:
def __init__(self, SX, SY, SZ, AX, AY, AZ, BX, BY, BZ, TZ, das, dbs):
## DO STUFF
## DO STUFF
## DO STUFF
pre_TY = (N2 -(M21*N1/M11))/(M22-(M21*M12/M11))
pre_TX = ((-1*M21*N1/M11) + (M21*M12/M11)*pre_TY)/(-1*M21)
TX = pre_TX
TY = pre_TY
self.TX_cm = int(TX*100)
self.TY_cm = int(TY*100)
self.TZ_cm = int(TZ*100)
def position_pub_sub():
rospy.init_node('test2_positioning_node', anonymous=True)
rospy.Subscriber('selectedAnchors', AnchorScan, callback)
pub = rospy.Publisher('position', AnchorScan, queue_size=2)
rate = rospy.Rate(10)
while not rospy.is_shutdown():
if var_control:
msg = AnchorScan()
tagpos = CalcPos2D3AIte(SX, SY, SZ, AX, AY, AZ, BX, BY, BZ, TZ,das, dbs)
msg.x = tagpos.TX_cm
msg.y = tagpos.TY_cm
msg.z = tagpos.TZ_cm
pub.publish(msg)
pub_info = "\nTX = %f \nTY = %f \nTZ = %f \n\n" % (tagpos.TX_cm,tagpos.TY_cm,tagpos.TZ_cm)
rospy.loginfo(pub_info)
rate.sleep()
Here is my AnchorScan.msg what it looks like:
# Timestamp
#Header header
int32[] AnchorID
float64[] x
float64[] y
float64[] z
float64 distance
# according to "S"
float64[] DDOA_of_anchors
The error you show is most likely caused by a mistake in the code of your "third node". Without you showing us the code, we cannot help you.
You don't show any
import
statements. AreN2
and friendsnumpy
vectors/matrices/arrays?Edit: the error message shows:
which line in the code you show is line 324? Where is
position_pub_sub
?And: please include the definition of the
AnchorScan
message. I would also recommend to add something likeprint ("type of tagpos.TX_cm: {}".format(type(tagpos.TX_cm))
right before the line where the script fails. That would let you check what the type if oftagpos.TX_cm
.I added the my code snippet. There is
position_pub_sub
function here and I publish and subscribe in this function. Also line 324 indicates the;in
position_pub_sub
function.