LoginSignup
3
0

【6日目】OSS連携してみたい!(4) Autoware-Microにエセ自作モジュール追加する

Last updated at Posted at 2023-12-05

この記事は筆者オンリーのAdvent Calendar 20236日目の記事です。

前回までのあらすじ

ROSモジュールを追加し、AutowareからサブスクライブしたメッセージをそのままAutowareに渡すという処理を追加し動作することを確認しました

今回やること

OSS連携を見据えて、Autowareのメッセージのメンバーを分解して渡すという処理をやりたいと思います

Autowareのメッセージの構造

例としてPathWithLaneIdを見てみます。
ここから、メッセージは
・Header型のheader
・PathPointWithLaneId型のpoints
・Point型のleft_bound
・Point型のright_bound
で構成されていることがわかります。
Point型はROS2で定義されているもののようです。

PathPointWithLaneIdを見てみます。
・PathPoint型の point
・int64型のベクターのlane_ids
で構成されていることがわかります。

PathPointを見てみます。
・Pose型のpose;
・float型のlongitudinal_velocity_mps
・float型のlateral_velocity_mps
・float型のheading_rate_rps
・boolean型のis_final
で構成されていることがわかります。
Pose型はROS2で定義されているもののようです。
Autoware独自の定義はこちらで見られるようです。

作業

例によってソースコードを作成します。
作成は前回記事のcpp_pathwithlaneid_pubsub_impl.cppを改造して作ります。

ソースコード

cpp_pathwithlaneid_pubsub_impl.cpp
#include "cpp_pathwithlaneid_pubsub.hpp"
#include <memory>

using PathWithLaneId = autoware_auto_planning_msgs::msg::PathWithLaneId;
using std::placeholders::_1;

PathSubscriber::PathSubscriber() : Node("path_subscriber")
{

  sub_path_pub_ = create_publisher<PathWithLaneId>(
      "behavior_planning/path_with_lane_id_modified", 1);

  sub_path_sub_ = create_subscription<PathWithLaneId>("behavior_planning/path_with_lane_id", 10, std::bind(&PathSubscriber::topicCallback, this, _1));
}

void PathSubscriber::topicCallback(const PathWithLaneId::ConstSharedPtr msg)
{
  PathWithLaneId path;

  /*PathPointWithLaneID*/
  path.header = msg->header;
  path.left_bound = msg->left_bound;
  path.right_bound = msg->right_bound;
  path.points = msg->points;


  // RCLCPP_INFO(this->get_logger(), "I heard");

  sub_path_pub_->publish(path);
}

これから

C++を用いたROS2モジュールの作成を一通りやりました。
が、連携OSSはPythonが多数のようです。
次回はC++と同様のことができるかPythonでも試してみたいと思います。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0