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

相关文章

AJAX请求上传下载进度监控实现方式

《AJAX请求上传下载进度监控实现方式》在日常Web开发中,AJAX(AsynchronousJavaScriptandXML)被广泛用于异步请求数据,而无需刷新整个页面,:本文主要介绍AJAX请... 目录1. 前言2. 基于XMLHttpRequest的进度监控2.1 基础版文件上传监控2.2 增强版多

Redis分片集群的实现

《Redis分片集群的实现》Redis分片集群是一种将Redis数据库分散到多个节点上的方式,以提供更高的性能和可伸缩性,本文主要介绍了Redis分片集群的实现,具有一定的参考价值,感兴趣的可以了解一... 目录1. Redis Cluster的核心概念哈希槽(Hash Slots)主从复制与故障转移2.

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

Mybatis 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

基于SpringBoot+Mybatis实现Mysql分表

《基于SpringBoot+Mybatis实现Mysql分表》这篇文章主要为大家详细介绍了基于SpringBoot+Mybatis实现Mysql分表的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录基本思路定义注解创建ThreadLocal创建拦截器业务处理基本思路1.根据创建时间字段按年进

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片

SpringBoot3实现Gzip压缩优化的技术指南

《SpringBoot3实现Gzip压缩优化的技术指南》随着Web应用的用户量和数据量增加,网络带宽和页面加载速度逐渐成为瓶颈,为了减少数据传输量,提高用户体验,我们可以使用Gzip压缩HTTP响应,... 目录1、简述2、配置2.1 添加依赖2.2 配置 Gzip 压缩3、服务端应用4、前端应用4.1 N

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态