Skip to content

Commit

Permalink
🔄 synced local 'docs/cheatsheets' with remote 'cheatsheets'
Browse files Browse the repository at this point in the history
  • Loading branch information
HansRobo committed Feb 29, 2024
1 parent 440f27f commit a87c80e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/cheatsheets/ROS Context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
created: 2024-02-23 10:24:46
---
## Default Context

それぞれのプロセスでは、シングルトンパターンによってデフォルトのContextが生成される。

rclcpp::initではこのデフォルトコンテキストを初期化している。


## オリジナル Contextを使ったROS 2プログラミング

rclcpp::initはデフォルトContextをinitしているに過ぎないので、
オリジナルContextしか使わない場合はContext::initさえしておけばrclcpp::initする必要はない


## CallbackGroup

## NodeOptions
ノードに対応する設定
-


## InitOptions

contextに対応する設定
- domain IDがセットできる


## ExecutorOptions

rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy;
rclcpp::Context::SharedPtr context;
size_t max_conditions;
=>デフォルトコンテキストが使われる
65 changes: 65 additions & 0 deletions docs/cheatsheets/rclcpp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
created: 2024-02-29 10:41:27
---

## パラメータ

### Nodeからいじる

#### get_parameter

##### 1

```
rclcpp::Parameter get_parameter(const std::string & name) const
```

名前を指定して、パラメータを返す。
存在しないパラメータに対しては `rclcpp::exceptions::ParameterNotDeclaredException`を送出する。

##### 2
```
bool get_parameter(const std::string & name, rclcpp::Parameter & parameter) const
```

名前を指定して、引数のパラメータ参照に代入する。
存在しないパラメータの場合、falseが返る。

##### 3

```
template<typename ParameterT>
bool get_parameter(const std::string & name, ParameterT & parameter) const
```

2のパラメータ型をテンプレートで指定するバージョン。
名前を指定して、引数の生パラメータ型の参照に代入する。
存在しないパラメータの場合、falseが返る。
テンプレートで指定したパラメータ型と取得しようとしているパラメータの型が異なる場合、`rclcpp::ParameterTypeException`を送出する。

##### 4
```
template<typename ParameterT>
bool
get_parameter_or(
const std::string & name,
ParameterT & parameter,
const ParameterT & alternative_value) const
```

3のラッパーで、3の返り値がfalseのときに3番目の引数を返す。
パラメータが宣言されていないときに自動で宣言してくれるような機能はない。
返り値はROS空間からパラメータを取得できたかどうか(=alternative_valueが使われたときはfalseが返る)
他のget_parameterと違って実装はnode_impl.hppにあるので注意。

##### 5

```
template<typename ParameterT>
ParameterT
get_parameter_or(
const std::string & name,
const ParameterT & alternative_value) const
```

4のラッパーになっていて、パラメータを参照ではなく返り値で返してくれる。

0 comments on commit a87c80e

Please sign in to comment.