正常导入包依赖命令:
cd src
catkin_create_pkg 自定义ROS包名 roscpp rospy std_msgs
这个是在创建功能包的同时导入包依赖。
请问下如何分开呢,先创建自定义功能包在按项目需求导入包依赖。
比如一个项目 我创建了功能包导入了roscpp 但是我突然又想用到rospy了怎么办?
项目是公司找的别人开发的ros项目
第一步
执行上面命令编译出现下图错误
百度
https://blog.csdn.net/qq_39779233/article/details/119384745
使用这个教程安装不起ros-melodic-catkin
按照此教程正常无报错运行
https://fishros.com/d2lros2/#/chapt10/10.5%E9%85%8D%E7%BD%AEFishbot%E8%BF%9B%E8%A1%8C%E5%BB%BA%E5%9B%BE
但是控制机器人走路并未出现5.3当中的建图路线
正常教程路线
我创建的未展示路线
@271658536 在 CMake编译错误 中说:
ModuleNotFoundError: No module named 'catkin_pkg'
已经解决,解决方法原文如下:
https://blog.csdn.net/qq_27865227/article/details/122609055
前置操作
安装carotgrapher
sudo apt install ros-foxy-cartographer
sudo apt install ros-foxy-cartographer-ros
然后在fishbot_ws工作空间创建fishbot_cartographer功能包
ros2 pkg create fishbot_cartographer
执行编译命令
colcon build --packages-select fishbot_cartographer
CMakeLists.txt文件内容如下
cmake_minimum_required(VERSION 3.5)
project(fishbot_cartographer)
install(
DIRECTORY config launch rviz
DESTINATION share/${PROJECT_NAME}
)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
编译错误内容如下
Starting >>> fishbot_cartographer
--- stderr: fishbot_cartographer
Traceback (most recent call last):
File "/opt/ros/foxy/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py", line 21, in <module>
from catkin_pkg.package import parse_package_string
ModuleNotFoundError: No module named 'catkin_pkg'
CMake Error at /opt/ros/foxy/share/ament_cmake_core/cmake/core/ament_package_xml.cmake:94 (message):
execute_process(/home/ros2/miniconda3/bin/python3
/opt/ros/foxy/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py
/home/ros2/fishbot_ws/src/fishbot_cartographer/package.xml
/home/ros2/fishbot_ws/build/fishbot_cartographer/ament_cmake_core/package.cmake)
returned error code 1
Call Stack (most recent call first):
/opt/ros/foxy/share/ament_cmake_core/cmake/core/ament_package_xml.cmake:49 (_ament_package_xml)
/opt/ros/foxy/share/ament_lint_auto/cmake/ament_lint_auto_find_test_dependencies.cmake:31 (ament_package_xml)
CMakeLists.txt:37 (ament_lint_auto_find_test_dependencies)
---
Failed <<< fishbot_cartographer [0.63s, exited with code 1]
Summary: 0 packages finished [0.85s]
1 package failed: fishbot_cartographer
1 package had stderr output: fishbot_cartographer
新建功能包无任何操作,编译也是这个错误。
urdf文件
<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- | This document was autogenerated by xacro from test03_my_car.xacro | -->
<!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | -->
<!-- =================================================================================== -->
<!-- 组合小车底盘与摄像头与雷达 -->
<robot name="my_car">
<!-- 圆柱惯性矩阵 -->
<!-- 立方体惯性矩阵 -->
<!-- 宏:黑色设置 -->
<material name="black">
<color rgba="0.0 0.0 0.0 1.0"/>
</material>
<!-- 质量 -->
<!-- 底盘 -->
<link name="base_footprint">
<visual>
<geometry>
<sphere radius="0.001"/>
</geometry>
</visual>
</link>
<link name="base_link">
<visual>
<geometry>
<cylinder length="0.08" radius="0.1"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
<material name="yellow">
<color rgba="0.5 0.3 0.0 0.5"/>
</material>
</visual>
<collision>
<geometry>
<cylinder length="0.08" radius="0.1"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
</collision>
<inertial>
<mass value="0.5"/>
<inertia ixx="0.001516666666666667" ixy="0" ixz="0" iyy="0.001516666666666667" iyz="0" izz="0.0025000000000000005"/>
</inertial>
</link>
<joint name="base_link2base_footprint" type="fixed">
<parent link="base_footprint"/>
<child link="base_link"/>
<origin xyz="0 0 0.055"/>
</joint>
<gazebo reference="base_link">
<material>Gazebo/Yellow</material>
</gazebo>
<!-- 质量 -->
<link name="left_wheel">
<visual>
<geometry>
<cylinder length="0.015" radius="0.0325"/>
</geometry>
<origin rpy="1.5707963 0.0 0.0" xyz="0.0 0.0 0.0"/>
<material name="black"/>
</visual>
<collision>
<geometry>
<cylinder length="0.015" radius="0.0325"/>
</geometry>
<origin rpy="1.5707963 0.0 0.0" xyz="0.0 0.0 0.0"/>
</collision>
<inertial>
<mass value="0.05"/>
<inertia ixx="1.4140625000000002e-05" ixy="0" ixz="0" iyy="1.4140625000000002e-05" iyz="0" izz="2.6406250000000005e-05"/>
</inertial>
</link>
<joint name="left_wheel2base_link" type="continuous">
<parent link="base_link"/>
<child link="left_wheel"/>
<origin xyz="0 0.1 -0.0225"/>
<axis xyz="0 1 0"/>
</joint>
<gazebo reference="left_wheel">
<material>Gazebo/Red</material>
</gazebo>
<link name="right_wheel">
<visual>
<geometry>
<cylinder length="0.015" radius="0.0325"/>
</geometry>
<origin rpy="1.5707963 0.0 0.0" xyz="0.0 0.0 0.0"/>
<material name="black"/>
</visual>
<collision>
<geometry>
<cylinder length="0.015" radius="0.0325"/>
</geometry>
<origin rpy="1.5707963 0.0 0.0" xyz="0.0 0.0 0.0"/>
</collision>
<inertial>
<mass value="0.05"/>
<inertia ixx="1.4140625000000002e-05" ixy="0" ixz="0" iyy="1.4140625000000002e-05" iyz="0" izz="2.6406250000000005e-05"/>
</inertial>
</link>
<joint name="right_wheel2base_link" type="continuous">
<parent link="base_link"/>
<child link="right_wheel"/>
<origin xyz="0 -0.1 -0.0225"/>
<axis xyz="0 1 0"/>
</joint>
<gazebo reference="right_wheel">
<material>Gazebo/Red</material>
</gazebo>
<!-- 质量 -->
<link name="front_wheel">
<visual>
<geometry>
<sphere radius="0.0075"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
<material name="black"/>
</visual>
<collision>
<geometry>
<sphere radius="0.0075"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
</collision>
<inertial>
<mass value="0.03"/>
<inertia ixx="6.75e-07" ixy="0" ixz="0" iyy="6.75e-07" iyz="0" izz="6.75e-07"/>
</inertial>
</link>
<joint name="front_wheel2base_link" type="continuous">
<parent link="base_link"/>
<child link="front_wheel"/>
<origin xyz="0.0925 0 -0.0475"/>
<axis xyz="1 1 1"/>
</joint>
<gazebo reference="front_wheel">
<material>Gazebo/Red</material>
</gazebo>
<link name="back_wheel">
<visual>
<geometry>
<sphere radius="0.0075"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
<material name="black"/>
</visual>
<collision>
<geometry>
<sphere radius="0.0075"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
</collision>
<inertial>
<mass value="0.03"/>
<inertia ixx="6.75e-07" ixy="0" ixz="0" iyy="6.75e-07" iyz="0" izz="6.75e-07"/>
</inertial>
</link>
<joint name="back_wheel2base_link" type="continuous">
<parent link="base_link"/>
<child link="back_wheel"/>
<origin xyz="-0.0925 0 -0.0475"/>
<axis xyz="1 1 1"/>
</joint>
<gazebo reference="back_wheel">
<material>Gazebo/Red</material>
</gazebo>
<!-- 摄像头安装的z坐标:底盘高度 / 2 + 摄像头高度 / 2 -->
<!-- 摄像头质量 -->
<!-- 摄像头关节以及link -->
<link name="camera">
<visual>
<geometry>
<box size="0.01 0.025 0.025"/>
</geometry>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<material name="black"/>
</visual>
<collision>
<geometry>
<box size="0.01 0.025 0.025"/>
</geometry>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
</collision>
<inertial>
<mass value="0.01"/>
<inertia ixx="6.041666666666668e-07" ixy="0" ixz="0" iyy="6.041666666666668e-07" iyz="0" izz="1.041666666666667e-06"/>
</inertial>
</link>
<joint name="camera2base_link" type="fixed">
<parent link="base_link"/>
<child link="camera"/>
<origin xyz="0.08 0.0 0.052500000000000005"/>
</joint>
<gazebo reference="camera">
<material>Gazebo/Blue</material>
</gazebo>
<!-- 支架安装的z坐标:底盘高度 / 2 + 支架高度 / 2 -->
<!-- 支架质量 -->
<link name="support">
<visual>
<geometry>
<cylinder length="0.15" radius="0.01"/>
</geometry>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<material name="red">
<color rgba="0.8 0.2 0.0 0.8"/>
</material>
</visual>
<collision>
<geometry>
<cylinder length="0.15" radius="0.01"/>
</geometry>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
</collision>
<inertial>
<mass value="0.02"/>
<inertia ixx="3.8e-05" ixy="0" ixz="0" iyy="3.8e-05" iyz="0" izz="1.0000000000000002e-06"/>
</inertial>
</link>
<joint name="support2base_link" type="fixed">
<parent link="base_link"/>
<child link="support"/>
<origin xyz="0.0 0.0 0.11499999999999999"/>
</joint>
<gazebo reference="support">
<material>Gazebo/White</material>
</gazebo>
<!-- 雷达安装的z坐标:支架高度 / 2 + 雷达高度 / 2 -->
<!-- 雷达质量 -->
<!-- 雷达关节以及link -->
<link name="laser">
<visual>
<geometry>
<cylinder length="0.05" radius="0.03"/>
</geometry>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<material name="black"/>
</visual>
<collision>
<geometry>
<cylinder length="0.05" radius="0.03"/>
</geometry>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
</collision>
<inertial>
<mass value="0.1"/>
<inertia ixx="4.333333333333333e-05" ixy="0" ixz="0" iyy="4.333333333333333e-05" iyz="0" izz="4.4999999999999996e-05"/>
</inertial>
</link>
<joint name="laser2support" type="fixed">
<parent link="support"/>
<child link="laser"/>
<origin xyz="0.0 0.0 0.1"/>
</joint>
<gazebo reference="laser">
<material>Gazebo/Black</material>
</gazebo>
<!-- 控制器 -->
<gazebo>
<plugin name='diff_drive' filename='libgazebo_ros_diff_drive.so'>
<ros>
<namespace>/</namespace>
<remapping>cmd_vel:=cmd_vel</remapping>
<remapping>odom:=odom</remapping>
</ros>
<update_rate>30</update_rate>
<left_joint>left_wheel2base_link</left_joint>
<right_joint>right_wheel2base_link</right_joint>
<!-- kinematics -->
<wheel_separation>0.2</wheel_separation>
<wheel_diameter>0.065</wheel_diameter>
<!-- limits -->
<max_wheel_torque>20</max_wheel_torque>
<max_wheel_acceleration>1.0</max_wheel_acceleration>
<!-- output -->
<publish_odom>true</publish_odom>
<publish_odom_tf>true</publish_odom_tf>
<publish_wheel_tf>false</publish_wheel_tf>
<odometry_frame>odom</odometry_frame>
<robot_base_frame>base_footprint</robot_base_frame>
</plugin>
<plugin name="fishbot_joint_state" filename="libgazebo_ros_joint_state_publisher.so">
<ros>
<remapping>~/out:=joint_states</remapping>
</ros>
<update_rate>30</update_rate>
<joint_name>left_wheel2base_link</joint_name>
<joint_name>right_wheel2base_link</joint_name>
</plugin>
</gazebo>
</robot>
launch代码
import os
from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
def generate_launch_description():
package_name = 'fishbot_description'
urdf_name = "test04.urdf"
rviz_name = "demo01.rviz"
robot_name_in_model = 'fishbot'
ld = LaunchDescription()
pkg_share = FindPackageShare(package=package_name).find(package_name)
urdf_model_path = os.path.join(pkg_share, f'urdf/{urdf_name}')
rviz_path_ = os.path.join(pkg_share, f'config/{rviz_name}')
gazebo_world_path = os.path.join(pkg_share, 'world/box_house.world')
# Start Gazebo server
start_gazebo_cmd = ExecuteProcess(
cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so',gazebo_world_path],
output='screen')
# Launch the robot
spawn_entity_cmd = Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=['-entity', robot_name_in_model, '-file', urdf_model_path ], output='screen')
# 添加机器人状态发布节点
robot_state_publisher_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
arguments=[urdf_model_path]
)
# 可选:用于控制关节运动的节点
joint_state_publisher_gui_node = Node(
package='joint_state_publisher_gui',
executable='joint_state_publisher_gui',
name='joint_state_publisher_gui',
arguments=[urdf_model_path]
)
rviz2_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
arguments=['-d', rviz_path_]
# arguments=['-d', rviz_path]
)
ld.add_action(start_gazebo_cmd)
ld.add_action(spawn_entity_cmd)
ld.add_action(robot_state_publisher_node)
# ld.add_action(joint_state_publisher_gui_node)
ld.add_action(rviz2_node)
return ld
运行launch文件后会出现警告是怎么回事呢
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "back_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp
[rviz2-4] Warning: Invalid frame ID "front_wheel" passed to canTransform argument source_frame - frame does not exist
[rviz2-4] at line 133 in /tmp/binarydeb/ros-foxy-tf2-0.13.13/src/buffer_core.cpp