Ask Your Question
0

Rosserial - combining two message custom class

asked 2021-08-06 02:37:15 -0500

Maxdod gravatar image

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

edit retag flag offensive close merge delete

Comments

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-06 17:43:36 -0500 )edit

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

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-07 06:41:19 -0500 )edit

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

Maxdod gravatar image Maxdod  ( 2021-08-07 09:34:36 -0500 )edit

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-07 11:26:32 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2021-08-07 11:23:42 -0500

Mike Scheutzow gravatar image

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 name when you use another msg type, like this:

std_msgs/Header header
edit flag offensive delete link more
0

answered 2021-08-07 02:22:39 -0500

Maxdod gravatar image

Thanks Mike. I followed these steps: 1) create a package containing the two msg: diag.msg and motore.msg 2) catkin_make of the package 3) generate ros_lib libraries for the Arduino messages 4) copied the diagnostics.h and motore.h to Arduino libraries 5) created a test sketch:

include <ros.h> include <ros node_handle.h=""> include <diag motore.h=""> include <diag diag.h="">

diag::diag diag_msg; diag::motore motor_msg; ros::NodeHandle nh; ros::Publisher diag_pub("diagnostic", &diag_msg); void setup() { // put your setup code here, to run once:

// ROS Setup nh.initNode(); nh.advertise(diag_pub); while(!nh.connected()) nh.spinOnce(); }

void loop() { // put your main code here, to run repeatedly: motor_msg.heartbeat= false; motor_msg.speedRPM= 10; motor_msg.wheel_speed=2.45; motor_msg.voltage= 26.0; motor_msg.current= 2.0; motor_msg.torque=30; motor_msg.temperature= 27; motor_msg.HSinkTemp= 28; diag_msg.FrontLeft = motor_msg; //diag_msg.fl.statoCtl= 8;

diag_pub.publish(&diag_msg); delay (5000); nh.spinOnce(); }

As I told, if I try to compile the sketch I get the error:

Users/mdore/Dropbox/Il mio Mac (MacBook-Pro-di-Massimo.local)/Documents/Arduino/libraries/Rosserial_Arduino_Library/src/diag/diag.h:16:21: error: invalid use of incomplete type 'class diag::diag' typedef diag::motore _FrontLeft_type; ^~~~~~ /Users/mdore/Dropbox/Il mio Mac (MacBook-Pro-di-Massimo.local)/Documents/Arduino/libraries/Rosserial_Arduino_Library/src/diag/diag.h:13:9: note: definition of 'class diag::diag' is not complete until the closing brace class diag : public ros::Msg ^~~~ /Users/mdore/Dropbox/Il mio Mac (MacBook-Pro-di-Massimo.local)/Documents/Arduino/libraries/Rosserial_Arduino_Library/src/diag/diag.h:17:7: error: '_FrontLeft_type' does not name a type _FrontLeft_type FrontLeft; ^~~~~~~~~~~~~~~

-------------------------- Second try:

1) I created two packages diag and motore on Ros: diagnostica_ws/src/diag and diagnostica_ws/src/motor 2) catkin_make 3) generate ros_lib libraries 4) copied diag.h on diag/diag.h and motore.h in motore/motore.h 5) compile the sketch changing the class name:

diag::diag diag_msg; motore::motore motor_msg; ros::NodeHandle nh; ros::Publisher diag_pub("diagnostic", &diag_msg); void setup() { // put your setup code here, to run once:

// ROS Setup nh.initNode(); nh.advertise(diag_pub); while(!nh.connected()) nh.spinOnce(); }

void loop() { // put your main code here, to run repeatedly: motor_msg.heartbeat= false; motor_msg.speedRPM= 10; motor_msg.wheel_speed=2.45; motor_msg.voltage= 26.0; motor_msg.current= 2.0; motor_msg.torque=30; motor_msg.temperature= 27; motor_msg.HSinkTemp= 28; diag_msg.FrontLeft = motor_msg; //diag_msg.fl.statoCtl= 8;

diag_pub.publish(&diag_msg); delay (5000); nh.spinOnce(); } now the compilation is fine, but the problem is on ros side, as I told you. ROS melodic runs on a x64 cpu with ubuntu 18.04lts

Probably I have to solve the compilation error on Arduino (Arduino due processor). it should be the same relationship as , fo example, Pose and Point but in my case I do not understand the problem. Thanks Massimo

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-08-06 02:37:15 -0500

Seen: 60 times

Last updated: Aug 07 '21