LoginSignup
1
1

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

Last updated at Posted at 2023-12-08

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

前回までのあらすじ

OSS連携を試みるため、PythonでROS2のサブスクリプションでAutowareのmsgをサブスクライブしてログを表示させるプログラムを作りました。
今回はC++同様、Autowareのmsgをサブスクライブして、msgをそのままAutowareに渡す処理を作っていきたいと思います。

ROS2でモジュール作成

ROSのチュートリアルの内容を例によって参照します。

Autowareのカスタマイズ

パッケージの作成

例によってROSのチュートリアルを見ながら、簡単なサブスクリプションを作ります。

公式サイトの通り、ROS2のパッケージを作成します。

$ cd ~/aichallenge2023-racing/docker/aichallenge/aichallenge_ws/src/aichallenge_submit/
$ ros2 pkg create --build-type ament_python py_path_subscriber

ROSチュートリアルに従って、package.xmlとCMakeLists.txtを変更します。

ソースコード

ソースコードはこんな感じ。
前回からパブリッシャーを作成し、サブスクリプションがmsgを受信した契機コールバック内からmsgをAutowareに投げています。

py_pathwithlaneid_sub_function.py
import rclpy
from rclpy.node import Node
from autoware_auto_planning_msgs.msg import PathWithLaneId
from std_msgs.msg import String


class MinimalSubscriber(Node):
    def __init__(self):
        super().__init__("minimal_subscriber")
        self.subscription = self.create_subscription(
            PathWithLaneId,
            "behavior_planning/path_with_lane_id",
            self.listener_callback,
            10,
        )
        self.subscription  # prevent unused variable warning

        self.path_pub = self.create_publisher(
            PathWithLaneId,
            "behavior_planning/path_with_lane_id_modified",
            10,
        )

    def listener_callback(self, msg: PathWithLaneId):
        path = msg
        self.get_logger().info("I heard PathWithLaneId")
        self.path_pub.publish(path)


def main(args=None):
    rclpy.init(args=args)

    minimal_subscriber = MinimalSubscriber()

    rclpy.spin(minimal_subscriber)

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    minimal_subscriber.destroy_node()
    rclpy.shutdown()


if __name__ == "__main__":
    main()


パッケージのビルド

次に、Dockerを起動してコードをビルドします。

$ cd /aichallenge/
$ pip install setuptools==58.2.0
$ bash clean_build.sh 

パッケージの実行

参考記事同様、launchファイルから実行します。本大会ではAutoware-Microを使用しており、autoware_micro_awsim.launch.xmlを変更します。

autoware_micro_awsim.launch.xml
<!-- lane_driving -->
〜割愛〜
<group>
    <node pkg="cpp_pathwithlaneid_pubsub" exec="cpp_pathwithlaneid_pubsub"/>
</group> <!-- Simple Pub Sub -->
</group> <!-- lane_driving -->

実行してみます。

$ bash run_autoware.sh
$ bash run_awsim.sh

通常通りにAutowareが走行し始めれば成功となります。

今後の予定

OSS連携のためのソースコードの雛形は作れました。
今後は連携するOSSを調査、あるいは自作の方向で進めていく予定です。

参考記事

自動運転 AIチャレンジ ~導入編~

1
1
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
1
1