robotology / gazebo-yarp-plugins

Plugins to interface Gazebo with YARP.
33 stars 48 forks source link

lasersensor errors #347

Open charleswilmot opened 6 years ago

charleswilmot commented 6 years ago

Hello everyone,

I have difficulties using the lasersensor plugin. Whenever I include a lasersensor to a sdf model, gazebo throws the following error:

yarp: Port /icubSim/laser/left active at tcp://141.2.249.190:10004/
yarp: Port /icubSim/laser/left/rpc:i active at tcp://141.2.249.190:10005/
[INFO]Rangefinder2DWrapper : no ROS initialization required 
[ERROR]Cannot find "gazebo_lasersensor" plugin (not built in, and no .ini file found for it)
[ERROR]Check that YARP_DATA_DIRS leads to at least one directory with plugins/gazebo_lasersensor.ini or share/yarp/plugins/gazebo_lasersensor.ini in it
yarpdev: ***ERROR*** could not find device <gazebo_lasersensor>
[ERROR]RangeFinder2DWrapper: failed to open subdevice.. check params 
yarpdev: ***ERROR*** driver <Rangefinder2DWrapper> was found but could not open
[ERROR]GazeboYarpLaserSensor Plugin failed: error in opening yarp driver wrapper 

Here is how I define the sensor in the sdf:

      <sensor name ='right_laser_sensor' type='ray'>
              <ray>
                <scan>
                  <horizontal>
                    <samples>1</samples>
                    <resolution>1</resolution>
                    <min_angle>-0.001</min_angle>
                    <max_angle>0.001</max_angle>
                  </horizontal>
                </scan>
                <range>
                  <min>0.01</min>
                  <max>50.0</max>
                  <resolution>0.001</resolution>
                </range>
              </ray>
              <always_on>1</always_on>
              <update_rate>100</update_rate>
              <visualize>true</visualize>
              <plugin filename="libgazebo_yarp_lasersensor.so" name="right_laser_plugin">
                 <yarpConfigurationFile>model://icub_head_laser/conf/right_laser.ini</yarpConfigurationFile>
              </plugin>
      </sensor>

Finally, here is the right_laser.ini file:

[include "gazebo_icub_robotname.ini"]

device Rangefinder2DWrapper
subdevice gazebo_lasersensor
name /${gazeboYarpPluginsRobotName}/laser/right
period 10

For debugging purpose, I tried creating an other .ini file, in the folder indicated by the environment variable YARP_DATA_DIR, and called it gazebo_lasersensor.ini :

>>> echo $YARP_DATA_DIR
[...]/yarp/install/share/yarp/

>>> cat [...]/yarp/install/share/yarp/plugins/gazebo_lasersensor.ini
[plugin gazebo_lasersensor]
type device
name gazebo_lasersensor
library gazebo_lasersensor

But I still get the same error (Cannot find "gazebo_lasersensor" plugin (not built in, and no .ini file found for it), Check that YARP_DATA_DIRS leads to at least one directory with plugins/gazebo_lasersensor.ini or share/yarp/plugins/gazebo_lasersensor.ini in it)

Could you tell me more about subdevices? Isn't the lasersensor a built-in plugin? What are the built-in plugins?

Thank you for your generous help, Charles

Additional resources:

readFromSelector where the error message comes from plugin selector definition of getSelectedPlugins YarpPluginSelector::scan definition of scan

charleswilmot commented 6 years ago

So I made some improvement today. First error was that the subdevice name isn't gazebo_lasersensor but gazebo_laserSensor with a capital S.

Then I found out that the config file requires a [GENERAL] section. The config file is looking like this now:

[include "gazebo_icub_robotname.ini"]

device Rangefinder2DWrapper
subdevice gazebo_laserSensor
sensorScopedName default::iCub::right_eye_link::right_laser_sensor
name /${gazeboYarpPluginsRobotName}/laser/right
period 10

[GENERAL]
clip_min_range 0.01
clip_max_range 50
discard_min_range 0.01
discard_max_range 50
enable_clip_range false
enable_discard_range false

Now the error message looks different:

[ERROR] Internal error
[ERROR] Rangefinder2DWrapper: Rangefinder2DWrapper: sensor returned false

The error actually comes from line 33. In the beginning, when the sensor is not functioning yet, the call to m_parentSensor->Ranges(m_sensorData) fills m_sensorData with a vector of size 0. The size of this vector is later checked at line 158. It seems that the variable m_first_run was supposed to avoid that issue, but it does not do the job correctly (at least on my installation).

There is multiple ways of solving that issue, but I'm not sure which one should be preferred. On my side, I replaced the line 33 by a loop:

    for (unsigned int i=0; i<m_samples; i++)
    {
  #if GAZEBO_MAJOR_VERSION >= 7
      m_sensorData[i] = this->m_parentSensor->Range(i);
  #else
      m_sensorData[i] = this->m_parentSensor->GetRange(i);
  #endif
    }

And this seems to work well. Only one remaining issue separates me now from getting the sensor working. I do observe in the standard output of gazebo that ports are active, but I can't see them in the output on yarp name list

yarp: Port /icubSim/laser/right active at tcp://141.2.249.190:10007/
yarp: Port /icubSim/laser/right/rpc:i active at tcp://141.2.249.190:10008/
[INFO]Rangefinder2DWrapper : no ROS initialization required 
[INFO]created device <gazebo_laserSensor>. See C++ class GazeboYarpLaserSensorDriver for documentation.
[INFO]created wrapper <Rangefinder2DWrapper>. See C++ class yarp::dev::Rangefinder2Dwrapper for documentation.
[INFO]created device <gazebo_laserSensor>. See C++ class GazeboYarpLaserSensorDriver for documentation.
traversaro commented 6 years ago

Hi @charleswilmot, sorry for the (extremely) late response. Apart from the fixes that you listed i n your issue (thanks!) you were then finally able to get the lasersensor to work?