ros2 启动rosbridge:
要启动ROS2中的rosbridge,需要先安装ROS2的rosbridge_suite软件包。使用以下命令安装:
sudo apt-get update
sudo apt-get install ros-<distro>-rosbridge-suite
将<distro>
替换为正在使用的ROS2发行版的名称,我的开发板是foxy
。
安装完成后,可以使用以下命令启动rosbridge:
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
ros2 run rosbridge_server rosbridge_websocket
这将启动rosbridge服务器并在WebSocket端口(默认为9090)上监听传入的连接请求。现在可以使用WebSocket客户端连接到rosbridge服务器,并使用ROS2消息进行通信。
ps:
在启动rosbridge的时候可能遇到报错:
cindy@ubuntu:~$ ros2 launch rosbridge_server rosbridge_websocket_launch.xml [INFO] [launch]: All log files can be found below /home/cindy/.ros/log/2023-08-25-11-04-02-495747-ubuntu-90823 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [rosbridge_websocket-1]: process started with pid [90825] [INFO] [rosapi_node-2]: process started with pid [90827] [rosbridge_websocket-1] Traceback (most recent call last): [rosbridge_websocket-1] File "/opt/ros/foxy/lib/rosbridge_server/rosbridge_websocket", line 45, in <module> [rosbridge_websocket-1] from rosbridge_library.capabilities.subscribe import Subscribe [rosbridge_websocket-1] File "/opt/ros/foxy/lib/python3.8/site-packages/rosbridge_library/capabilities/subscribe.py", line 38, in <module> [rosbridge_websocket-1] from rosbridge_library.internal.pngcompression import encode as encode_png [rosbridge_websocket-1] File "/opt/ros/foxy/lib/python3.8/site-packages/rosbridge_library/internal/pngcompression.py", line 37, in <module> [rosbridge_websocket-1] from PIL import Image [rosbridge_websocket-1] ModuleNotFoundError: No module named 'PIL' [ERROR] [rosbridge_websocket-1]: process has died [pid 90825, exit code 1, cmd '/opt/ros/foxy/lib/rosbridge_server/rosbridge_websocket --ros-args -r __node:=rosbridge_websocket --params-file /tmp/launch_params_a52mg6ze --params-file /tmp/launch_params_4ik_ubfb --params-file /tmp/launch_params_hne3k2bh --params-file /tmp/launch_params_zjtdbmwi --params-file /tmp/launch_params__akyk0l9 --params-file /tmp/launch_params_rpbmxoz9 --params-file /tmp/launch_params_1_ygw841 --params-file /tmp/launch_params_xsxxbbd5 --params-file /tmp/launch_params_0v3jj0yl --params-file /tmp/launch_params_mqfiurda --params-file /tmp/launch_params_o70a8uof --params-file /tmp/launch_params_i7wcqg3t'].
这个错误提示是因为缺少PIL模块导致的。PIL是Python Imaging Library的缩写,它是Python的一个图像处理库,rosbridge_server需要用到它来进行图像压缩。需要安装PIL模块,可以使用以下命令来安装:
pip3 install pillow
安装完成后,再次尝试启动rosbridge_server,应该就不会再出现这个错误了。