Skip to content

Commit

Permalink
🎨 style: format
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryZhuHR committed Nov 13, 2023
1 parent 6a13fb1 commit 7d87b05
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 304 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BraceWrapping:
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
Expand All @@ -97,7 +97,7 @@ BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true

# === 每行字符的限制,0表示没有限制 ===
# ColumnLimit: 200
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false

Expand Down
57 changes: 9 additions & 48 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
{
"configurations": [
{
"name": "ROS2_Darwin",
"browse": {
"databaseFilename": "${default}",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
// ROS 不同版本的路径不一样
// "/opt/ros/humble/include/**",
"/Users/henryzhu/mambaforge/envs/ros2_humble/include",
// 第三方库
"/usr/include/opencv4",
"libs/jsoncpp/include",
// 接口头文件
// "install/state_interfaces/include/state_interfaces",
"install/state_interfaces/include",
//
"modules/common/system_state/include",
"modules/common/base_node/include",
//
"core/controller/motion_controller/serial/include",
"core/controller/motion_controller/include",
//
"core/manager/system_manager/include",
//
"modules/video_streamer_cpp/include"
],
"defines": [
"DEBUG"
],
"intelliSenseMode": "linux-gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14"
},
{
"name": "ROS",
"browse": {
Expand All @@ -43,32 +8,28 @@
},
"includePath": [
// ROS 不同版本的路径不一样
// "/opt/ros/humble/include/**",
"/opt/ros/galactic/include/",
"/opt/ros/humble/include/**",
// 第三方库
"/usr/include/opencv4",
// "/usr/include/opencv4",
"libs/jsoncpp/include",
// 接口头文件
// "install/state_interfaces/include/state_interfaces",
"install/state_interfaces/include",
"install/state_interfaces/include/state_interfaces",
//
"modules/common/system_state/include",
"modules/common/base_node/include",
//
"core/controller/motion_controller/serial/include",
"core/controller/motion_controller/include",
//
"core/manager/system_manager/include",
"core/base/base_node/include",
//
"modules/video_streamer_cpp/include"
"modules/video_streamer_cpp/include",
"modules/common/system_state/include"
],
"defines": [
"DEBUG"
],
"intelliSenseMode": "linux-gcc-x64",
"intelliSenseMode": "gcc-arm64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14"
"cppStandard": "c++14",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
Expand Down
42 changes: 25 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"clangd.arguments": [
"--background-index",
"--compile-commands-dir=build",
"--query-driver=/usr/bin/clang++",
"-j=8",
"--clang-tidy",
"--all-scopes-completion",
"--completion-style=detailed",
],
"ros.distro": "humble",
"python.autoComplete.extraPaths": [
"install/interfaces/lib/python3.8/site-packages",
"install/state_interfaces/lib/python3.8/site-packages",
"modules/common/system_state_py",
"modules/common/base_node_py/base_node",
"/opt/ros/galactic/lib/python3.8/site-packages",
"/opt/ros/humble/lib/python3.10/site-packages"
"/opt/ros/humble/lib/python3.10/site-packages",
"install/interfaces/lib/python3.10/site-packages",
"install/state_interfaces/lib/python3.10/site-packages",
"core/manager/system_state_py/system_manager",
"core/base/base_node_py/base_node",
"modules/common/system_state_py"
],
"python.analysis.extraPaths": [
"install/interfaces/lib/python3.8/site-packages",
"install/state_interfaces/lib/python3.8/site-packages",
"/opt/ros/humble/lib/python3.10/site-packages",
"install/interfaces/lib/python3.10/site-packages",
"install/state_interfaces/lib/python3.10/site-packages",
"core/manager/system_state_py/system_manager",
"core/base/base_node_py/base_node",
"modules/common/system_state_py",
"modules/common/base_node_py/base_node",
"/opt/ros/galactic/lib/python3.8/site-packages",
"/opt/ros/humble/lib/python3.10/site-packages"

],
"ros.distro": "humble",
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build",
"--query-driver=/usr/bin/clang,/usr/bin/c++",
],
"files.associations": {
"string": "cpp"
},
"cmake.configureOnOpen": true,
}
26 changes: 12 additions & 14 deletions modules/common/node_template/app/node_template.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <rclcpp/rclcpp.hpp>
#include "base_node/base_node.hpp"

int main(int argc, char **argv)
{
int main(int argc, char** argv) {
rclcpp::init(argc, argv);
auto node = std::make_shared<BaseNode>("base_node"); // 设置节点名称

Expand All @@ -13,23 +12,22 @@ int main(int argc, char **argv)
* 参考 `SystemState::StateGroup` 和 `SystemState::StateID`
*/
auto init_error = node->InitNode(
static_cast<uint8_t>(SystemState::StateGroup::SENSOR), // 分组为传感器
static_cast<uint8_t>(SystemState::StateGroup::SENSOR), // 分组为传感器
static_cast<uint8_t>(SystemState::StateID::Sensor::JOY) // ID为手柄
);

if (init_error == 0)
{
RCLCPP_INFO(node->get_logger(), "%s[INIT NODE] Successfully init:%s %s", //
SystemState::Color::LGREEN, SystemState::Color::DEFAULT, //
if (init_error == 0) {
RCLCPP_INFO(node->get_logger(),
"%s[INIT NODE] Successfully init:%s %s", //
SystemState::Color::LGREEN, SystemState::Color::DEFAULT, //
node->get_name());
rclcpp::spin(node);
}
else
{
RCLCPP_FATAL(node->get_logger(), "%s[INIT NODE] Init Node Error (%ld)%s. Please Check Group and id in \"InitNode()\"", //
SystemState::Color::LRED, //
init_error,
SystemState::Color::DEFAULT);
} else {
RCLCPP_FATAL(node->get_logger(),
"%s[INIT NODE] Init Node Error (%ld)%s. Please Check "
"Group and id in \"InitNode()\"", //
SystemState::Color::LRED, //
init_error, SystemState::Color::DEFAULT);
}
rclcpp::shutdown();
return 0;
Expand Down
10 changes: 9 additions & 1 deletion modules/common/system_state/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.20)
project(system_state)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
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(rclcpp REQUIRED)
Expand Down
89 changes: 44 additions & 45 deletions modules/common/system_state/include/system_state/error_code.hpp
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
#ifndef COMMON__SYSTEM_STATE__ERROR_CODE_HPP
#define COMMON__SYSTEM_STATE__ERROR_CODE_HPP

namespace SystemState
{
/**
* @brief 错误码 (uint64_t)
*/
enum class ErrorCode : uint64_t
{
NO_ERROR = 0, // 没有错误
STATE_UPDATE_GROUP_OVERFLOW, // 系统状态更新时,分组超出范围
STATE_UPDATE_GROUP_NOT_FOUND, // 系统状态更新时,未找到对应的状态分组
STATE_UPDATE_ID_OVERFLOW, // 系统状态更新时,状态ID超出范围
STATE_UPDATE_ID_NOT_FOUND, // 系统状态更新时,未找到对应的状态
#include <cstdint>
namespace SystemState {
/**
* @brief 错误码 (uint64_t)
*/
enum class ErrorCode : uint64_t {
NO_ERROR = 0, // 没有错误
STATE_UPDATE_GROUP_OVERFLOW, // 系统状态更新时,分组超出范围
STATE_UPDATE_GROUP_NOT_FOUND, // 系统状态更新时,未找到对应的状态分组
STATE_UPDATE_ID_OVERFLOW, // 系统状态更新时,状态ID超出范围
STATE_UPDATE_ID_NOT_FOUND, // 系统状态更新时,未找到对应的状态

// 文件相关错误码
FILE_NOT_FOUND, // 文件未找到
// 文件相关错误码
FILE_NOT_FOUND, // 文件未找到

// 解析配置错误码
CONFIG__KEY_NOT_FOUND, // 配置文件中未找到对应的key
// 解析配置错误码
CONFIG__KEY_NOT_FOUND, // 配置文件中未找到对应的key

// ROS相关错误
ROS_RCLCPP_NOT_INIT, // ROS rclcpp未初始化
// ROS相关错误
ROS_RCLCPP_NOT_INIT, // ROS rclcpp未初始化

// 串口相关错误码
SERIAL_PORT_NOT_FOUND, // 串口未找到
SERIAL_OPEN_FAILED, // 串口打开失败
SERIAL_WRITE_FAILED, // 串口写入失败
SERIAL_READ_FAILED, // 串口读取失败
SERIAL_TIMEOUT, // 串口超时
SERIAL_DATA_ERROR, // 串口数据错误
SERIAL_DATA_LENGTH_ERROR, // 串口数据长度错误
SERIAL_DATA_CRC_ERROR, // 串口数据CRC校验错误
SERIAL_DATA_ID_ERROR, // 串口数据ID错误
SERIAL_DATA_TYPE_ERROR, // 串口数据类型错误
SERIAL_DATA_VALUE_ERROR, // 串口数据值错误
SERIAL_DATA_NOT_FOUND, // 串口数据未找到
SERIAL_DATA_NOT_INIT, // 串口数据未初始化
SERIAL_DATA_NOT_SUPPORT, // 串口数据不支持
SERIAL_DATA_NOT_MATCH, // 串口数据不匹配
SERIAL_DATA_NOT_ENOUGH, // 串口数据不足
SERIAL_DATA_OVERFLOW, // 串口数据溢出
SERIAL_DATA_NOT_READY, // 串口数据未准备好
SERIAL_DATA_NOT_OPEN, // 串口数据未打开
SERIAL_DATA_NOT_CONNECTED, // 串口数据未连接
SERIAL_DATA_NOT_CONFIGURED, // 串口数据未配置
SERIAL_DATA_NOT_STARTED, // 串口数据未启动
SERIAL_DATA_NOT_STOPPED, // 串口数据未停止
SERIAL_UNKOOWN_ERROR, // 串口未知错误
};
}
// 串口相关错误码
SERIAL_PORT_NOT_FOUND, // 串口未找到
SERIAL_OPEN_FAILED, // 串口打开失败
SERIAL_WRITE_FAILED, // 串口写入失败
SERIAL_READ_FAILED, // 串口读取失败
SERIAL_TIMEOUT, // 串口超时
SERIAL_DATA_ERROR, // 串口数据错误
SERIAL_DATA_LENGTH_ERROR, // 串口数据长度错误
SERIAL_DATA_CRC_ERROR, // 串口数据CRC校验错误
SERIAL_DATA_ID_ERROR, // 串口数据ID错误
SERIAL_DATA_TYPE_ERROR, // 串口数据类型错误
SERIAL_DATA_VALUE_ERROR, // 串口数据值错误
SERIAL_DATA_NOT_FOUND, // 串口数据未找到
SERIAL_DATA_NOT_INIT, // 串口数据未初始化
SERIAL_DATA_NOT_SUPPORT, // 串口数据不支持
SERIAL_DATA_NOT_MATCH, // 串口数据不匹配
SERIAL_DATA_NOT_ENOUGH, // 串口数据不足
SERIAL_DATA_OVERFLOW, // 串口数据溢出
SERIAL_DATA_NOT_READY, // 串口数据未准备好
SERIAL_DATA_NOT_OPEN, // 串口数据未打开
SERIAL_DATA_NOT_CONNECTED, // 串口数据未连接
SERIAL_DATA_NOT_CONFIGURED, // 串口数据未配置
SERIAL_DATA_NOT_STARTED, // 串口数据未启动
SERIAL_DATA_NOT_STOPPED, // 串口数据未停止
SERIAL_UNKOOWN_ERROR, // 串口未知错误
};
} // namespace SystemState

#endif // COMMON__SYSTEM_STATE__ERROR_CODE_HPP
15 changes: 7 additions & 8 deletions modules/common/system_state/include/system_state/services.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

#include <string>

namespace SystemState
{
namespace services
{
const std::string update_state = "__server__update_system_state"; // 系统状态更新的服务名称
} // namespace services

} // namespace system_state
namespace SystemState {
namespace services {
// clang-format off
const std::string update_state = "__server__update_system_state"; // 系统状态更新的服务名称
// clang-format on
} // namespace services
} // namespace SystemState
#endif // COMMON__SYSTEM_STATE__SERVICES_HPP
Loading

0 comments on commit 7d87b05

Please sign in to comment.