Skip to content

Commit

Permalink
Merge pull request #38 from tier4/sync-upstream
Browse files Browse the repository at this point in the history
chore: sync upstream
  • Loading branch information
tier4-autoware-public-bot[bot] authored Feb 3, 2023
2 parents f76d35e + 10db123 commit cb4e3dc
Show file tree
Hide file tree
Showing 107 changed files with 2,542 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
pre-commit:
if: ${{ github.event.repository.private }}
if: ${{ github.event.repository.private }} # Use pre-commit.ci for public repositories
runs-on: ubuntu-latest
steps:
- name: Generate token
Expand Down
3 changes: 3 additions & 0 deletions .markdown-link-check.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
},
{
"pattern": "^https://github.com/.*/discussions/new"
},
{
"pattern": "^https://www\\.autosar\\.org/*"
}
],
"retryOn429": true,
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config-optional.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/tcort/markdown-link-check
rev: v3.10.0
rev: v3.10.3
hooks:
- id: markdown-link-check
args: [--config=.markdown-link-check.json]
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-json
- id: check-merge-conflict
Expand All @@ -19,29 +19,29 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.1
rev: v0.32.2
hooks:
- id: markdownlint
args: [-c, .markdownlint.yaml, --fix]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
rev: v3.0.0-alpha.4
hooks:
- id: prettier

- repo: https://github.com/adrienverge/yamllint
rev: v1.27.1
rev: v1.28.0
hooks:
- id: yamllint
exclude: .*.param.yaml

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.4
rev: v0.9.0.2
hooks:
- id: shellcheck

- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.5.1-1
rev: v3.6.0-1
hooks:
- id: shfmt
args: [-w, -s, -i=4]
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/coding-guidelines/languages/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Follow the guidelines below if a rule is not defined on this page.

1. <https://docs.ros.org/en/humble/Contributing/Code-Style-Language-Versions.html>
2. <https://www.autosar.org/fileadmin/user_upload/standards/adaptive/21-11/AUTOSAR_RS_CPP14Guidelines.pdf>
2. <https://www.autosar.org/fileadmin/standards/adaptive/22-11/AUTOSAR_RS_CPP14Guidelines.pdf>
3. <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines>

Also, it is encouraged to apply Clang-Tidy to each file.
Expand Down
187 changes: 185 additions & 2 deletions docs/contributing/coding-guidelines/ros-nodes/console-logging.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,188 @@
# Console logging

!!! warning
ROS 2 logging is a powerful tool for understanding and debugging ROS nodes.

