shupx / swarm_ros_bridge

A lightweight middle interface that enables specified ROS message transmission among swarm robots through socket communication

Home Page:https://wiki.ros.org/swarm_ros_bridge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New ROS message error

AshwinDisa opened this issue · comments

Hello,

I'm trying to add the sensor_msgs/NavSatFix message to communicate GPS data between 2 nodes. Working well for other message types (pose and cmd_vel).

Getting the folllowing error:

[FATAL] [1681032161.446449717]: Invalid ROS msg_type "sensor_msgs/NavSatFix" in configuration!
[swarm_bridge_node-2] process has died [pid 2605, exit code 1, cmd /home/ubuntu/catkin_ws/devel/lib/swarm_ros_bridge/bridge_node __name:=swarm_bridge_node __log:=/home/ubuntu/.ros/log/12ceba90-d6b8-11ed-b861-f7029b9ccf7b/swarm_bridge_node-2.log].
log file: /home/ubuntu/.ros/log/12ceba90-d6b8-11ed-b861-f7029b9ccf7b/swarm_bridge_node-2*.log

In ros_topic.yaml
I changed the topic name and msg_type from sensor_msgs/Imu to sensor_msgs/NavSatFix for both send topics and recv topics.

ros_sub_pub.hpp looks like this
#include <sensor_msgs/NavSatFix.h>
#define MSG_TYPE1 "sensor_msgs/NavSatFix"
#define MSG_CLASS1 sensor_msgs::NavSatFix

catkin_make not needed as sensor_msgs is already present in CMakeLists.txt

Any idea where I might be going wrong?
Thanks

You should rebuild the package by catkin_make for any modification.

catkin_make didn't solve the issue.

I can not figure out the bug according to your description. Maybe you should list your ros_sub_pub.hpp.

/**

  • @file ros_sub_pub.hpp
  • @author Peixuan Shu (shupeixuan@qq.com)
  • @brief Header file for different ROS message type.
  • Core Idea: modify the macros about MSG_TYPEx and MSG_CLASSx,
  • it will generate template functions for different ros message types.
  • Remember to add the dependent package in find_package() of ../CMakeLists.txt
  • Note: the sub_cb() and deserialize_pub() are only declared here,
  • you should define them in you .cpp file according to your need.
  • @Version 1.0
  • @Date 2023-01-01
  • @license BSD 3-Clause License
  • @copyright (c) 2023, Peixuan Shu
  • All rights reserved.

*/

#ifndef ROS_SUB_PUB
#define ROS_SUB_PUB
#include <ros/ros.h>

#include <sensor_msgs/NavSatFix.h>
#define MSG_TYPE1 "sensor_msgs/NavSatFix"
#define MSG_CLASS1 sensor_msgs::NavSatFix

#include <geometry_msgs/Twist.h>
#define MSG_TYPE2 "geometry_msgs/Twist"
#define MSG_CLASS2 geometry_msgs::Twist

#include <std_msgs/String.h>
#define MSG_TYPE3 "std_msgs/String"
#define MSG_CLASS3 std_msgs::String

#include <geometry_msgs/Pose.h>
#define MSG_TYPE4 "geometry_msgs/Pose"
#define MSG_CLASS4 geometry_msgs::Pose

// ......

// #include <xxx/yy.h>
// #define MSG_TYPE10 "xxx/yy"
// #define MSG_CLASS10 xxx::yy

define SUB_MAX 50 // max number of subscriber callbacks

template <typename T, int i>
void sub_cb(const T &msg);

template
void (*sub_callbacks[])(const T &);

template
ros::Subscriber nh_sub(std::string topic_name, ros::NodeHandle nh, int i);

ros::Subscriber topic_subscriber(std::string topic_name, std::string msg_type, ros::NodeHandle nh, int i);

ros::Publisher topic_publisher(std::string topic_name, std::string msg_type, ros::NodeHandle nh);

template
void deserialize_pub(uint8_t* buffer_ptr, size_t msg_size, int i);

void deserialize_publish(uint8_t* buffer_ptr, size_t msg_size, std::string msg_type, int i);

template
void (*sub_callbacks[])(const T &)=
{
sub_cb<T,0>, sub_cb<T,1>, sub_cb<T,2>, sub_cb<T,3>, sub_cb<T,4>,
sub_cb<T,5>, sub_cb<T,6>, sub_cb<T,7>, sub_cb<T,8>, sub_cb<T,9>,
sub_cb<T,10>, sub_cb<T,11>, sub_cb<T,12>, sub_cb<T,13>, sub_cb<T,14>,
sub_cb<T,15>, sub_cb<T,16>, sub_cb<T,17>, sub_cb<T,18>, sub_cb<T,19>,
sub_cb<T,20>, sub_cb<T,21>, sub_cb<T,22>, sub_cb<T,23>, sub_cb<T,24>,
sub_cb<T,25>, sub_cb<T,26>, sub_cb<T,27>, sub_cb<T,28>, sub_cb<T,29>,
sub_cb<T,30>, sub_cb<T,31>, sub_cb<T,32>, sub_cb<T,33>, sub_cb<T,34>,
sub_cb<T,35>, sub_cb<T,36>, sub_cb<T,37>, sub_cb<T,38>, sub_cb<T,39>,
sub_cb<T,40>, sub_cb<T,41>, sub_cb<T,42>, sub_cb<T,43>, sub_cb<T,44>,
sub_cb<T,45>, sub_cb<T,46>, sub_cb<T,47>, sub_cb<T,48>, sub_cb<T,49>
};

