39 #include <pybind11/pybind11.h>
40 #include <ros/duration.h>
41 #include <ros/serialization.h>
49 PYBIND11_EXPORT pybind11::object
createMessage(
const std::string& ros_msg_name);
50 PYBIND11_EXPORT
bool convertible(
const pybind11::handle& h,
const char* ros_msg_name);
64 static handle
cast(T&& src, return_value_policy , handle )
66 return PyFloat_FromDouble(src.toSec());
70 bool load(handle src,
bool convert)
72 if (hasattr(src,
"to_sec"))
74 value = T(src.attr(
"to_sec")().cast<
double>());
78 value = T(src.cast<
double>());
100 struct type_caster<T, enable_if_t<ros::message_traits::IsMessage<T>::value>>
103 static handle
cast(
const T& src, return_value_policy , handle )
106 std::size_t size = ros::serialization::serializationLength(src);
107 object pbuffer = reinterpret_steal<object>(PyBytes_FromStringAndSize(
nullptr, size));
108 ros::serialization::OStream stream(
reinterpret_cast<uint8_t*
>(PyBytes_AsString(pbuffer.ptr())), size);
109 ros::serialization::serialize(stream, src);
112 msg.attr(
"deserialize")(pbuffer);
113 return msg.release();
122 object pstream = module::import(
"io").attr(
"BytesIO")();
123 src.attr(
"serialize")(pstream);
124 object pbuffer = pstream.attr(
"getvalue")();
126 char* cbuffer =
nullptr;
128 PyBytes_AsStringAndSize(pbuffer.ptr(), &cbuffer, &size);
129 ros::serialization::IStream cstream(
const_cast<uint8_t*
>(
reinterpret_cast<const uint8_t*
>(cbuffer)), size);
130 ros::serialization::deserialize(cstream, value);
PYBIND11_EXPORT pybind11::object createMessage(const std::string &ros_msg_name)
PYBIND11_EXPORT bool convertible(const pybind11::handle &h, const char *ros_msg_name)
Main namespace for MoveIt.
Convert ros::Duration / ros::WallDuration into a float.
bool load(handle src, bool convert)
static handle cast(T &&src, return_value_policy, handle)
PYBIND11_TYPE_CASTER(T, _("Duration"))
PYBIND11_TYPE_CASTER(T, _< T >())
static handle cast(const T &src, return_value_policy, handle)
bool load(handle src, bool)