ROS noetic tf demo错误处理及python版本切换

文章目录

  • 报错描述及解决
  • ubuntu20.04下python版本切换

报错描述及解决

ubuntu版本:20.04,ROS版本:noetic

~$ roslaunch turtle_tf turtle_tf_demo.launch

报错信息

[turtle1_tf_broadcaster-4] process has died

完整信息

... logging to /home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/roslaunch-zbw-ubuntu-11587.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://zbw-ubuntu:36561/

SUMMARY
========

PARAMETERS
 * /rosdistro: noetic
 * /rosversion: 1.15.11
 * /scale_angular: 2.0
 * /scale_linear: 2.0
 * /turtle1_tf_broadcaster/turtle: turtle1
 * /turtle2_tf_broadcaster/turtle: turtle2

NODES
  /
    sim (turtlesim/turtlesim_node)
    teleop (turtlesim/turtle_teleop_key)
    turtle1_tf_broadcaster (turtle_tf/turtle_tf_broadcaster.py)
    turtle2_tf_broadcaster (turtle_tf/turtle_tf_broadcaster.py)
    turtle_pointer (turtle_tf/turtle_tf_listener.py)

auto-starting new master
process[master]: started with pid [11595]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 501597ba-e4b7-11eb-b452-b90036f82ed0
process[rosout-1]: started with pid [11605]
started core service [/rosout]
process[sim-2]: started with pid [11612]
process[teleop-3]: started with pid [11613]
process[turtle1_tf_broadcaster-4]: started with pid [11614]
Reading from keyboard
---------------------------
Use arrow keys to move the turtle. 'q' to quit.
process[turtle2_tf_broadcaster-5]: started with pid [11619]
process[turtle_pointer-6]: started with pid [11622]
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/turtle_tf/turtle_tf_broadcaster.py", line 35, in <module>
    import rospy
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/noetic/lib/python3/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest  # noqa: F401
  File "/opt/ros/noetic/lib/python3/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named rospkg
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/turtle_tf/turtle_tf_listener.py", line 34, in <module>
    import rospy
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/noetic/lib/python3/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest  # noqa: F401
  File "/opt/ros/noetic/lib/python3/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named rospkg
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/turtle_tf/turtle_tf_broadcaster.py", line 35, in <module>
    import rospy
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/noetic/lib/python3/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest  # noqa: F401
  File "/opt/ros/noetic/lib/python3/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named rospkg
[turtle1_tf_broadcaster-4] process has died [pid 11614, exit code 1, cmd /opt/ros/noetic/lib/turtle_tf/turtle_tf_broadcaster.py __name:=turtle1_tf_broadcaster __log:=/home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/turtle1_tf_broadcaster-4.log].
log file: /home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/turtle1_tf_broadcaster-4*.log
[turtle2_tf_broadcaster-5] process has died [pid 11619, exit code 1, cmd /opt/ros/noetic/lib/turtle_tf/turtle_tf_broadcaster.py __name:=turtle2_tf_broadcaster __log:=/home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/turtle2_tf_broadcaster-5.log].
log file: /home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/turtle2_tf_broadcaster-5*.log
[turtle_pointer-6] process has died [pid 11622, exit code 1, cmd /opt/ros/noetic/lib/turtle_tf/turtle_tf_listener.py __name:=turtle_pointer __log:=/home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/turtle_pointer-6.log].
log file: /home/zbw/.ros/log/501597ba-e4b7-11eb-b452-b90036f82ed0/turtle_pointer-6*.log

如果demo运行正常,效果应该是屏幕上出现两只小乌龟,当使用键盘上的箭头按键控制小乌龟运动时,另一只小乌龟会跟随我们控制的乌龟移动。由于出现了上面的错误,屏幕上只出现一只小乌龟。demo中使用的是python3,而系统默认使用的是python2,更改默认python版本后运行正常。

ubuntu20.04下python版本切换

  1. 查看已安装的python版本

~$ ls /usr/bin/python*

可以看到当前系统中有两个python版本
在这里插入图片描述

  1. 查看系统中是否有python配置选项

~$ sudo update-alternatives --list python

没有添加过配置选项的话会显示update-alternatives错误
在这里插入图片描述

配置过的话会显示下图的内容
在这里插入图片描述

  1. 第1步中看到了系统有python2和python3两个版本,下面配置python选项

~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

在这里插入图片描述

  1. python版本切换

先来查看下目前使用的python版本

~$ python --version

当前使用的是python2
在这里插入图片描述
下面来切换python版本

~$ sudo update-alternatives --config python

根据编号,输入2后回车,即切换到了python3
ROS noetic tf demo错误处理及python版本切换_第1张图片
再来查看一下python版本,已经切换成功,如果想要切换回python2,重复上面的步骤,输入编号1即可
在这里插入图片描述
参考网址

☝ ★★★ — 返回 《ROS机器人开发笔记汇总》总目录 — ★★★ ☝

你可能感兴趣的:(ROS机器人开发笔记,ros,noetic,tf,tf,demo,python版本)