Gazebo | Ignition | Community
Ask Your Question
0

Plugin for WirelessTransmitter and WirelessReciever sensors

asked 2016-04-05 06:54:30 -0500

tseco gravatar image

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=co...

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

edit retag flag offensive close merge delete

Comments

Can you post your SDF file that includes the plugin? Also, let us know what version of gazebo you are using.

nkoenig gravatar imagenkoenig ( 2016-04-05 11:00:11 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-06 06:25:08 -0500

tseco gravatar image

Hi,

I am working with Gazebo 7 and the file that includes the plugin is a modify version of wireless_sensors.world:

<?xml version="1.0" ?>
<sdf version="1.5">
  <world name="default">
    <!-- Ground -->
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <!-- Wireless transmitter sensor model -->
    <model name="wirelessTransmitter">
      <static>true</static>
      <pose>0 0 0.025 0 0 0</pose>
      <link name="link">
        <inertial>
          <mass>0.1</mass>
        </inertial>
        <visual name="base">
          <geometry>
            <box>
              <size>.05 .05 .05</size>
            </box>
          </geometry>
        </visual>
        <visual name="antenna">
          <pose>0 0 .04 0 0 0</pose>
          <geometry>
            <cylinder>
              <radius>.005</radius>
              <length>.07</length>
            </cylinder>
          </geometry>
        </visual>
        <sensor name="wirelessTransmitter" type="wireless_transmitter">
          <always_on>1</always_on>
          <update_rate>1</update_rate>
          <visualize>true</visualize>
          <transceiver>
            <essid>osrf</essid>
            <frequency>2442.0</frequency>
            <power>14.5</power>
            <gain>2.6</gain>
          </transceiver>
        </sensor>
      </link>
    </model>
    <!-- Wireless receiver sensor model -->
    <model name="wirelessReceiver">
      <static>true</static>
      <pose>0 -5 0.025 0 0 0</pose>
      <link name="link">
        <inertial>
          <mass>0.1</mass>
        </inertial>
        <visual name="base">
          <geometry>
            <box>
              <size>.05 .05 .05</size>
            </box>
          </geometry>
        </visual>
        <visual name="antenna">
          <pose>0 0 .04 0 0 0</pose>
          <geometry>
            <cylinder>
              <radius>.005</radius>
              <length>.07</length>
            </cylinder>
          </geometry>
        </visual>
        <sensor name="wirelessReceiver" type="wireless_receiver">
                <plugin name="receiver_plugin" filename="libwirelessReceiver.so"/>
          <always_on>1</always_on>
          <update_rate>1</update_rate>
          <visualize>true</visualize>
          <transceiver>
            <min_frequency>2412.0</min_frequency>
            <max_frequency>2484.0</max_frequency>
            <power>14.5</power>
            <gain>2.5</gain>
            <sensitivity>-90.0</sensitivity>
          </transceiver>
        </sensor>
      </link>
    </model>
    <!-- A global light source -->
    <include>
      <uri>model://sun</uri>
    </include>
  </world>
</sdf>

The received signal has the initial value 14.5, but the gazebo topic (/gazebo/default/wirelessReceiver/link/wirelessReceiver/transceiver) publishes another value:

node {
  essid: "osrf"
  frequency: 2442
  signal_level: -30.926731914521884
}

The message type of this topic is msgs::WirelessNodes but I do not know how to obtain this vaule from sensors::WirelessReceiver sensor.

My final goal is to create a gazebo ros plugin.

Thanks in advance!

edit flag offensive delete link more

Comments

Hi, I am also needing a wireless receiver plugin for a project. Were you successful creating it that way?

robot1 gravatar imagerobot1 ( 2016-10-14 08:31:45 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-04-05 06:54:30 -0500

Seen: 2,367 times

Last updated: Apr 06 '16