Home | Tutorials | Wiki | Issues
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Publisher in system plugin ?

Hello,

How to send a message from a system plugin to a model plugin. I tried this code but it doesn't work:

I want to send arguments to the model plugin. And I run this plugin in server side.

#include <gazebo/math/Rand.hh>
#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <iostream>

using namespace std;
namespace gazebo
{
  typedef const boost::shared_ptr<const msgs::Vector2d> VectorTwoDPtr;

  class CommandLine : public SystemPlugin
  {
    public: void Load(int argc, char ** argv)
    {
      for(int i =0; i<argc; i++)// I want to send the arguments to the model plugin
        cout << argv[i] << endl;
      this->connections.push_back( event::Events::ConnectPreRender( boost::bind(&CommandLine::Update, this)));
     }

private: void Init()
{
  transport::NodePtr nodePub = transport::NodePtr(new transport::Node());
  nodePub->Init();
  transport::PublisherPtr  publisher = nodePub->Advertise<msgs::Vector2d>("~/robotName");

  math::Vector2d vect( 2, 1);   
  msgs::Vector2d msg;
  msgs::Set(&msg, vect);
  publisher->Publish(msg);
}
private: void Update()
{
  // the onUpdate don't work 
}
private: std::vector<event::ConnectionPtr> connections;
  };
  GZ_REGISTER_SYSTEM_PLUGIN(CommandLine) 
}

THANK YOU !

Publisher in send arguments from system plugin to model plugin ?

Hello,

How to send a message from a system plugin to a model plugin. I tried this code but it doesn't work:

I want to send arguments to the model plugin. And I run this plugin in server side.

#include <gazebo/math/Rand.hh>
#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <iostream>

using namespace std;
namespace gazebo
{
  typedef const boost::shared_ptr<const msgs::Vector2d> VectorTwoDPtr;

  class CommandLine : public SystemPlugin
  {
    public: void Load(int argc, char ** argv)
    {
      for(int i =0; i<argc; i++)// I want to send the arguments to the model plugin
        cout << argv[i] << endl;
      this->connections.push_back( event::Events::ConnectPreRender( boost::bind(&CommandLine::Update, this)));
     }

private: void Init()
{
  transport::NodePtr nodePub = transport::NodePtr(new transport::Node());
  nodePub->Init();
  transport::PublisherPtr  publisher = nodePub->Advertise<msgs::Vector2d>("~/robotName");

  math::Vector2d vect( 2, 1);   
  msgs::Vector2d msg;
  msgs::Set(&msg, vect);
  publisher->Publish(msg);
}
private: void Update()
{
  // the onUpdate don't work 
}
private: std::vector<event::ConnectionPtr> connections;
  };
  GZ_REGISTER_SYSTEM_PLUGIN(CommandLine) 
}

THANK YOU !