ChaeChae0505 / Paper-reading

읽고 싶은 논문, 읽은 논문들을 정리하는 공간
1 stars 0 forks source link

220103 ROS2 설치 및 vscode 연결 ! #1

Closed ChaeChae0505 closed 2 years ago

ChaeChae0505 commented 2 years ago

220103

@ error 1

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
- 그냥 .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.distro": "foxy", "colcon.provideTasks": true, "files.associations": { ".repos": "yaml", ".world": "xml", "*.xacro": "xml" },

- 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
  }
  1. C/C++ properties 설정

c_cpp_properties.json ~/robot_ws/.vscode/c_cpp_properties.json


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)

(5) 기타

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)

(4) 공백 문자 대 탭 (Spaces vs. Tabs)

foo = function_name(var_one, var_two, var_three, var_four)

def long_long_long_long_function_name(
        var_one,
        var_two,
        var_three,
        var_four):
    print(var_one)

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)



​

(5) 괄호 (Brace)

- 괄호는 계산식 및 배열 인덱스로 사용하며, 자료형에 따라 적절한 괄호(대괄호 `[ ]`, 중괄호 `{ }`, 소괄호 `( )`)를 사용한다.

list = [1, 2, 3, 4, 5]
dictionary = {'age': 30, 'name': '홍길동'}
tupple = (1, 2, 3, 4, 5)
​

​

(6) 주석 (Comments)

- 문서 주석에는 `"""`을 사용하며 Docstring Conventions을 기술한 PEP 257 [12]을 준수한다.

- 구현 주석에는 `#`을 사용한다.

​

(7) 린터 (Linters)

- Python 코드 스타일의 자동 오류 검출을 위하여 ament_flake8 [13]를 사용하자.

​

(8) 기타

- 모든 문자는 큰 따옴표(`"`, double quotes)가 아닌 작은 따옴표(`'`, single quotes)를 사용하여 표현한다.

​
[1][Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
[2][C++ 14 Standard](https://en.wikipedia.org/wiki/C%2B%2B14)
​[3] ROS 2 developer guide, https://index.ros.org/doc/ros2/Contributing/Developer-Guide/
[4] ROS Enhancement Proposals (REPs), https://www.ros.org/reps/rep-0000.html
[5] Python Enhancement Proposals (PEPs), https://www.python.org/dev/peps/
[6] https://www.python.org/dev/peps/pep-0008/
ChaeChae0505 commented 2 years ago

01.04일에는 21강 부터 진행하겠습니다 python cpp 빌드까지 완료 하기!