template
ros::Subscriber nh_sub(std::string topic_name, ros::NodeHandle nh, int i)
{
return nh.subscribe(topic_name, 10, sub_callbacks[i], ros::TransportHints().tcpNoDelay());
}

ros::Subscriber topic_subscriber(std::string topic_name, std::string msg_type, ros::NodeHandle nh, int i)
{
#ifdef MSG_TYPE1
if (msg_type == MSG_TYPE1)
return nh_sub<MSG_CLASS1>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE2
if (msg_type == MSG_TYPE2)
return nh_sub<MSG_CLASS2>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE3
if (msg_type == MSG_TYPE3)
return nh_sub<MSG_CLASS3>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE4
if (msg_type == MSG_TYPE4)
return nh_sub<MSG_CLASS4>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE5
if (msg_type == MSG_TYPE5)
return nh_sub<MSG_CLASS5>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE6
if (msg_type == MSG_TYPE6)
return nh_sub<MSG_CLASS6>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE7
if (msg_type == MSG_TYPE7)
return nh_sub<MSG_CLASS7>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE8
if (msg_type == MSG_TYPE8)
return nh_sub<MSG_CLASS8>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE9
if (msg_type == MSG_TYPE9)
return nh_sub<MSG_CLASS9>(topic_name, nh, i);
#endif
#ifdef MSG_TYPE10
if (msg_type == MSG_TYPE10)
return nh_sub<MSG_CLASS10>(topic_name, nh, i);
#endif
ROS_FATAL("Invalid ROS msg_type "%s" in configuration!", msg_type.c_str());
exit(1);
}

ros::Publisher topic_publisher(std::string topic_name, std::string msg_type, ros::NodeHandle nh)
{
#ifdef MSG_TYPE1
if (msg_type == MSG_TYPE1)
return nh.advertise<MSG_CLASS1>(topic_name, 10);
#endif
#ifdef MSG_TYPE2
if (msg_type == MSG_TYPE2)
return nh.advertise<MSG_CLASS2>(topic_name, 10);
#endif
#ifdef MSG_TYPE3
if (msg_type == MSG_TYPE3)
return nh.advertise<MSG_CLASS3>(topic_name, 10);
#endif
#ifdef MSG_TYPE4
if (msg_type == MSG_TYPE4)
return nh.advertise<MSG_CLASS4>(topic_name, 10);
#endif
#ifdef MSG_TYPE5
if (msg_type == MSG_TYPE5)
return nh.advertise<MSG_CLASS5>(topic_name, 10);
#endif
#ifdef MSG_TYPE6
if (msg_type == MSG_TYPE6)
return nh.advertise<MSG_CLASS6>(topic_name, 10);
#endif
#ifdef MSG_TYPE7
if (msg_type == MSG_TYPE7)
return nh.advertise<MSG_CLASS7>(topic_name, 10);
#endif
#ifdef MSG_TYPE8
if (msg_type == MSG_TYPE8)
return nh.advertise<MSG_CLASS8>(topic_name, 10);
#endif
#ifdef MSG_TYPE9
if (msg_type == MSG_TYPE9)
return nh.advertise<MSG_CLASS9>(topic_name, 10);
#endif
#ifdef MSG_TYPE10
if (msg_type == MSG_TYPE10)
return nh.advertise<MSG_CLASS10>(topic_name, 10);
#endif
ROS_FATAL("Invalid ROS msg_type "%s" in configuration!", msg_type.c_str());
exit(1);
}

void deserialize_publish(uint8_t* buffer_ptr, size_t msg_size, std::string msg_type, int i)
{
#ifdef MSG_TYPE1
if (msg_type == MSG_TYPE1)
return deserialize_pub<MSG_CLASS1>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE2
if (msg_type == MSG_TYPE2)
return deserialize_pub<MSG_CLASS2>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE3
if (msg_type == MSG_TYPE3)
return deserialize_pub<MSG_CLASS3>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE4
if (msg_type == MSG_TYPE4)
return deserialize_pub<MSG_CLASS4>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE5
if (msg_type == MSG_TYPE5)
return deserialize_pub<MSG_CLASS5>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE6
if (msg_type == MSG_TYPE6)
return deserialize_pub<MSG_CLASS6>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE7
if (msg_type == MSG_TYPE7)
return deserialize_pub<MSG_CLASS7>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE8
if (msg_type == MSG_TYPE8)
return deserialize_pub<MSG_CLASS8>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE9
if (msg_type == MSG_TYPE9)
return deserialize_pub<MSG_CLASS9>(buffer_ptr, msg_size, i);
#endif
#ifdef MSG_TYPE10
if (msg_type == MSG_TYPE10)
return deserialize_pub<MSG_CLASS10>(buffer_ptr, msg_size, i);
#endif
ROS_FATAL("Invalid ROS msg_type "%s" in configuration!", msg_type.c_str());
exit(1);
}

#endif

There should not be problem if you follow the instruction strictly in all steps and rebuild the package. There might be some slight mistakes you have made that were ignored. Check carefully and wish you fix this issue

Erasing /devel and /build folders and rebuilding the package solved my issue. Thanks!