当前位置: 首页 > news >正文

ros2—交叉编译ros bridge自定义消息

拉取ros bridge

git clone https://github.com/ros2/ros1_bridge.git

这里根据目标的ros2版本,切相应分支,目前我用的是foxy版本

git checkout foxy

编译ros1自定义消息

ros1编译操作在bridge根目录执行

创建ROS1工作区

mkdir catkin_ws
catkin_init_workspace
cd catkin_ws
mkdir src
cd src
catkin_create_pkg custom_msgs std_msgs message_generation

创建自定义消息内容

custom_msgs/msg/MotCmd.msg

# type: 1 on MoveL, 2 on MoveR, 3 on MoveCint64 type
Pose[] pose_arr
float64 velocity
float64 acceleration

custom_msgs/msg/Pose.msg

float64 x
float64 y
float64 z
float64 qw
float64 qx
float64 qy
float64 qz

custom_msgs/msg/ShapeBox.msg

Pose center
float64 l
float64 w
float64 h

custom_msgs/srv/PlannerPlanPath.srv

Pose start_pose
Pose target_pose
ShapeBox robot
ShapeBox[] env
---
int64 error_code
MotCmd[] cmd_arr

更改CMakeLists.txt 和package.xml

custom_msgs/CMakeLists.txt

cmake_minimum_required(VERSION 3.0.2)
project(custom_msgs)## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTSmessage_generationstd_msgs
)## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()################################################
## Declare ROS messages, services and actions ##
################################################## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)## Generate messages in the 'msg' folderadd_message_files(FILESMotCmd.msgPose.msgShapeBox.msg)## Generate services in the 'srv' folder
add_service_files(FILESPlannerPlanPath.srv
)## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )## Generate added messages and services with any dependencies listed heregenerate_messages(DEPENDENCIESstd_msgs)################################################
## Declare ROS dynamic reconfigure parameters ##
################################################## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES custom_msgsCATKIN_DEPENDS message_generation message_runtime std_msgs
#  DEPENDS system_lib
)###########
## Build ##
############# Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include${catkin_INCLUDE_DIRS}
)

custom_msgs/package.xml

<?xml version="1.0"?>
<package format="2"><name>custom_msgs</name><version>0.0.0</version><description>The custom_msgs package</description><!-- One maintainer tag required, multiple allowed, one person per tag --><!-- Example:  --><!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --><maintainer email="root@todo.todo">root</maintainer><!-- One license tag required, multiple allowed, one license per tag --><!-- Commonly used license strings: --><!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --><license>TODO</license><!-- Url tags are optional, but multiple are allowed, one per tag --><!-- Optional attribute type can be: website, bugtracker, or repository --><!-- Example: --><!-- <url type="website">http://wiki.ros.org/custom_msgs</url> --><!-- Author tags are optional, multiple are allowed, one per tag --><!-- Authors do not have to be maintainers, but could be --><!-- Example: --><!-- <author email="jane.doe@example.com">Jane Doe</author> --><!-- The *depend tags are used to specify dependencies --><!-- Dependencies can be catkin packages or system dependencies --><!-- Examples: --><!-- Use depend as a shortcut for packages that are both build and exec dependencies --><!--   <depend>roscpp</depend> --><!--   Note that this is equivalent to the following: --><!--   <build_depend>roscpp</build_depend> --><!--   <exec_depend>roscpp</exec_depend> --><!-- Use build_depend for packages you need at compile time: --><!--   <build_depend>message_generation</build_depend> --><!-- Use build_export_depend for packages you need in order to build against this package: --><!--   <build_export_depend>message_generation</build_export_depend> --><!-- Use buildtool_depend for build tool packages: --><!--   <buildtool_depend>catkin</buildtool_depend> --><!-- Use exec_depend for packages you need at runtime: --><!--   <exec_depend>message_runtime</exec_depend> --><!-- Use test_depend for packages you need only for testing: --><!--   <test_depend>gtest</test_depend> --><!-- Use doc_depend for packages you need only for building documentation: --><!--   <doc_depend>doxygen</doc_depend> --><buildtool_depend>catkin</buildtool_depend><build_depend>message_generation</build_depend><build_depend>std_msgs</build_depend><build_export_depend>std_msgs</build_export_depend><exec_depend>std_msgs</exec_depend><exec_depend>message_generation</exec_depend><exec_depend>message_runtime</exec_depend><!-- The export tag contains other, unspecified, tags --><export><!-- Other tools can request additional information be placed here --></export>
</package>

编译自定义消息

catkin_make

编译成功即可

编译ros2自定义消息

ros2编译操作在bridge根目录执行

创建ROS2工作区

# 需要新开一个终端,避免ROS1和ROS2环境混杂
source /opt/ros/foxy/setup.bash
mkdir colcon_ws
cd colcon_ws
ros2 pkg create --build-type ament_cmake custom_msgs

创建自定义消息

这里我的自定义消息内容如下:

custom_msgs/msg/MotCmd.msg

