5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

スイッチを押したらROS2 nodeを起動する(実装の備忘録)

Posted at

なぜこんなことしたか

スイッチおしたらwaypoint followのnodeを起動して、動きだす仕組みをつくりたかった
スイッチも複数(5個くらい)に増やせるので、follow waypointsのnodeも経路別で5個くらいつくっておいて
スイッチ1を押したら1の経路、スイッチ2をおしたら2の経路・・・これがしたいからです。

環境

ROS2、galactic、FT232H bord、スイッチ

設定

これ通り

回路図

別途作成し、更新予定ですが、以下リンクのDigital input通り

実装

私はスイッチを押したらfollow_waypoints のnodeを起動する仕組みにしたかったので、start.pyを以下内容で作成する

cd ros2
sudo nano start.py

以下コードをコピー&ペーストして保存。(ctrl+x→y)

import subprocess
from numpy import true_divide
import board
import digitalio
button = digitalio.DigitalInOut(board.C0)
button.direction = digitalio.Direction.INPUT

#follow_waypoints follow_waypointsの部分を自分が起動したいnodeにする
cmd = "ros2 run follow_waypoints follow_waypoints"

while True:
    if button.value == True:
        subprocess.run(cmd,shell=True)

上記コード内の以下の部分を自分が起動したいnodeに変更する。
"ros2 run follow_waypoints follow_waypoints"

cd ros2
python start.py

スイッチを押したら、follow_waypoints nodeが起動します。

うまくいかなかったら、これも実装する必要あるかも

setup.bashの自動読み込み

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?