1
$\begingroup$

I am trying to set up a Lidar, IMU, and depth camera in Webots on a ROS 2 robot in its xacro file (starting with just the Lidar).

I currently have the following:

<webots>

  <plugin type="webots_ros2_driver::Ros2Lidar">
    <frameName>laser_frame</frameName>
    <enabled>true</enabled>
    <scanRate>10</scanRate>
    <topicName>/scan</topicName>
    <alwaysOn>true</alwaysOn>
  </plugin>

  <plugin type="webots_ros2_control::Ros2Control"/>

</webots>

I'm not sure about the parameters since I just adapted it from the IMU plugin from the turtlebot webots_ros2 example. But the only error I have is this:

[driver-2] ModuleNotFoundError: No module named 'webots_ros2_driver::Ros2Lidar'
[driver-2] terminate called after throwing an instance of 'std::runtime_error'
[driver-2]   what():  The webots_ros2_driver::Ros2Lidar plugin cannot be found (C++ or Python).

I've found the Ros2Lidar plugin locally (I think), but it doesn't seem to be able to find it. The demos all work, but the vast majority are just from robots built IN Webots .proto files. But I need to use ROS for the robot itself that uses a xacro file.

Any hints would be appreciated.

Thanks in advance, Craig

$\endgroup$

1 Answer 1

1
$\begingroup$

We are aware that there is a lack of documentation on current implemented device interfaces and how to use them. We are currently working on new tutorials for the official ROS 2 documentation.

Currently, there are 10 devices that have an automatic interface with ROS 2:

  • Camera
  • Compass
  • Distance Sensor
  • Emitter
  • GPS
  • LED
  • Lidar
  • Light Sensor
  • Ranger Finder
  • Receiver

For these devices, webots_ros2_driver will automatically load the static plugin. This means that associated topics and services will be created. You can have a look at each of these plugins in webots_ros2_driver/src/plugins/static. You can overwrite multiple parameters like topic names or the update rate in your URDF file in the <webots> tag. In your example, it would be:

<device reference="lidar_name_in_webots" type="Lidar">
  <ros>
    <frameName>laser_frame</frameName>
    <enabled>true</enabled>
    <scanRate>10</scanRate>
    <topicName>/scan</topicName>
    <alwaysOn>true</alwaysOn>
  </ros>
</device>    

There is also a plugin provided with webots_ros2_driver that interfaces IMU sensors. You can find it in webots_ros2_driver/src/plugins/dynamic. This plugin can be loaded in the exact way you did in your question:

<plugin type="webots_ros2_driver::Ros2IMU">
  <enabled>true</enabled>
  <topicName>/imu</topicName>
  <alwaysOn>true</alwaysOn>
  <frameName>imu_link</frameName>
  <inertialUnitName>inertial unit</inertialUnitName>
  <gyroName>gyro</gyroName>
</plugin>

If the default interfaces don't suit you or is not enough, you can create your own custom plugin. Please take a look at the following links to do so in C++ or Python: Tutorial-Creating-a-Custom-Cpp-Plugin and Tutorial-Creating-a-Custom-Python-Plugin.

$\endgroup$
8
  • $\begingroup$ Thanks for the reply! I've tried adding the Lidar as you described but I haven't seen anything show up in webots, nor are there topicspublished in ROS 2. I can't see any errors either so there's no indication that it's failing. I have the frameName linked with the urdf physical lidar shape. But it doesn't seem to be working. Any ideas? Does the reference="hokuyo" refer to a hardware model? Or is it just a name? $\endgroup$
    – Craig MS
    Apr 1, 2023 at 3:25
  • $\begingroup$ I am very sorry for the confusion. I thought I had changed this field. In fact, the name of the Lidar in Webots should be given in the reference of the device tag. I have edited my answer. $\endgroup$ Apr 3, 2023 at 6:21
  • $\begingroup$ Ah thanks for the clarification! Does setting these devices in the urdf require a webots proto in addition to the urdf? Devices don't seem to be added when I import from a xacro/urdf. I have devices defined in the xacro file and everything imports spawns in webots properly including the ros2_controllers, but Lidars and such don't seem to come along? $\endgroup$
    – Craig MS
    Apr 3, 2023 at 8:14
  • $\begingroup$ I solved this! Apparently, the URDFspawner script can import using gazebo tags... a bit weird but okay. I managed to get the robot importing and working just by using <gazebo> <sensor> tags in the URDF. I still had to enable them in webots but after that they worked as expected. $\endgroup$
    – Craig MS
    Apr 3, 2023 at 22:33
  • 1
    $\begingroup$ Looking into the code it doesn't look too tricky to add GPS into urdf2webots so I might do that. $\endgroup$
    – Craig MS
    Apr 6, 2023 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.