ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

'utf-8' codec can't decode byte 0x80 in position 14: invalid start byte

asked 2021-05-26 10:27:22 -0600

Daniel Robotics gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-31 04:46:22 -0600

Daniel Robotics gravatar image

updated 2021-05-31 04:48:03 -0600

So apparently the issue is due to float and double format not being equivalent in the two programming languages. An easy workaround, is to use Numpy's framework or to be more explicit, their QyObjects, they support easy transparent conversion of float/double arrays and seem to be efficient to decode aswell.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-05-26 10:11:52 -0600

Seen: 1,803 times

Last updated: May 31 '21