Rosserial - combining two message custom class
Hi, I want to create a custom message to send diagnostics info from an Arduino to ros. The message structure is the following:
motore.msg : bool heartbeat int32 speedRPM float32 wheel_speed float32 voltage float32 current int32 torque int32 temperature int32 HSinkTemp int32 statoCtl
Then diag.msg
motore FrontLeft motore FrontRight motore BackLeft motore BackRight
First test: I put the two messages in the same msg directory of package. Compiled fine, the generate the .h files in ros_lib. But when I compile the Arduino sketch I get tis error: error: invalid use of incomplete type 'class diag::diag' typedef diag::motore _FrontLeft_type; ^~~~~~
the class definition (diag):
namespace diag {
class diag : public ros::Msg { public: typedef diag::motore _FrontLeft_type; _FrontLeft_type FrontLeft; typedef diag::motore _FrontRight_type; _FrontRight_type FrontRight; typedef diag::motore _BackLeft_type; _BackLeft_type BackLeft; typedef diag::motore _BackRight_type; _BackRight_type BackRight;
diag():
FrontLeft(),
FrontRight(),
BackLeft(),
BackRight()
{
}
.... and motore.h: ...
namespace diag {
class motore : public ros::Msg { public: typedef bool _heartbeat_type; _heartbeat_type heartbeat; typedef int32_t _speedRPM_type; _speedRPM_type speedRPM; typedef float _wheel_speed_type; _wheel_speed_type wheel_speed; typedef float _voltage_type; _voltage_type voltage; typedef float _current_type; _current_type current; typedef int32_t _torque_type; _torque_type torque; typedef int32_t _temperature_type; _temperature_type temperature; typedef int32_t _HSinkTemp_type; _HSinkTemp_type HSinkTemp; typedef int32_t _statoCtl_type; _statoCtl_type statoCtl;
motore():
heartbeat(0),
speedRPM(0),
wheel_speed(0),
voltage(0),
current(0),
torque(0),
temperature(0),
HSinkTemp(0),
statoCtl(0)
{
}
The only way to compile the code in Arduino is to put the motor class into a different namespace: .... namespace motore {
class motore : public ros::Msg { public: typedef bool _heartbeat_type; _heartbeat_type heartbeat; typedef int32_t _speedRPM_type; _speedRPM_type speedRPM; typedef float _wheel_speed_type; _wheel_speed_type wheel_speed; typedef float _voltage_type; _voltage_type voltage; typedef float _current_type; _current_type current; typedef int32_t _torque_type; _torque_type torque; typedef int32_t _temperature_type; _temperature_type temperature; typedef int32_t _HSinkTemp_type; _HSinkTemp_type HSinkTemp; typedef int32_t _statoCtl_type; _statoCtl_type statoCtl;
motore():
heartbeat(0),
speedRPM(0),
wheel_speed(0),
voltage(0),
current(0),
torque(0),
temperature(0),
HSinkTemp(0),
statoCtl(0)
{
}
class diag : public ros::Msg { public: typedef motore::motore _FrontLeft_type; _FrontLeft_type FrontLeft; typedef motore::motore _FrontRight_type; _FrontRight_type FrontRight; typedef motore::motore _BackLeft_type; _BackLeft_type BackLeft; typedef motore::motore _BackRight_type; _BackRight_type BackRight;
diag():
FrontLeft(),
FrontRight(),
BackLeft(),
BackRight()
{
}
....
Now when I connect the Arduino to Rosserial (python) I get this error: Traceback (most recent call last): File "/opt/ros/melodic/lib/rosserial_python/serial_node.py", line 89, in <module> client.run() File "/opt/ros/melodic/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 540, in run self.callbackstopic_id File "/opt/ros/melodic/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 110, in handlePacket m = self.message() File "/home/maxdod/ros/diagnostica_ws/devel/lib/python2.7/dist-packages/diag/msg/_diag.py", line 61, in __init__ self.FrontLeft = diag.msg.motore() AttributeError: type object 'diag' has no attribute 'msg'
It seems that the message generated on ros side (melodic) create a msg field that is not defined in any place! What am I missing ? Thanks Massimo
Creating custom messages for ros-serial is a multi-step process. 1) you define the ros .msg files and add them to CMakeLists.txt, 2) you compile the messages using catkin_make, 3) you generate the matching non-ros .h files for use on the ros-serial client side.
Have you done all 3 of these steps? Note: it is not recommended that you try to handcraft your own msg class for motore.
Please use the button to move your "answer" into a comment (like this one), or edit your question and copy/paste it there. You should only use answer section if you are providing an actual answer to the question.
Regarding this problem: did your message definition files compile in catkin_make without error? The content of your
diag.msg
file looks wrong -- I believe you need to specify the ros-package names when you use another msg type, like this:std_msgs/Header header
Thanks Mike ! following your suggestion I solved my problem: I modified diag.msg motore/motore FrontLeft motore/motore FrontRight motore/motore BackLeft motore/motore BackRight
rostopic echo now is ok ! FrontLeft: heartbeat: False speedRPM: 10 wheel_speed: 2.45000004768 voltage: 26.0 current: 2.0 torque: 30 temperature: 27 HSinkTemp: 28 statoCtl: 0 FrontRight: heartbeat: False speedRPM: 0 wheel_speed: 0.0 voltage: 0.0 current: 0.0 torque: 0 temperature: 0 HSinkTemp: 0 statoCtl: 0 BackLeft: heartbeat: False speedRPM: 0 wheel_speed: 0.0 voltage: 0.0 current: 0.0 torque: 0 temperature: 0 HSinkTemp: 0 statoCtl: 0 BackRight: heartbeat: False speedRPM: 0 wheel_speed: 0.0 voltage: 0.0 current: 0.0 torque: 0 temperature: 0 HSinkTemp: 0 statoCtl: 0
Massimo
Good, I'm glad it's working now. Please click the check mark in the round circle (it turns green) to indicate this solution worked for you.