terminate called after throwing an instance of 'spdlog::spdlog_ex'
what(): Failed opening file /home/ch/.ros/log/turtlesim_node_6588_1641176674614.log for writing: Permission denied
위와 같은 에러가 자꾸 떠서 강제로 user로 바꿨다
-- 이렇게 해도 되는지는 모르겠다
ch@ch:~$ cd /home/ch/.ros/
ch@ch:~/.ros$ sudo chown -R $USER:$USER *
ch@ch:~/.ros$ ls -l
total 8
drwxr-xr-x 5 ch ch 4096 Sep 29 15:52 log
-rw------- 1 ch ch 3682 Sep 29 15:53 rospack_cache_11486458967921186402
ch@ch:~/.ros$ ros2 run turtlesim turtlesim_node
[INFO]: Starting turtlesim with node name /turtlesim
[INFO]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]
- 그냥 .ros 폴더 자체를 지우고 다시까는 걸 추천한다
## VSCODE 설정방법
중요 파일
~/.config/Code/User/settings.json
~/robot_ws/.vscode/c_cpp_properties.json
~/robot_ws/.vscode/tasks.json
~/robot_ws/.vscode/launch.json
1. User settings 설정
- ~/.config/Code/User/settings.json 문서와 관련이 있음
- 만들거나 찾기 힘드니깐 F1 >> Preferences: Open Settings (JSON) 으로 들어가서 수정해주자
- settings.json 은 VSCode의 사용자별 글로벌 환경 설정을 지정하는 파일이다. 이 파일에 기술된 설정들은 모든 작업공간(workspace)에서 적용된다.
- ex) 미니맵 사용, 세로 제한 줄 표시, 탭 사이즈 등
- ROS와 관련된 설정은 위 3가지 정도
1) 'ms-iot.vscode-ros'의 '"ros.distro": "foxy"'와 같이 ROS 버전을 지정
2) 'deitry.colcon-helper'의 '"colcon.provideTasks": true'와 같이 colcon이 지원되는 Task를 사용한다는 의미로 지정한다.
3) "files.associations"을 통해 확장자로 알 수 없는 *.repos, *.world, *.xacro 와 같이 ROS에서만 사용되는 파일명을 파일 형식이 무엇인지 명시해주는 설정을 하게된다.
> settings.json
> ~/.config/Code/User/Settins.json
```json
{
"cmake.configureOnOpen": false,
"editor.minimap.enabled": false,
"editor.mouseWheelZoom": true,
"editor.renderControlCharacters": true,
"editor.rulers": [100],
"editor.tabSize": 2,
"files.associations": {
"*.repos": "yaml",
"*.world": "xml",
"*.xacro": "xml"
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"terminal.integrated.scrollback": 1000000,
"workbench.iconTheme": "vscode-icons",
"workbench.editor.pinnedTabSizing": "compact",
"ros.distro": "foxy",
"colcon.provideTasks": true
}
3. Tasks 설정
- bulid 설정에 가면 > tasks.json뜸
4. launch.json
5. build >> ctrl+shift+b
6. ctrl+shift+d : 디버깅
6-1) rclcpp
- Run and Debug (`Ctrl + Shift + d`)로 이동
- "Debug-rclcpp(gbd)" 선택
- "Package name" 입력 (예: topic_service_action_rclcpp_example)
- "node name" 입력 (예: argument)
- Start Debugging 클릭 (`F5`)
6-2) rclpy
- Run and Debug (`Ctrl + Shift + d`)로 이동
- "Debug-rclpy(debugpy)" 선택
- Start Debugging 클릭 (`F5`)
7. Qtcreator
- 설치
- qtcreator-ros ( ros와 plug in 해서 설치 )
## 코드 가이드
### C++ Style
- Google style guide[1]을 따른다
- C++ 14 Standard [2]를 준수한다
- 'CamelCased', 'snake_case', 'ALL_CAPITALS'만을 사용
- CamelCaed : 타입, 클래스, 구조체, 열거형
- snake_case : 파일, 패키지, 인터페이스, 네임스페이스, 변수, 함수, 메소드
- ALL_CAPTALS: 상수, 매크로
- 소스파일 '.cpp', 헤더파일 '.hpp' 확장자 사용
- 전역변수(global variable)는 사용이 피치 못한 경우에는 `g_` 접두어를 붙인다.
- 클래스 멤버 변수(class member variable)는 마지막에 밑줄(`_`)을 붙인다.
(1) 공백 문자 대 탭 (Spaces vs. Tabs)
- 기본 들여쓰기(indent)는 공백 문자(space) `2개`를 사용한다. (탭(tab)문자 사용 금지)
- `Class`의 `public:`, `protected:`, `private:`은 들여쓰기를 사용하지 않는다.
(2) 괄호 (Brace)
- 모든 if, else, do, while, for 구문에 괄호를 사용한다.
- 괄호 및 공백 사용은 아래 예제를 참고하자.
- 예제 (올바른 사용법)
```c++
int main(int argc, char **argv)
{
if (condition) {
return 0;
} else {
return 1;
}
}
if (this && that || both) {
...
}
// Long condition; open brace
if (
this && that || both && this && that || both && this && that || both && this && that)
{
...
}
// Short function call
call_func(foo, bar);
// Long function call; wrap at the open parenthesis
call_func(
foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar,
foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar);
// Very long function argument; separate it for readability
call_func(
bang,
fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo,
bar, bat);
ReturnType LongClassName::ReallyReallyReallyLongFunctionName(
Type par_name1, // 2 space indent
Type par_name2,
Type par_name3)
{
DoSomething(); // 2 space indent
...
}
MyClass::MyClass(int var)
: some_var_(var),
some_other_var_(var + 1)
{
...
DoSomething();
...
}
(3) 주석 (Comments)
문서 주석에는 /** */을 사용한다.
구현 주석에는 //을 사용한다.
(4) 린터 (Linters)
C++ 코드 스타일의 자동 오류 검출을 위하여 ament_cpplint [7], ament_uncrustify [8]를 사용하고 정적 코드 분석이 필요한 경우 ament_cppcheck [9]를 사용하자.
(5) 기타
Boost 라이브러리의 사용은 가능한 피하고 어쩔 수 없을 경우에만 사용한다.
포인트 구문은 char * c;처럼 사용한다. (char* c; 이나 char *c; 처럼 사용하지 않는다.)
중첩 템플릿은 set<list<string>>처럼 사용한다. (set<list<string> > 또는 set< list<string> >처럼 사용하지 않는다.)
Python Style
ROS 2 Developer Guide [3] 및 ROS 2 Code style [4]에서 다루고 있는 Python 코드 스타일은 Python Enhancement Proposals (PEPs) [5]의 PEP 8 [6]를 준수한다.
(1) 기본 규칙
Python 3 (Python 3.5 이상)를 사용한다.
(2) 라인 길이
최대 100 문자
(3) 이름 규칙 (Naming)
CamelCased, snake_case, ALL_CAPITALS 만을 사용한다.
CamelCased: 타입, 클래스
snake_case: 파일, 패키지, 인터페이스, 모듈, 변수, 함수, 메소드
ALL_CAPITALS: 상수
(4) 공백 문자 대 탭 (Spaces vs. Tabs)
기본 들여쓰기(indent)는 공백 문자(space) 4개를 사용한다. (탭(tab)문자 사용 금지)
Hanging indent(문장 중간에 들여쓰기를 사용하는 형식)의 사용 방법은 아래 예제를 참고하자.
220103
@ error 1
중요 파일 ~/.config/Code/User/settings.json
~/robot_ws/.vscode/c_cpp_properties.json
~/robot_ws/.vscode/tasks.json
~/robot_ws/.vscode/launch.json
"ros.distro": "foxy", "colcon.provideTasks": true, "files.associations": { ".repos": "yaml", ".world": "xml", "*.xacro": "xml" },
(3) 주석 (Comments)
문서 주석에는
/** */
을 사용한다.구현 주석에는
//
을 사용한다.
(4) 린터 (Linters)
(5) 기타
Boost 라이브러리의 사용은 가능한 피하고 어쩔 수 없을 경우에만 사용한다.
포인트 구문은
char * c;
처럼 사용한다. (char* c;
이나char *c;
처럼 사용하지 않는다.)중첩 템플릿은
set<list<string>>
처럼 사용한다. (set<list<string> >
또는set< list<string> >
처럼 사용하지 않는다.)
Python Style
ROS 2 Developer Guide [3] 및 ROS 2 Code style [4]에서 다루고 있는 Python 코드 스타일은 Python Enhancement Proposals (PEPs) [5]의 PEP 8 [6]를 준수한다.
(1) 기본 규칙
(2) 라인 길이
(3) 이름 규칙 (Naming)
CamelCased
,snake_case
,ALL_CAPITALS
만을 사용한다.
CamelCased: 타입, 클래스
snake_case: 파일, 패키지, 인터페이스, 모듈, 변수, 함수, 메소드
ALL_CAPITALS: 상수
(4) 공백 문자 대 탭 (Spaces vs. Tabs)
기본 들여쓰기(indent)는 공백 문자(space)
4개
를 사용한다. (탭(tab)문자 사용 금지)Hanging indent
(문장 중간에 들여쓰기를 사용하는 형식)의 사용 방법은 아래 예제를 참고하자.괄호 및 공백 사용은 아래 예제를 참고하자.
foo = long_function_name(var_one, var_two, var_three, var_four)
def long_function_name( var_one, var_two, var_three, var_four): print(var_one)