Publishing and subscribing C structures?
So I want to publish C structure. I have my_pkg.msg
int32 a
float32 b
And C structure:
namespace my {
struct __atribute((packed)) my_pkg {
int a;
float b;
};
}
And then I do serialization like in this link
namespace ros
{
namespace message_traits
{
template<> struct IsFixedSize<my::my_pkg> : public TrueType {};
template<> struct IsSimple<my::my_pkg> : public TrueType {};
template<>
struct MD5Sum<my::my_pkg>
{
static const char* value()
{
return MD5Sum<my::my_pkg>::value();
}
static const char* value(const my::my_pkg& m)
{
return MD5Sum<my::my_pkg>::value(m);
}
};
template<>
struct DataType<my::my_pkg>
{
static const char* value()
{
return DataType<my::my_pkg>::value();
}
static const char* value(const my::my_pkg& m)
{
return DataType<my::header_s>::value(m);
}
};
template<>
struct Definition<my::my_pkg>
{
static const char* value()
{
return Definition<my::my_pkg>::value();
}
static const char* value(const my::my_pkg& m)
{
return Definition<my::my_pkg>::value(m);
}
};
} // namespace message_traits
namespace serialization
{
template<>
struct Serializer<my::my_pkg>
{
template<typename Stream, typename T>
inline static void allInOne(Stream& stream, T item)
{
stream.next(item.a);
stream.next(item.b);
}
ROS_DECLARE_ALLINONE_SERIALIZER;
};
} // namespace serialization
} // namespace ros
And I want to publish my message so I do
ros::Publisher pub = n.advertise<my::my_pkg>("test", 1);
And I get Segmentation Fault at this level. Can someone has idea what I'm doing wrong?
EDIT: gdb
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff1a76700 (LWP 10115)]
[New Thread 0x7ffff1275700 (LWP 10116)]
[New Thread 0x7ffff0a74700 (LWP 10117)]
[New Thread 0x7fffebfff700 (LWP 10122)]
Thread 1 "example" received signal SIGSEGV, Segmentation fault.
0x000055555555b3b9 in ros::message_traits::MD5Sum<my::my_pkg>::value() ()
So what did
gdb
tell you about theSEGFAULT
?How can I use gdb with roscpp to debug code?
wiki/roslaunch - Roslaunch Nodes in Valgrind or GDB.
(we're here to help, but a quick google (
ros gdb
) returns this as one of the first results for me)I've never run roscpp nodes by roslaunch so it takes me a while.
If you're starting individual nodes, you can also just do something like
gdb -ex run --args /path/to/your/node
. In a regular Catkin workspace, that could becatkin_ws/devel/lib/$pkg_name/$binary
.Thanks, that was really helpful. Here is output:
Thread 1 "example" received signal SIGSEGV, Segmentation fault. 0x000055555555b3b9 in ros::message_traits::MD5Sum<my::my_pkg>::value() ()
Please edit your OP with the new info.
Note that backtraces are really only useful if you compile your program in debug mode.
And the full backtrace is also preferable over just a few lines.
Has someone an idea what i'm doing wrong?