ROS2快速实现ament_lint_auto自动代码审查

2024-03-08 06:04

本文主要是介绍ROS2快速实现ament_lint_auto自动代码审查,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

ROS2快速实现ament_lint_auto自动代码审查

文章目录

  • 前言
  • 正文
    • 参考CMakeLists.txt
    • 参数说明
    • 编译及测试
    • 代码格式化不符合要求报警
  • 总结

前言

本文用来记录ROS2 ament_cmake如何快速实现代码自动审查测试。

正文

参考CMakeLists.txt

源代码在gitee代码库,地址如下**Bing Lee / Learn Ros2 Moveit**

cmake_minimum_required(VERSION 3.8)
project(ros2_control_demo_example_5)if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")add_compile_options(-Wall -Wextra -Wpedantic)
endif()# find dependencies
set(THIS_PACKAGE_INCLUDE_DEPENDShardware_interfacepluginlibrclcpprclcpp_lifecycle
)# find dependencies
find_package(ament_cmake REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)## COMPILE
add_library(ros2_control_demo_example_5SHAREDhardware/external_rrbot_force_torque_sensor.cpphardware/rrbot.cpp
)
target_compile_features(ros2_control_demo_example_5 PUBLIC cxx_std_17)
target_include_directories(ros2_control_demo_example_5 PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/hardware/include>
$<INSTALL_INTERFACE:include/ros2_control_demo_example_5>
)
ament_target_dependencies(ros2_control_demo_example_5 PUBLIC${THIS_PACKAGE_INCLUDE_DEPENDS}
)# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROS2_CONTROL_DEMO_EXAMPLE_5_BUILDING_DLL")# Export hardware plugins
pluginlib_export_plugin_description_file(hardware_interface ros2_control_demo_example_5.xml)# INSTALL
install(DIRECTORY hardware/include/DESTINATION include/ros2_control_demo_example_5
)
install(DIRECTORY description/launch description/ros2_control description/urdf description/rvizDESTINATION share/ros2_control_demo_example_5
)
install(DIRECTORY bringup/launch bringup/configDESTINATION share/ros2_control_demo_example_5
)
install(TARGETS ros2_control_demo_example_5EXPORT export_ros2_control_demo_example_5ARCHIVE DESTINATION libLIBRARY DESTINATION libRUNTIME DESTINATION bin
)if(BUILD_TESTING)find_package(ament_lint_auto REQUIRED)set(ament_cmake_uncrustify_FOUND TRUE)set(ament_cmake_xmllint_FOUND TRUE)ament_lint_auto_find_test_dependencies()
endif()## EXPORTS
ament_export_targets(export_ros2_control_demo_example_5 HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()

参数说明

# CMakeLists.txtif(BUILD_TESTING)## 配置自动检测find_package(ament_lint_auto REQUIRED)## 忽略uncrustify错误set(ament_cmake_uncrustify_FOUND TRUE)## 忽略xmllint错误set(ament_cmake_xmllint_FOUND TRUE)## 自动查找匹配文件并testament_lint_auto_find_test_dependencies()
endif()
<?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>ros2_control_demo_example_5</name><version>0.0.0</version><description>TODO: Package description</description><maintainer email="lilinxin75@gmail.com">Bing Lee</maintainer><url type="website">https://blog.csdn.net/Bing_Lee</url><license>TODO: License declaration</license><buildtool_depend>ament_cmake</buildtool_depend><depend>hardware_interface</depend><depend>pluginlib</depend><depend>rclcpp</depend><depend>rclcpp_lifecycle</depend><exec_depend>controller_manager</exec_depend><exec_depend>forward_command_controller</exec_depend><exec_depend>joint_state_broadcaster</exec_depend><exec_depend>joint_state_publisher_gui</exec_depend><exec_depend>robot_state_publisher</exec_depend><exec_depend>ros2_control_demo_description</exec_depend><exec_depend>ros2_controllers_test_nodes</exec_depend><exec_depend>ros2controlcli</exec_depend><exec_depend>ros2launch</exec_depend><exec_depend>rviz2</exec_depend><exec_depend>xacro</exec_depend><!-- 下边这两个是必须要加上的 --><test_depend>ament_lint_common</test_depend><test_depend>ament_lint_auto</test_depend><export><build_type>ament_cmake</build_type></export>
</package>

编译及测试

# 编译目标程序
colcon build --packages-up-to ros2_control_demo_example_5 # 自动测试目标程序
colcon test --packages-up-to ros2_control_demo_example_5

日志会自动生成在本地log文件中。

代码格式化不符合要求报警

[0.950508] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: 2 files with code style divergence\n'}
[0.950534] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: No code style divergence in file 'hardware/include/ros2_control_demo_example_5/external_rrbot_force_torque_sensor.hpp'\n"}
[0.950559] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: \n'}
[0.950585] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: No code style divergence in file 'hardware/include/ros2_control_demo_example_5/rrbot.hpp'\n"}
[0.950609] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: \n'}
[0.950634] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: No code style divergence in file 'hardware/include/ros2_control_demo_example_5/visibility_control.h'\n"}
[0.950661] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: \n'}
[0.953409] (ros2_control_demo_example_5) StdoutLine: {'line': b'7: -- run_test.py: return code 1\n'}
[0.953489] (ros2_control_demo_example_5) StdoutLine: {'line': b"7: -- run_test.py: verify result file '/home/dev/workspace/learn_ros_moveit/build/ros2_control_demo_example_5/test_results/ros2_control_demo_example_5/uncrustify.xunit.xml'\n"}
# ============================== 错误1 ============================
[0.958686] (ros2_control_demo_example_5) StdoutLine: {'line': b'7/8 Test #7: uncrustify .......................***Failed    0.10 sec\n'}
...
[1.616985] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: File 'package.xml' is invalid:\n"}
[1.617088] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: /home/dev/workspace/learn_ros_moveit/ros2_control_demos/ros2_control_demo_example_5/package.xml:8: element url: Schemas validity error : Element 'url': This element is not expected. Expected is one of ( maintainer, license ).\n"}
[1.617126] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: /home/dev/workspace/learn_ros_moveit/ros2_control_demos/ros2_control_demo_example_5/package.xml fails to validate\n'}
[1.617158] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: \n'}
[1.617187] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: 1 files are invalid\n'}
[1.617216] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: File 'ros2_control_demo_example_5.xml' is valid\n"}
[1.617243] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: \n'}
[1.633089] (ros2_control_demo_example_5) StdoutLine: {'line': b'8: -- run_test.py: return code 1\n'}
[1.633246] (ros2_control_demo_example_5) StdoutLine: {'line': b"8: -- run_test.py: verify result file '/home/dev/workspace/learn_ros_moveit/build/ros2_control_demo_example_5/test_results/ros2_control_demo_example_5/xmllint.xunit.xml'\n"}
# ============================== 错误2 ============================
[1.644917] (ros2_control_demo_example_5) StdoutLine: {'line': b'8/8 Test #8: xmllint ..........................***Failed    0.69 sec\n'}
[1.645272] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}
[1.645510] (ros2_control_demo_example_5) StdoutLine: {'line': b'75% tests passed\x1b[0;0m, \x1b[0;31m2 tests failed\x1b[0;0m out of 8\n'}
[1.645693] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}
[1.645774] (ros2_control_demo_example_5) StdoutLine: {'line': b'Label Time Summary:\n'}
[1.645848] (ros2_control_demo_example_5) StdoutLine: {'line': b'copyright     =   0.18 sec*proc (1 test)\n'}
[1.645916] (ros2_control_demo_example_5) StdoutLine: {'line': b'cppcheck      =   0.09 sec*proc (1 test)\n'}
[1.645985] (ros2_control_demo_example_5) StdoutLine: {'line': b'cpplint       =   0.17 sec*proc (1 test)\n'}
[1.646055] (ros2_control_demo_example_5) StdoutLine: {'line': b'flake8        =   0.15 sec*proc (1 test)\n'}
[1.646124] (ros2_control_demo_example_5) StdoutLine: {'line': b'lint_cmake    =   0.08 sec*proc (1 test)\n'}
[1.646192] (ros2_control_demo_example_5) StdoutLine: {'line': b'linter        =   1.56 sec*proc (8 tests)\n'}
[1.646271] (ros2_control_demo_example_5) StdoutLine: {'line': b'pep257        =   0.11 sec*proc (1 test)\n'}
[1.646341] (ros2_control_demo_example_5) StdoutLine: {'line': b'uncrustify    =   0.10 sec*proc (1 test)\n'}
[1.646411] (ros2_control_demo_example_5) StdoutLine: {'line': b'xmllint       =   0.69 sec*proc (1 test)\n'}
[1.646479] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}
[1.646550] (ros2_control_demo_example_5) StdoutLine: {'line': b'Total Test time (real) =   1.56 sec\n'}
[1.646622] (ros2_control_demo_example_5) StdoutLine: {'line': b'\n'}[1.646690] (ros2_control_demo_example_5) StdoutLine: {'line': b'The following tests FAILED:\n'}
# ============================== 错误1 ============================
[1.646761] (ros2_control_demo_example_5) StdoutLine: {'line': b'\t\x1b[0;31m  7 - uncrustify (Failed)\x1b[0;0m\n'}
# ============================== 错误2 ============================
[1.646836] (ros2_control_demo_example_5) StdoutLine: {'line': b'\t\x1b[0;31m  8 - xmllint (Failed)\x1b[0;0m\n'}
[1.673562] (ros2_control_demo_example_5) StderrLine: {'line': b'Errors while running CTest\n'}
[1.674189] (ros2_control_demo_example_5) StderrLine: {'line': b'Output from these tests are in: /home/dev/workspace/learn_ros_moveit/build/ros2_control_demo_example_5/Testing/Temporary/LastTest.log\n'}
[1.674550] (ros2_control_demo_example_5) StderrLine: {'line': b'Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.\n'}
[1.679593] (ros2_control_demo_example_5) CommandEnded: {'returncode': 8}
[1.682088] (ros2_control_demo_example_5) TestFailure: {'identifier': 'ros2_control_demo_example_5'}
[1.682270] (ros2_control_demo_example_5) JobEnded: {'identifier': 'ros2_control_demo_example_5', 'rc': 0}
[1.683575] (-) EventReactorShutdown: {}

