写在前面
用以前的设置,快速配置项目,以防长久不用忘记,部分资料在资源文件里还没有整理
outline
- cmakelist 复用
- vscode 找到头文件
- vscode debug
- 现有代码直接关联远端git
- ros杂记
- repo 杂记
- glog杂记
update
- 12 22 更新了复用的cmaklist,加入了手动找库的两种方式
- 用 include dir 和 add library直接add 顺便把yaml写进取以后我写工程直接复制
- set 一个宏
cmakelist 复用
包含了根据系统路径找库,debug,主动set库路径,单元测试用,和常用的加入头文件与源文件
xml
cmake_minimum_required(VERSION 3.14.1)
project(project_Planner)
set( CMAKE_CXX_STANDARD 11 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( THREADS_PREFER_PTHREAD_FLAG ON )
function(include_sub_directories_recursively root_dir)
if (IS_DIRECTORY ${root_dir})
include_directories(${root_dir})
file(GLOB children RELATIVE ${root_dir} ${root_dir}/*)
foreach(child ${children})
if (IS_DIRECTORY ${root_dir}/${child})
include_sub_directories_recursively(${root_dir}/${child})
endif()
endforeach()
endif()
endfunction()
function(aux_source_directory_recursively root_dir var_name)
if(IS_DIRECTORY ${root_dir})
aux_source_directory(${root_dir} TMP_SRC_LIST)
set(${var_name} ${${var_name}} ${TMP_SRC_LIST} PARENT_SCOPE)
file(GLOB children RELATIVE ${root_dir} ${root_dir}/*)
foreach(child ${children})
if(IS_DIRECTORY ${root_dir}/${child})
aux_source_directory_recursively(${root_dir}/${child} ${var_name})
endif()
endforeach()
endif()
endfunction()
find_package(glog REQUIRED)
find_package(Eigen3 REQUIRED)
#find_package(osqp REQUIRED )
find_package(OsqpEigen REQUIRED)
find_package(yaml-cpp REQUIRED)
Set(GLOG_INCLUDE_DIRS "/usr/include/glog/")
Set(GLOG_LIBRARIES "/usr/lib/x86_64-linux-gnu/libglog.so")
#Set(GLOG_LIBRARIES "/usr/local/lib/libglog.so")
# message(STATUS "GLOG_INCLUDE_DIRS: ${GLOG_INCLUDE_DIR}")
# message(STATUS "GLOG_LIBRARIES: ${GLOG_LIBRARIES}")
# message(STATUS "EIGEN3_INCLUDE_DIR: ${EIGEN3_INCLUDE_DIR}")
# message(STATUS "EIGEN3_LIBRARIES: ${EIGEN3_LIBRARIES}")
# message(STATUS "osqp_INCLUDE_DIR: ${osqp_INCLUDE_DIR}")
# message(STATUS "osqp_LIBRARIES: ${osqp_LIBRARIES}")
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRC_LIST)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/. SRC_LIST)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/commen/. SRC_LIST)
#aux_source_directory_recursively(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_LIST)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/libs)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/src)
##############################debug start##############################
get_property(include_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${include_dirs})
message("Include directory: ${dir}")
endforeach()
message("Source files:")
foreach(file IN LISTS SRC_LIST)
message(" ${file}")
endforeach()
#################################debug end####################################
include_directories(${GLOG_INCLUDE_DIRS})
include_directories(${EIGEN3_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${SRC_LIST})
#add_library(${PROJECT_NAME} STATIC ${SRC_LIST}) # temp use
target_include_directories(${PROJECT_NAME} PRIVATE ${GLOG_INCLUDE_DIRS})
#target_include_directories(${PROJECT_NAME} PRIVATE ${OSQP_INCLUDE_DIRS})
#target_link_libraries(${PROJECT_NAME} OsqpEigen::OsqpEigen)
target_link_libraries(${PROJECT_NAME} PRIVATE ${GLOG_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${EIGEN3_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp)
# link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/yaml-cpp/)# for all
# target_link_libraries(${PROJECT_NAME} PRIVATE libyaml-cpp.a)
#target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libs/yaml-cD/libyaml-cD.a)
#target_link_libraries(${PROJECT_NAME} PRIVATE osqp::osqp)
#####################################unit test ###################################
# add_executable(unit_test_pathFW ${SRC_LIST})
# target_link_libraries( unit_test_pathFW
# ${GLOG_LIBRARIES}
# # ${CMAKE_CURRENT_SOURCE_DIR}/libs/yaml-cD/libyaml-cD.a
# ${CMAKE_CURRENT_SOURCE_DIR}/libs/yaml-cD/libyaml-cD.a
# # yaml-cD
# )
#####################################unit test end#################################
备注:target_include_directories 用于为特定目标设置包含目录,而 include_directories 用于设置项目中所有目标的全局包含目录,add_library为直接加入库路径
这里写了更多find package 找不到库的细节处理https://blog.csdn.net/weixin_46479223/article/details/135153942
vscode 找头文件
之前使用visual studio 感觉在这一点上 更方便,如果vscode 要配置一下 。
新建:c_cpp_properties.json 或者 ctrl +shift+ p在设置中查找 configuration (json),但也可以ui方式直接设置
xml
{
"configurations": [
{
"browse": {
"databaseFilename": "${default}",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/home/kaifengqu/Desktop/H06CodeinROSEnv/devel/include/**",
"/opt/ros/noetic/include/**",
"/home/kaifengqu/Desktop/H06CodeinROSEnv/src/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14"
}
],
"version": 4
}
vscode debug
xml
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build_t/project_MPtest
",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
# 使用ros的方式
1 Vscode 安装ros插件 还是需要添加一下launch配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ROS: Attach",
"type": "ros",
"request": "attach"
}
]
}
2设置断点,运行节点,回放数据
3使用调试与运行中 ROS Attach 查找ID 或进程名称,将可执行文件(NODE)附加到进程里。
如果不是用ros(有一个问题无法暂停数据的播放)也要配置debuggdb
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/project_PPconrtoller",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
现有代码直接关联远端git
bash
echo "# Scripts" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main # 改不改名字都可以
git remote add origin git@github.com:HerrQQ/Scripts.git # 从git复制
git push -u origin main # 如果不着急推送 就git branch -u origin/master
# 完事了 git remote -v 䁖一眼
ros 杂记
xml
脚本更改
rosrun pilot_controller modifyForRos.py
分析工具
rosrun plotjuggler plotjuggler
记录
rosbag record -O recorded_data -a
启动节点
roslaunch pilot_controller pilot_controller_ha1.launch
找节点关闭
pidof program_name
pkill -f feishu
回放
rqt_bag
编译
catkin_make -j4 -DCMAKE_BUILD_TYPE=Debug
plotjuggler缺东西问题
使用sudo apt install ros-noetic-plotjuggler-ros一键安装plotjuggler及其ros插件
repo 杂记
https://blog.csdn.net/weixin_48120109/article/details/128272613 讲解repo具体用法
https://blog.csdn.net/KIK9973/article/details/118755045 haoyong nice to use
xml
1. 初始化: 使用 repo init 命令初始化 repo,在后面添加 -u 参数,并指明源的 URL。例如:
repo init -u https://android.googlesource.com/platform/manifest
可以添加 -b 参数来切换到不同的分支,比如 -b android-4.0.1_r1。
同步: 使用 repo sync 命令将所有相关的 git 仓库同步到本地。可以添加 仓库名 参数来单独同步某一个仓库,否则默认同步全部。例如:
repo sync
同步特定仓库:
repo sync project_name
查看状态:使用 repo status 命令来查看所有 git 仓库的状态。
开始工作: 在开始对任何仓库做出修改之前,建议先使用 repo start 创建一个新的分支:
repo start my_branch my_project
1. 提交: 分别在每个 git 仓库中添加和提交更改,然后使用 repo upload 上传更改。
更多关于 repo 使用的命令和详细说明,可以通过在控制台输入 repo -h 查看。
Glog杂记
cpp
google::InitGoogleLogging(argv[0]);
google::SetStderrLogging(google::GLOG_ERROR);
FLAGS_colorlogtostderr = true;
FLAGS_logtostderr = false; // 将日志输出到日志文件
FLAGS_minloglevel = 2; // 设置最小日志级别为 ERROR
FLAGS_log_dir = "/path/to/logs"; // 设置日志文件的输出目录