I am following the instructions provided on ROS2 Jazzy tutorial page on Webots. When I launch the robot using the following command:
ros2 launch my_package robot_launch.py
I get the following error:
All log files can be found below /home/swagat/.ros/log/2025-04-29-14-34-05-202943-swagat-Alienware-m18-R2-126534
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [webots-1]: process started with pid [126537]
[INFO] [webots_controller_my_robot-2]: process started with pid [126538]
[webots_controller_my_robot-2] The specified robot (at /tmp/webots/swagat/1234/ipc/my_robot/extern) is not in the list of robots with <extern> controllers, retrying for another 50 seconds...
[webots_controller_my_robot-2] Traceback (most recent call last):
[webots_controller_my_robot-2] File "/home/swagat/ros2_ws/install/my_package/lib/python3.12/site-packages/my_package/my_robot_driver.py", line 1, in <module>
[webots_controller_my_robot-2] import rclpy
[webots_controller_my_robot-2] File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/__init__.py", line 48, in <module>
[webots_controller_my_robot-2] from rclpy.parameter import Parameter
[webots_controller_my_robot-2] File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/parameter.py", line 27, in <module>
[webots_controller_my_robot-2] import yaml
[webots_controller_my_robot-2] ModuleNotFoundError: No module named 'yaml'
[webots_controller_my_robot-2] terminate called after throwing an instance of 'std::runtime_error'
[webots_controller_my_robot-2] what(): The my_package.my_robot_driver.MyRobotDriver plugin cannot be found (C++ or Python).
[webots_controller_my_robot-2] [ros2run]: Aborted
[ERROR] [webots_controller_my_robot-2]: process has died [pid 126538, exit code 250, cmd '/opt/ros/jazzy/share/webots_ros2_driver/scripts/webots-controller --robot-name=my_robot --protocol=ipc --port=1234 ros2 --ros-args -p robot_description:=/home/swagat/ros2_ws/install/my_package/share/my_package/resource/my_robot.urdf'].
I have checked that the module pyyaml is already installed and working. Not sure why it is able to find the yaml module.
The file my_robot.urdf has the following content:
<?xml version="1.0" ?>
<robot name="my robot">
<webots>
<plugin type="my_package.my_robot_driver.MyRobotDriver" />
</webots>
</robot>
MyRobotDriver is a class defined in the script my_package/my_package/my_robot_driver.py. This is exactly the same as provided on the tutorial page above. Also, I notice that this file does not have a main function even though it is referred to the in the setup.py file.
Any help to resolve this error will be appreciated.
Thanks & Regards, Swagat
ModuleNotFoundError: No module named 'yaml'. Do you haveyamlpackage installed?