Program exits with code -11 when using async_send_request to set parameters in ROS 2 C++ client

オープン
#2,534 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp
領域
api

調査の方向性

まず、rclcpp::Client::async_send_request と spin_until_future_complete を、動作する promise/callback の例および rclcpp::SyncParametersClient の実装と比較します。この issue では、比較のために ros2cli call.py の実装もリンクされています。完了条件は、直接 future パスでセグメンテーションフォルトが発生する理由を特定し、async_send_request の一般的な使用方法に関するガイダンスを文書化することです。

索引モデルが issue の本文から書いたものです。

説明

more-information-needed

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • binary (apt)
  • Version or commit hash:
    • humble
  • DDS implementation:
    • default
  • Client library (if applicable):
    • rclcpp
Steps to reproduce issue

I am encountering a segmentation fault (exit code -11) when using the async_send_request method to set parameters in a ROS 2 C++ client. Below is the relevant code snippet:

const auto set_parameters_req = std::make_shared<rcl_interfaces::srv::SetParameters::Request>();
auto set_parameters_resp = set_parameters_client_->async_send_request(set_parameters_req);
EXPECT_EQ(rclcpp::FutureReturnCode::SUCCESS, rclcpp::spin_until_future_complete(node_, set_parameters_resp));
Actual behavior

When executing the above code, the program exits with code -11 at the spin_until_future_complete call.

Additional information

The direct use of ros2 service call from the command line works correctly, and its implementation in Python at ros2cli GitHub resembles the C++ code I am using.

An alternative approach, using a promise and callback with async_send_request, does work as shown below. This approach is inspired by the implementation in rclcpp::SyncParametersClient:

auto promise_result = std::make_shared<std::promise<std::vector<rcl_interfaces::msg::SetParametersResult>>>();
set_parameters_client_->async_send_request(
  set_parameters_req,
  [promise_result, future_result](rclcpp::Client<rcl_interfaces::srv::SetParameters>::SharedFuture cb_f) {
    promise_result->set_value(cb_f.get()->results);
  }
);
rclcpp::spin_until_future_complete(test_node_, future_result);

Questions:

  • Why does the first approach result in a segmentation fault while the second approach and the Python version work correctly?
  • Are there any general rules or guidelines for using async_send_request in ROS 2 C++ clients to avoid such issues?
主要言語
C++
スター
829
フォーク
587
平均マージ
4日 6時間
マージ済み PR(30日)
30

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ros2/rclcpp のほかの issue

ros2/rclcpp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。