Problems and solutions encountered in ROS learning

Question 1. When using xarco to create urdf, an error is reported when running joint_state_publisher/joint_state_publisher_gui

The error is as follows:

[joint_state_publisher_gui-4] process has died [pid 97153, exit code 1, cmd /opt/ros/melodic/lib/joint_state_publisher_gui/joint_state_publisher_gui __name:=joint_state_publisher_gui __log:=/home/ros/.ros/log/4422783c-0504-11ee-8b5a-000c29b0c758/joint_state_publisher_gui-4.log].
log file: /home/ros/.ros/log/4422783c-0504-11ee-8b5a-000c29b0c758/joint_state_publisher_gui-4*.log

Reason: generally because urdf contains Chinese characters

solution:

  1. Delete all Chinese characters in the urdf file;
  2. Modify joint_state_publisher and joint_state_publisher_gui configuration
    • cd /opt/ros/melodic/lib/joint_state_publisher (joint_state_publisher_gui类似)
    • sudo gedit joint_state_publisher
    • Revise
    • Add reload(sys) sys.setdefaultencoding("utf-8") after import sys
  3. If the error is still reported, modify the execution permission:

    cd /opt/ros/melodic/lib/joint_state_publisher

    chmod 777 joint_state_publisher

Question 2. When using amcl to locate No laser scan received, there is a warning. The /scan topic has data, and amcl has also subscribed to this topic.

The error looks like this:

amcl: No laser scan received (and thus no pose updates have been published) for xxxx seconds ?

insert image description here
insert image description here
insert image description here
insert image description here

Reason: There is no odometer information, causing the amcl coordinate system to be disordered.
solution:

  1. Add odometer information
  2. post /odom topic
  3. Add conversion from base_link to odom

参考
amcl: No laser scan received (and thus no pose updates have been published) for xxxx seconds ?

Question 3. Running the .py file reports an error

reason:

  1. Whether to grant .py file permissions,
  2. Whether to mark executable files in CMakeLists.txt,
  3. Is it because of the Chinese remarks.

solution:

  1. sudo chomod +x .py
  2.  ## Mark executable scripts (Python etc.) for installation
     ## in contrast to setup.py, you can choose the destination
     # catkin_install_python(PROGRAMS
     #   scripts/my_python_script
     #   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
     # )
     # 
     catkin_install_python(PROGRAMS
     scripts/talker.py
     DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
     )
    
  3. Add at the top of the python file
    #! /usr/bin/env python
    # -*- coding: UTF-8 -*-
    

Question 4. ModuleNotFoundError: No module named 'xxxxx' is reported when a launch file is launched in roalaunch

Problem Description:

Traceback (most recent call last):
  File "/home/ros/catkin_workspace/src/arbotix_ros/arbotix_python/bin/arbotix_driver", line 30, in <module>
    import rospy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module>
    import roslib
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest  # noqa: F401
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ModuleNotFoundError: No module named 'rospkg'

reason

Because the ros version used by ubuntu18.04 is melodic, and melodic uses python2 by default, but we actually use python3 to run the code.

solution

  1. Add in the bashrc filealias python=python3
  2. after savingsource ~/.bashrc
  3. downloadpip3 install rospkg

Question 5. The character spacing of the vscode terminal is too large

Problem Description:
insert image description here

Cause
Due to the font under Linux, the character spacing is too large

solution
insert image description here

Question 6. When starting Gazebo in ROS for the first time, Err [REST.cc:205] Error in REST request appears

  1. Problem Description
    insert image description here

  2. Solution:
    Here you need to modify the .ignition/fuel/config.yaml file

    Open the yaml file command:

    sudo gedit ~/.ignition/fuel/config.yaml

    Comment url : https://api.ignitionfuel.orgout with #

    then add

    url: https://api.ignitionrobotics.org

    As shown below:

    insert image description here

<!-- 将 Urdf 文件的内容加载到参数服务器 -->
<param name="robot_description" textfile="$(find simu02)/urdf/urdf02_helloworld.urdf" />
<node pkg="rviz" type="rviz" name="rviz" />
<!-- 启动 gazebo -->
<!-- <include file="$(find gazebo_ros)/launch/empty_world.launch" /> -->

<!-- 在 gazebo 中显示机器人模型 -->
<!-- <node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model car -param robot_description"  /> -->

Set the default to use python3

  1. Default Python2 adjusted to Python3
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 200
    
  2. Default Python3 adjusted to Python2
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 200
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100
    
  3. Enter python in the terminal and find that python3 is used by default successfully!
    insert image description here

Question 7. File character set incompatibilities such as joint_state_publisher

  1. Problem Description

    UnicodeEncodeError: 'ascii' codec can't encode characters in position 53-57: ordinal not in range(128)
    
    [joint_state_publisher-1] process has died [pid 9340, exit code 1, cmd /opt/ros/melodic/lib/joint_state_publisher/joint_state_publisher __name:=joint_state_publisher __log:=/home/yzh/.ros/log/5314feca-c547-11ed-b4c2-000c2907fba7/joint_state_publisher-1.log].
    
    log file: /home/yzh/.ros/log/5314feca-c547-11ed-b4c2-000c2907fba7/joint_state_publisher-1*.log
    
    
  2. problem causes

    It is due to the problem of the character set. I saw many solutions saying not to write Chinese comments, but the comments are very important, otherwise you will not know what you are doing when you re-examine the code in the future.

  3. Solution

    Find the file in /opt/ros/melodic/lib/joint_state_publisher/joint_state_publisher and add it

    reload(sys)
    sys.setdefaultencoding( "utf-8" )
    

    These two lines of code can solve the character set problem.

Guess you like

Origin blog.csdn.net/weixin_45827203/article/details/131092263