Under Construction
This page focuses on how to design console logging in Autoware and shows several practical examples.
To comprehensively understand how ROS 2 logging works, refer to the [logging documentation](https://docs.ros.org/en/humble/Concepts/About-Logging.html).

## Logging use cases in Autoware

- Developers debug code by seeing the console logs.
- Vehicle operators take appropriate risk-avoiding actions depending on the console logs.
- Log analysts analyze the console logs that are recorded in rosbag files.

To efficiently support these use cases, clean and highly visible logs are required.
For that, several rules are defined below.

## Rules

### Choose appropriate severity levels (required, non-automated)

#### Rationale

It's confusing if severity levels are inappropriate as follows:

- Useless messages are marked as `FATAL`.
- Very important error messages are marked as `INFO`.

#### Example

Use the following criteria as a reference:

- **DEBUG:** Use this level to show debug information for developers. Note that logs with this level is hidden by default.
- **INFO:** Use this level to notify events (cyclic notifications during initialization, state changes, service responses, etc.) to operators.
- **WARN:** Use this level when a node can continue working correctly, but unintended behaviors might happen.
- For example, "path optimization failed but the previous data can be used", "the localization score is low", etc.
- **ERROR:** Use this level when a node can't continue working correctly, and unintended behaviors would happen.
- For example, "path optimization failed and the path is empty", "the vehicle will trigger an emergency stop", etc.
- **FATAL:** Use this level when the entire system can't continue working correctly, and the system must be stopped.
- For example, "the vehicle control ECU doesn't respond", "the system storage crashed", etc.

### Filter out unnecessary logs by setting logging options (required, non-automated)

#### Rationale

Some third-party nodes such as drivers may not follow the Autoware's guidelines.
If the logs are noisy, unnecessary logs should be filtered out.

#### Example

Use the `--log-level {level}` option to change the minimum level of logs to be displayed:

```xml
<launch>
<!-- This outputs only FATAL level logs. -->
<node pkg="demo_nodes_cpp" exec="talker" ros_args="--log-level fatal" />
</launch>
```

If you want to disable only specific output targets, use the `--disable-stdout-logs`, `--disable-rosout-logs`, and/or `--disable-external-lib-logs` options:

```xml
<launch>
<!-- This outputs to rosout and disk. -->
<node pkg="demo_nodes_cpp" exec="talker" ros_args="--disable-stdout-logs" />
</launch>
```

```xml
<launch>
<!-- This outputs to stdout. -->
<node pkg="demo_nodes_cpp" exec="talker" ros_args="--disable-rosout-logs --disable-external-lib-logs" />
</launch>
```

### Use throttled logging when the log is unnecessarily shown repeatedly (required, non-automated)

#### Rationale

If tons of logs are shown on the console, people miss important message.

#### Example

While waiting for some messages, throttled logs are usually enough.
In such cases, wait about 5 seconds as a reference value.

```cpp
// Compliant
void FooNode::on_timer() {
if (!current_pose_) {
RCLCPP_ERROR_THROTTLE(get_logger(), *get_clock(), 5000, "Waiting for current_pose_.");
return;
}
}

// Non-compliant
void FooNode::on_timer() {
if (!current_pose_) {
RCLCPP_ERROR(get_logger(), "Waiting for current_pose_.");
return;
}
}
```

#### Exception

The following cases are acceptable even if it's not throttled.

- The message is really worth displaying every time.
- The message level is DEBUG.

### Do not depend on rclcpp::Node in core library classes but depend only on rclcpp/logging.hpp (advisory, non-automated)

#### Rationale

Core library classes, which contain reusable algorithms, may also be used for non-ROS platforms.
When porting libraries to other platforms, fewer dependencies are preferred.

#### Example

```cpp
// Compliant
#include <rclcpp/logging.hpp>

class FooCore {
public:
explicit FooCore(const rclcpp::Logger & logger) : logger_(logger) {}

void process() {
RCLCPP_INFO(logger_, "message");
}

private:
rclcpp::Logger logger_;
};

// Compliant
// Note that logs aren't published to `/rosout` if the logger name is different from the node name.
#include <rclcpp/logging.hpp>

class FooCore {
void process() {
RCLCPP_INFO(rclcpp::get_logger("foo_core_logger"), "message");
}
};


// Non-compliant
#include <rclcpp/node.hpp>

class FooCore {
public:
explicit FooCore(const rclcpp::NodeOptions & node_options) : node_("foo_core_node", node_options) {}

void process() {
RCLCPP_INFO(node_.get_logger(), "message");
}

private:
rclcpp::Node node_;
};
```
## Tips
### Use rqt_console to filter logs
To filter logs, using `rqt_console` is useful:
```bash
ros2 run rqt_console rqt_console
```

For more details, refer to [ROS 2 Documentation](https://docs.ros.org/en/rolling/Tutorials/Beginner-CLI-Tools/Using-Rqt-Console/Using-Rqt-Console.html).

### Useful marco expressions

To debug program, sometimes you need to see which functions and lines of code are executed.
In that case, you can use `__FILE__`, `__LINE__` and `__FUNCTION__` macro:

```cpp
void FooNode::on_timer() {
RCLCPP_DEBUG(get_logger(), "file: %s, line: %s, function: %s" __FILE__, __LINE__, __FUNCTION__);
}
```

The example output is as follows:

> [DEBUG] [1671720414.395456931] [foo]: file: /path/to/file.cpp, line: 100, function: on_timer
Loading

0 comments on commit cb4e3dc

Please sign in to comment.