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

相关文章

Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单

《Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单》:本文主要介绍Springboot的ThreadPoolTaskScheduler线... 目录ThreadPoolTaskScheduler线程池实现15分钟不操作自动取消订单概要1,创建订单后

python使用watchdog实现文件资源监控

《python使用watchdog实现文件资源监控》watchdog支持跨平台文件资源监控,可以检测指定文件夹下文件及文件夹变动,下面我们来看看Python如何使用watchdog实现文件资源监控吧... python文件监控库watchdogs简介随着Python在各种应用领域中的广泛使用,其生态环境也

el-select下拉选择缓存的实现

《el-select下拉选择缓存的实现》本文主要介绍了在使用el-select实现下拉选择缓存时遇到的问题及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录项目场景:问题描述解决方案:项目场景:从左侧列表中选取字段填入右侧下拉多选框,用户可以对右侧

SpringCloud集成AlloyDB的示例代码

《SpringCloud集成AlloyDB的示例代码》AlloyDB是GoogleCloud提供的一种高度可扩展、强性能的关系型数据库服务,它兼容PostgreSQL,并提供了更快的查询性能... 目录1.AlloyDBjavascript是什么?AlloyDB 的工作原理2.搭建测试环境3.代码工程1.

Java调用Python代码的几种方法小结

《Java调用Python代码的几种方法小结》Python语言有丰富的系统管理、数据处理、统计类软件包,因此从java应用中调用Python代码的需求很常见、实用,本文介绍几种方法从java调用Pyt... 目录引言Java core使用ProcessBuilder使用Java脚本引擎总结引言python

Java中ArrayList的8种浅拷贝方式示例代码

《Java中ArrayList的8种浅拷贝方式示例代码》:本文主要介绍Java中ArrayList的8种浅拷贝方式的相关资料,讲解了Java中ArrayList的浅拷贝概念,并详细分享了八种实现浅... 目录引言什么是浅拷贝?ArrayList 浅拷贝的重要性方法一:使用构造函数方法二:使用 addAll(

Python pyinstaller实现图形化打包工具

《Pythonpyinstaller实现图形化打包工具》:本文主要介绍一个使用PythonPYQT5制作的关于pyinstaller打包工具,代替传统的cmd黑窗口模式打包页面,实现更快捷方便的... 目录1.简介2.运行效果3.相关源码1.简介一个使用python PYQT5制作的关于pyinstall

使用Python实现大文件切片上传及断点续传的方法

《使用Python实现大文件切片上传及断点续传的方法》本文介绍了使用Python实现大文件切片上传及断点续传的方法,包括功能模块划分(获取上传文件接口状态、临时文件夹状态信息、切片上传、切片合并)、整... 目录概要整体架构流程技术细节获取上传文件状态接口获取临时文件夹状态信息接口切片上传功能文件合并功能小

python实现自动登录12306自动抢票功能

《python实现自动登录12306自动抢票功能》随着互联网技术的发展,越来越多的人选择通过网络平台购票,特别是在中国,12306作为官方火车票预订平台,承担了巨大的访问量,对于热门线路或者节假日出行... 目录一、遇到的问题?二、改进三、进阶–展望总结一、遇到的问题?1.url-正确的表头:就是首先ur

C#实现文件读写到SQLite数据库

《C#实现文件读写到SQLite数据库》这篇文章主要为大家详细介绍了使用C#将文件读写到SQLite数据库的几种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录1. 使用 BLOB 存储文件2. 存储文件路径3. 分块存储文件《文件读写到SQLite数据库China编程的方法》博客中,介绍了文