🤖
WindowsでROS2する(MSVC)
前回、Windows で hello world くらいまでいったのだけど、その続き。
pixi がよくわかっていなくて C:\pixi_ws 決め打ちのように書いたのだけどそんなことはなかった。
任意のフォルダで作業できます。
pixi で setup する環境について
pixi init project_folder すると project_folder/.pixi ができて、そこに全部入りの環境が作られる。
ros2 は pixi run ros2 経由で使います。
このとき、ros2 は .pixi 下の python やライブラリなどを使うようです。
ros2 + pixi のプロジェクト手順
これ
0. 事前準備
pixi コマンドをインストールする
pixi コマンドにパスを通しておきます。
> where.exe pixi
~\AppData\Local\pixi\bin\pixi.exe
> pixi --version
# pixi 0.47.0
pixi 0.56.0
1. project作成
> pixi init ros2_hello
> cd ros2_hello
ros2_hello> git init
ros2_hello> git add .
ros2_hello> git commit -m init
pixi.toml
[workspace]
authors = ["ousttrue <ousttrue@gmail.com>"]
channels = ["conda-forge"]
name = "ros2_hello"
platforms = ["win-64"]
version = "0.1.0"
[tasks]
[dependencies]
ros2 要素追加
ここで ros のバージョン(humble, jazzy, kilted...)を決める。
kilted
ros2_hello> pixi add "python=3.12.3"
ros2_hello> py -V
Python 3.13.3
ros2_hello> pixi run python -V
Python 3.12.3
ros2_hello> pixi workspace channel add robostack-kilted
ros2_hello> pixi add ros-kilted-desktop ros-kilted-ament-cmake-auto
# "setuptools<=58.2.0" はエラーになるので省いた
ros2_hello> pixi add colcon-common-extensions
ros2_hello> pixi add compilers pkg-config cmake ninja
pixi.toml
[workspace]
channels = ["conda-forge", "robostack-kilted"]
[dependencies]
python = "3.12.3.*"
ros-kilted-desktop = ">=0.12.0,<0.13"
ros-kilted-ament-cmake-auto = ">=2.7.3,<3"
colcon-common-extensions = ">=0.3.0,<0.4"
compilers = ">=1.11.0,<2"
pkg-config = ">=0.29.2,<0.30"
cmake = ">=4.1.2,<5"
ninja = ">=1.13.1,<2"
humble
ros2_hello> pixi workspace channel add robostack-humble
ros2_hello> pixi add ros-humble-desktop ros-humble-ament-cmake-auto
ros2_hello> pixi add colcon-common-extensions "setuptools<=58.2.0"
ros2_hello> pixi add compilers pkg-config cmake ninja
pixi.toml
[workspace]
channels = ["conda-forge", "robostack-humble"]
[dependencies]
ros-humble-desktop = ">=0.10.0,<0.11"
ros-humble-turtlesim = ">=1.4.2,<2"
colcon-common-extensions = ">=0.3.0,<0.4"
setuptools = "<=58.2.0"
ros-humble-ament-cmake-auto = ">=1.3.12,<2"
compilers = ">=1.11.0,<2"
pkg-config = ">=0.29.2,<0.30"
cmake = ">=4.1.2,<5"
ninja = ">=1.13.1,<2"
rcl package 追加
ros2_hello> pixi run ros2 pkg create --build-type ament_cmake --destination-directory src --node-name hello_node hello_pkg
build
ros2_hello> pixi run colcon build --symlink-install --cmake-args -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
ros2_hello> pixi run ros2 run hello_pkg hello_node
hello world hello_pkg package
launch.xml
src/hello_pkg/launch/launch.xml
<launch>
<node pkg="hello_pkg" exec="hello_node" />
</launch>
CMakeLists.txt
add_executable(hello_node src/main.cpp)
ros2_hello> pixi run ros2 launch .\src\hello_pkg\launch\launch.xml
vscode で rcl node に break point アタッチする
pixi run ros2 run xxx
という風に間接的にプロセスを起動するので、デバッガを launch できない。
そこで ros2 拡張の debugger launch 機能があります。
debugger 下の debugger が必要
pixi 環境から vscode を起動するべし
ros2_hello> pixi shell
(ros2_hello) PS> code .
.vscode/settings.json
{
"ROS2.rosSetupScript": "${workspaceFolder}/install/local_setup.bat"
}
debug設定
.vscode/launch.json
{
"configurations": [
{
"name": "ROS2: Launch",
"type": "ros2",
"request": "launch",
"target": "${workspaceFolder}\\src\\hello_pkg\\launch\\launch.xml",
},
]
}

break できた。
rviz で見えるのを作る
pixi run rviz2
> pixi run rviz2 -d .\install\urdf_tutorial_cpp\share\urdf_tutorial_cpp\urdf\r2d2.rviz
pixi run ros2 launch
> pixi run ros2 launch .\src\urdf_tutorial_cpp\launch\launch.py

C2065
colcon build
log\latest_build\urdf_tutorial_cpp\stdout_stderr.log
urdf_tutorial.cpp
C:\work\ros2_hello\src\urdf_tutorial_cpp\src\urdf_tutorial.cpp(39,25): error C2065: 'M_PI': 定義されていない識別子です。 [C:\work\ros2_hello\build\urdf_tutorial_cpp\urdf_tutorial_cpp.vcxproj]
CMakeLists.txt
target_compile_definitions(urdf_tutorial_cpp PRIVATE _USE_MATH_DEFINES)
import error: launch.substitutions.FileContent
ros2 launch
humble には FileContent 無かった。
kilted にできていないことに気付いた。
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
ros2 launch
.pixi の python と robostack-humble や robostack-kilted のバージョンが一致していない。
のように調べて、
ros2_hello> pixi add "python=3.12.3"
のように指定する。
Discussion