总结

本文提供一种在ROS2 程序ament_cmakeCI编译时自动自动审查测试的方法,也可以单独设置ament_cmake_pycodestyle ament_cmake_cppcheck ament_cmake_clang_format ament_cmake_flake8 ...1,其中还有有一些规范设置等参数,感兴趣的朋友可以自行研究。


  1. Github/ament/ament_lint_auto ↩︎

这篇关于ROS2快速实现ament_lint_auto自动代码审查的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/786253

相关文章

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

电脑桌面文件删除了怎么找回来?别急,快速恢复攻略在此

在日常使用电脑的过程中,我们经常会遇到这样的情况:一不小心,桌面上的某个重要文件被删除了。这时,大多数人可能会感到惊慌失措,不知所措。 其实,不必过于担心,因为有很多方法可以帮助我们找回被删除的桌面文件。下面,就让我们一起来了解一下这些恢复桌面文件的方法吧。 一、使用撤销操作 如果我们刚刚删除了桌面上的文件,并且还没有进行其他操作,那么可以尝试使用撤销操作来恢复文件。在键盘上同时按下“C

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

poj 1258 Agri-Net(最小生成树模板代码)

感觉用这题来当模板更适合。 题意就是给你邻接矩阵求最小生成树啦。~ prim代码:效率很高。172k...0ms。 #include<stdio.h>#include<algorithm>using namespace std;const int MaxN = 101;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int n

Kubernetes PodSecurityPolicy:PSP能实现的5种主要安全策略

Kubernetes PodSecurityPolicy:PSP能实现的5种主要安全策略 1. 特权模式限制2. 宿主机资源隔离3. 用户和组管理4. 权限提升控制5. SELinux配置 💖The Begin💖点点关注,收藏不迷路💖 Kubernetes的PodSecurityPolicy(PSP)是一个关键的安全特性,它在Pod创建之前实施安全策略,确保P