# type: 1 on MoveL, 2 on MoveR, 3 on MoveCint64 type
Pose[] pose_arr
float64 velocity
float64 acceleration

custom_msgs/msg/Pose.msg

float64 x
float64 y
float64 z
float64 qw
float64 qx
float64 qy
float64 qz

custom_msgs/msg/ShapeBox.msg

Pose center
float64 l
float64 w
float64 h

custom_msgs/srv/PlannerPlanPath.srv

Pose start_pose
Pose target_pose
ShapeBox robot
ShapeBox[] env
---
int64 error_code
MotCmd[] cmd_arr

修改CMakeLists.txt和package.xm进行编译适配

custom_msgs/CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(custom_msgs)# 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)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)rosidl_generate_interfaces(custom_msgssrv/PlannerPlanPath.srvmsg/Pose.msgmsg/ShapeBox.msgmsg/MotCmd.msgDEPENDENCIESbuiltin_interfaces
)install(TARGETSDESTINATION share/${PROJECT_NAME}
)
ament_export_dependencies(rosidl_default_runtime)
# 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()

custom_msgs/package.xml

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3"><name>custom_msgs</name><version>0.0.0</version><description>TODO: Package description</description><maintainer email="root@todo.todo">root</maintainer><license>TODO: License declaration</license><buildtool_depend>ament_cmake</buildtool_depend><member_of_group>rosidl_interface_packages</member_of_group><test_depend>ament_lint_auto</test_depend><test_depend>ament_lint_common</test_depend><depend>builtin_interfaces</depend><depend>rosidl_default_generators</depend><depend>rclpy</depend><export><build_type>ament_cmake</build_type></export>
</package>

编译自定义消息

colcon build --packages-select custom_msgs –symlink-install

编译成功后能看到提示

编译ros bridge

source /opt/ros/noetic/setup.bash

source /opt/ros/foxy/setup.bash

source catkin_ws/devel/setup.bash

source colcon_ws/install/setup.bash

colcon build --packages-select ros1_bridge --cmake-force-configure

source /opt/ros/noetic/setup.bash

source /opt/ros/foxy/setup.bash

source catkin_ws/devel/setup.bash

source colcon_ws/install/setup.bash

source install/setup.bash

ros2 run ros1_bridge dynamic_bridge --print-pairs | grep custom_msgs

ros2 run ros1_bridge dynamic_bridge

可以成功看到bridge被运行,并且能桥接我们想要的数据类型!

编译问题汇总

cmake版本不匹配

这里我使用的是3.12版本cmake

wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
./configure --prefix=/usr/local/cmake
make && make install
rm -rf /usr/bin/cmake
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
cmake --version

能看到版本号显示3.12版本

ros2编译,colon环境缺失

colon build时提示colon not found 需要安装colon环境

执行sudo apt install python3-colcon-common-extensions安装,如果遇到以下报错则可以这样解决:

sudo sh -c ‘. /etc/lsb-release && echo “deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ lsb_release -cs main” > /etc/apt/sources.list.d/ros-latest.list’

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

sudo apt update

随后执行sudo apt install python3-colcon-common-extensions

重新安装colcon

em和empy环境冲突

错误提示如下,原因是empy和em都是使用import em引入,而我们真正要使用的是empy

执行以下命令解决:

pip uninstall em
pip3 install empy==3.3.4
pip3 install lark

rospkg安装

pip3 install rospkg

打包dynamic bridge到其他板卡

http://www.dtcms.com/a/491182.html

相关文章:

  • 修复ubuntu22.04检测不到mt7922蓝牙问题
  • C#共用体
  • 正点原子RK3568学习日志7-module_init优先级
  • 脑机接口:BCI2000框架,EEG信号解码?
  • 2025“芯星计划”华中区域启动暨长沙民政加速科技集成电路测试验证实践基地揭牌仪式圆满收官
  • 一般的学校网站怎么做网站主要的设计内容主题
  • docker后端jar包本地构建镜像
  • Spring Boot 3零基础教程,Spring Boot 日志的归档与切割,笔记22
  • 序列化的几种常见方式
  • 蜜罐技术重塑网络安全新格局
  • 做网站需要用到的符号语言基于网站开发的app
  • 企业管理咨询网站gta买办公室网站建设中
  • Python 的 typing 库介绍
  • 33. C++ cout cin 文件IO
  • 腾讯地图时空智能开放平台MCP接入说明
  • 10.15考研笔记
  • 计算机操作系统文件管理——文件系统挂载
  • ForkJoinPool 核心的任务分配与执行
  • 沧州网站改版优化app的制作需要多少钱
  • 提示词工程优化
  • 小程序商城开源最新seo新手教程
  • Android Studio USB串口通信
  • 数据结构的复习(1):
  • Python爬虫第5课:正则表达式与数据清洗技术
  • 自己做背景的网站app商城软件
  • 网页网站模板2023重大新闻事件10条
  • h5游戏免费下载:极限超车
  • Linux之认识理解目录
  • HarmonyOS Next 学习文档总览 [特殊字符]
  • 织梦微信网站模板wordpress4.9.4漏洞