'utf-8' codec can't decode byte 0x80 in position 14: invalid start byte
I am currently occupied with implementing a python-wrapper for a ROS-package, but I am stuck at serialization or rather the decoding part of it.
I recieve a somewhat nasty error message in python, when receiving a message type of "Float64MUltiArray", however it works as a charm with "Int64MultiArray". The error message is of type: " 'utf-8' codec can't decode byte 0x80 in position 14: invalid start byte ", note that the byte position depends on the data I put into "Float64MUltiArray".
Now to some relevant code in CPP and Python (in addition, I have followed the tutorial at: ROS/Tutorials)
std::string pose_euler(const std::string& q_)
{
std_msgs::Float64MultiArray q = from_python<std_msgs::Float64MultiArray>(q_);
std_msgs::Float64MultiArray msg = kdl_interface::car_euler(q);
return to_python<std_msgs::Float64MultiArray>(msg);
}
std::string to_python(const std_msgs::Float64MultiArray& msg)
{
size_t serial_size = ros::serialization::serializationLength(msg);
boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);
ros::serialization::OStream stream(buffer.get(), serial_size);
ros::serialization::serialize(stream, msg);
std::string str_msg;
str_msg.reserve(serial_size);
for (size_t i = 0; i < serial_size; ++i)
{
str_msg.push_back(buffer[i]);
}
return str_msg;
}
BOOST_PYTHON_MODULE(_kdl_interface_cpp)
{
def("pose_euler", pose_euler);
}
def pose_euler(self, q_e):
"""
Return a cartesian pose given the joint_angles
"""
if not isinstance(q_e, Float64MultiArray):
rospy.ROSException('Argument 1 is not a std_msgs/Float64MultiArray')
q_e = self._to_cpp(q_e)
msg = self.pose_euler(q_e) /* The error occurs here, when returning */
...
def _to_cpp(self, msg):
"""
Return a serialized string from a ROS message
"""
buf = BytesIO()
msg.serialize(buf)
return buf.getvalue()
I have simplified the code slightly as to_python is a template function in my code, which takes arbitrary message types (this way I could try std_msgs::Int64MultiArray).
And to an ending, I think the problem is caused by floating numbers, but I could be wrong.
Best Regards Daniel