Gazebo | Ignition | Community
Ask Your Question
1

unable to parse message of type [...] error in custom message

asked 2015-01-13 13:29:25 -0500

djou07 gravatar image

updated 2015-01-13 13:33:12 -0500

Hello,

I am trying to send a custom message from a model plugin to another model plugin. The two plugins are linked to same model. The code compiles well, but when I run gazebo GUI it shows me this error in topic visualisation:

unable to parse message of type[robot_brain_fitness_msgs.msgs.robotDataRequest]

I do not why, can you guys help me...thanks in advance :)

here is the source code


in subfolder msgs

/msgs/robot_brain_fitness.proto

package robot_brain_fitness_msgs.msgs;
message robotDataRequest
{
   required double fitness = 1; 
}

/msgs/CMakeLists.txt

find_package(Protobuf REQUIRED)
set(PROTOBUF_IMPORT_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
  if(ITR MATCHES ".*gazebo-[0-9.]+$")
    set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
  endif()
endforeach()
set (msgs
  robot_brain_fitness.proto
  ${PROTOBUF_IMPORT_DIRS}/vector2d.proto
  ${PROTOBUF_IMPORT_DIRS}/header.proto
  ${PROTOBUF_IMPORT_DIRS}/time.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(robot_brain_fitness_msgs SHARED ${PROTO_SRCS})
target_link_libraries(robot_brain_fitness_msgs ${PROTOBUF_LIBRARY})

in root folder

plugin1.cc

#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>
#include <iostream>
#include "robot_brain_fitness.pb.h"

namespace gazebo
{   

typedef const boost::shared_ptr
    <const robot_brain_fitness_msgs::msgs::robotDataRequest>   robotDataRequestPtr;


    class ReceiveMsgPlugin : public ModelPlugin
    {

    private: event::ConnectionPtr updateConnection;
             physics::ModelPtr model;
             transport::SubscriberPtr subscriber;
             transport::NodePtr node;

    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) 
    {    
        //subscriber = node->Subscribe("~/robotData", &ReceiveMsgPlugin::create, this);

        this->updateConnection = event::Events::ConnectWorldUpdateBegin
            ( boost::bind(&ReceiveMsgPlugin::OnUpdate, this, _1));
    }
    /*public: void create(robotDataRequestPtr &msg)
    {
        std::cout << "fitness : " <<msg->fitness() << "\n";

    }*/     
    public: void OnUpdate(const common::UpdateInfo & /*_info*/)
    {

    }
};
 GZ_REGISTER_MODEL_PLUGIN(ReceiveMsgPlugin)
 }

plugin2.cc

#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>
#include <iostream>
#include "robot_brain_fitness.pb.h"

namespace gazebo
{   
 class SendMsgPlugin : public ModelPlugin
 {
private: event::ConnectionPtr updateConnection;
         physics::ModelPtr model;
         transport::PublisherPtr publisher;
         transport::NodePtr node;

   public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) 
   {
    this->model = _parent;

     node = transport::NodePtr(new transport::Node());

     node->Init(this->model->GetWorld()->GetName());

     this->updateConnection = event::Events::ConnectWorldUpdateBegin
        ( boost::bind(&SendMsgPlugin::OnUpdate, this, _1));

   }

    public: void OnUpdate(const common::UpdateInfo & /*_info*/)
    {
        robot_brain_fitness_msgs::msgs::robotDataRequest request;
        request.set_fitness(10);
        publisher = node->Advertise
          <robot_brain_fitness_msgs::msgs::robotDataRequest>("~/robotData");
        publisher->Publish(request);
    }
};
GZ_REGISTER_MODEL_PLUGIN(SendMsgPlugin)  
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
FIND_PACKAGE( Boost 1.40 COMPONENTS system REQUIRED )
set (CMAKE_CXX_FLAGS "-g -Wall")

include (FindPkgConfig)
if (PKG_CONFIG_FOUND)
  pkg_check_modules(GAZEBO gazebo)
  pkg_check_modules(SDF sdformat)
endif()

include_directories(
  ${GAZEBO_INCLUDE_DIRS}
  ${CMAKE_CURRENT_BINARY_DIR}/msgs
  )
link_directories(${GAZEBO_LIBRARY_DIRS} ${SDF_LIBRARY_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/msgs)
add_subdirectory(msgs)

add_library(plugin1 SHARED plugin1.cc)
target_link_libraries(plugin1 robot_brain_fitness_msgs 
${Boost_LIBRARIES} ${GAZEBO_LIBRARIES} ${SDF_LIBRARIES})
add_dependencies(plugin1 robot_brain_fitness_msgs)

add_library(plugin2 SHARED plugin2.cc)
target_link_libraries(plugin2 robot_brain_fitness_msgs ${Boost_LIBRARIES}
${GAZEBO_LIBRARIES} ${SDF_LIBRARIES})
add_dependencies(plugin2 robot_brain_fitness_msgs)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-15 10:27:35 -0500

nkoenig gravatar image

The problem is that the Gazebo GUI doesn't know about your custom message, so it can't display it in the topic visualizer. There is no easy solution. If you want to quickly see the content of the message, you can print it to the terminal (or to a log file) in your plugin.

This problem will be fixed in Gazebo 6, when we update the transport library.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2015-01-13 13:29:25 -0500

Seen: 1,288 times

Last updated: Jan 15 '15