myAGV(ROS2)

myAGV(ROS1)ができたので,次はROS2.
と思ってmyagv ros2にアクセスしてみると,
defaultのbranchがgalactic-JNになっていました.
Raspberry pi版は,jazzy-Pi5となっています.
ん?Pi5?
ってことは,今の手元のRaspbarry piだとダメってことですね.
しかも,jazzyということはUbuntu 24.04になるはず.
そして,現段階(2026/03/02)では,中身は空っぽ….

とりあえず,JetsonNanoバージョンを頑張ってみますか….
ros2shellを実行して,pythonをros2の環境に切り替えておきます.

er@er:~$ ros2shell
ROS_DISTRO was set to 'noetic' before. Please make sure that the environment does not mix paths from different distributions.
ROS_DISTRO was set to 'galactic' before. Please make sure that the environment does not mix paths from different distributions.
(ros2 galactic py3)er@er:~$ 

ちなみに,これは環境変数を書き換えて,bashを読み込み直すだけです.

(ros2 galactic py3)er@er:~$ cat .local/bin/ros2shell 
#!/bin/bash
export MYCOBOT_ROS_2_INIT=1
export MYCOBOT_ROS_2_COMMANDS="$*"
bash

で,なぜこれでROS2の世界になるかと言うと,.bashrcにて,この環境変数を見て,setup.bashを読み込むようになっているからです.

(ros2 galactic py3)er@er:~$ cat .bashrc|head -n82|tail -n20
ros2-init()
{
	source /opt/ros/galactic/setup.bash
	if [ -f ~/colcon_ws/install/setup.bash ]; then
		source ~/colcon_ws/install/setup.bash
		if [ "$MYCOBOT_ROS_2_COMMANDS" != "" ]; then
			echo "$MYCOBOT_ROS_2_COMMANDS"
			eval "$MYCOBOT_ROS_2_COMMANDS"
			exit
		fi
	fi
}

if [ "$MYCOBOT_ROS_1_INIT" == "1" ]; then
	ros-init
fi

if [ "$MYCOBOT_ROS_2_INIT" == "1" ]; then
	ros2-init
fi

素晴らしいですね.
で,関係しそうなパッケージのインストール

sudo apt install ros-galactic-bondcpp \
    ros-galactic-test-msgs* \
    ros-galactic-behaviortree-cpp-v3* \
    ros-galactic-ompl \
    ros-galactic-joint-state-publisher \
    ros-galactic-rqt-tf-tree \
    ros-galactic-diagnostic-updater \
    ros-galactic-camera-info-manager -y
sudo apt install ros-galactic-geographic-msgs -y

ROS2の環境構築

mkdir -p ~/myagv_ros2/src
cd ~/myagv_ros2/src
git clone https://github.com/elephantrobotics/myagv_ros2.git

ROS2-myAGVのパッケージのビルド

cd ~/myagv_ros2
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -r -y
colcon build --symlink-install

いくつかのパッケージが重複している模様.

(ros2 galactic py3)er@er:~/myagv_ros2$ colcon build --symlink-install

[2.780s] colcon.colcon_core.package_selection WARNING Some selected packages are already built in one or more underlay workspaces:
	'cv_bridge' is in: /opt/ros/galactic
	'image_geometry' is in: /opt/ros/galactic
	'teleop_twist_keyboard' is in: /opt/ros/galactic
If a package in a merged underlay workspace is overridden and it installs headers, then all packages in the overlay must sort their include directories by workspace order. Failure to do so may result in build failures or undefined behavior at run time.
If the overridden package is used by another package in any underlay, then the overriding package in the overlay must be API and ABI compatible or undefined behavior at run time may occur.

If you understand the risks and want to override a package anyways, add the following to the command line:
	--allow-overriding cv_bridge image_geometry teleop_twist_keyboard

This may be promoted to an error in a future release of colcon-override-check.

気になるのであれば,無視のフラグを立てておく.

cd ~/myagv_ros2/src
# システムと重複しているフォルダに無視ファイルを置く
touch vision_opencv/cv_bridge/COLCON_IGNORE
touch vision_opencv/image_geometry/COLCON_IGNORE
touch teleop_twist_keyboard/COLCON_IGNORE

ビルドできたら,環境の更新って,ビルドにかなり時間がかかります….
ちなみに,screenを使いたかったら,

export MYCOBOT_ROS_2_INIT=1
screen

ってやらないと,フラグがない状態でbashを呼び出すことになるのでros1のシェルが立ち上がってしまうことに気をつけて下さい.
また,どこかでmyagv_rosによる設定上書きが入ってしまった場合もros2shellが無視されるので気をつけて下さい.
詳しくは,「a href=”https://www.kdel.org/wp/?p=3960″>ros2shellを実行しても,(ros1 noetic py3) になる
」を.
さて,使ってみますか.

# GPIO 20 を有効にする
echo 20 | sudo tee /sys/class/gpio/export

# 出力モードに設定する
echo out | sudo tee /sys/class/gpio/gpio20/direction

# 電源をONにする(1を書く)
echo 1 | sudo tee /sys/class/gpio/gpio20/value

起動します.

ros2 launch myagv_bringup bringup.launch.py

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

*