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

相关文章

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

在 Spring Boot 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

Python位移操作和位运算的实现示例

《Python位移操作和位运算的实现示例》本文主要介绍了Python位移操作和位运算的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 位移操作1.1 左移操作 (<<)1.2 右移操作 (>>)注意事项:2. 位运算2.1

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依