Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Plugin for WirelessTransmitter and WirelessReciever sensors

Hello, I need to modify the code of WirelessTransmitter sensor in order to use another propagation function. The first thing I tried is to create a pluggin for both WirelessReceiver and WirelessTranmitter sensors. I followed the tutorial: [http://gazebosim.org/tutorials?tut=contact_sensor#Introduction

The code for WirelessReceiverPlugin.hh is:

#ifndef _GAZEBO_WIRELESS_RECEIVER_PLUGIN_HH_
#define _GAZEBO_WIRELESS_RECEIVER_PLUGIN_HH_

#include <string>

#include "gazebo/gazebo.hh"
#include "gazebo/sensors/sensors.hh"

namespace gazebo
{
  /// \brief Plugin for a wireless receiver sensor.
  class WirelessReceiverPlugin : public SensorPlugin
  {
    /// \brief Constructor.
    public: WirelessReceiverPlugin();

    /// \brief Destructor.
    public: virtual ~WirelessReceiverPlugin();

    /// \brief Load the sensor plugin.
    /// \param[in] _sensor Pointer to the sensor that loaded this plugin.
    /// \param[in] _sdf SDF element that describes the plugin.
    public: virtual void Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf);

    /// \brief Callback that receives the wireless receiver sensor's update signal.
    private: virtual void OnUpdate();

    /// \brief Pointer to the contact sensor
    private: sensors::WirelessReceiverPtr parentSensor;

    /// \brief Connection that maintains a link between the contact sensor's
    /// updated signal and the OnUpdate callback.
    private: event::ConnectionPtr updateConnection;
  };
}
#endif

And WirelesReceiverPlugin.cc

#include "WirelessReceiverPlugin.hh"

using namespace gazebo;
GZ_REGISTER_SENSOR_PLUGIN(WirelessReceiverPlugin)

/////////////////////////////////////////////////
WirelessReceiverPlugin::WirelessReceiverPlugin() : SensorPlugin()
{
}

/////////////////////////////////////////////////
WirelessReceiverPlugin::~WirelessReceiverPlugin()
{
}

/////////////////////////////////////////////////
void WirelessReceiverPlugin::Load(sensors::SensorPtr _sensor, sdf::ElementPtr /*_sdf*/)
{
  // Get the parent sensor.
  this->parentSensor =
    std::dynamic_pointer_cast<sensors::WirelessReceiver>(_sensor);

  // Make sure the parent sensor is valid.
  if (!this->parentSensor)
  {
    gzerr << "WirelessReceiverPlugin requires a WirelessReceiver.\n";
    return;
  }

  // Connect to the sensor update event.
  this->updateConnection = this->parentSensor->ConnectUpdated(
      std::bind(&WirelessReceiverPlugin::OnUpdate, this));

  // Make sure the parent sensor is active.
  this->parentSensor->SetActive(true);

    std::cout << "wirelress receiver active";
}

/////////////////////////////////////////////////
void WirelessReceiverPlugin::OnUpdate()
{
     std::cout << "recieved wireless signal";
     double power = 0.0;
     power = this->parentSensor->GetPower();
     std::cout << power << " \n";

}

I get both plugins, but when I try to use them with wireless_sensor.world some errors arise and the obtained power is not updated as expected.

This is the termnal output:

[Msg] Waiting for master.

[Msg] Waiting for master.

[Msg] Connected to gazebo master @ http://127.0.0.1:11345

[Msg] Connected to gazebo master @ http://127.0.0.1:11345

[Msg] Publicized address: 193.144.228.251

[Msg] Publicized address: 193.144.228.251

[Wrn] [msgs.cc:1685] Conversion of sensor type[wireless_transmitter] not suppported.

[Wrn] [msgs.cc:1685] Conversion of sensor type[wireless_receiver] not suppported.

wirelress transmitter activo

[Wrn] [Event.cc:87] Warning: Deleteing a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
wirelress receiver activo[Wrn] [msgs.cc:1685] Conversion of sensor type[wireless_transmitter] not suppported.

[Wrn] [msgs.cc:1685] Conversion of sensor type[wireless_receiver] not suppported.

[Wrn] [msgs.cc:1685] Conversion of sensor type[wireless_transmitter] not suppported.

[Wrn] [msgs.cc:1685] Conversion of sensor type[wireless_receiver] not suppported.

[Wrn] [Scene.cc:3172] Duplicate visuals detected[wirelessTransmitter_GUIONLY_transmitter_vis]

transmitted wireless signal14.5 

recieved wireless signal14.5 

transmitted wireless signal14.5 

recieved wireless signal14.5

Any suggestions? Thanks in advance