ROS2とPythonで作って学ぶAIロボット入門 写経メモ(C++で書き換えます)
p36でエラー
libcurl: (6) Could not resolve host: fuel.ignitionrobotics.org
~/.ignition/fuel/config.yamlを作成し、以下一行加えるでOK
url: https://api.ignitionrobotics.org
参考
rclcpp検知してくれない問題、以下をpackage.xmlに追加したら大丈夫だった。
ubuntu@7e0741175644:~/happy_ws$ colcon build --cmake-clean-cache
Starting >>> hello
--- stderr: hello
/home/ubuntu/happy_ws/src/chapter2/hello/src/hellop_node.cpp:2:10: fatal error: rclcpp/rclcpp.hpp: そのようなファイルやディレクトリはありません
2 | #include "rclcpp/rclcpp.hpp"
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
+find_package(rclcpp REQUIRED)
+find_package(rclcpp_components REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
add_executable(hellop_node src/hellop_node.cpp)
+ament_target_dependencies(hellop_node rclcpp)
target_include_directories(hellop_node PUBLIC
rclcpp自体は /opt/ros/foxy/include
以下にいる
教本の教示通りtiryoh/ros2-desktop-vnc:foxyをpullしてきてデスクトップ上に構築された仮想環境でやっているが、コーディング・ホストへのコピペなどがつらくなってきた
WSLで環境作る方向にシフト
基本的にはこれに準拠(ただしfoxyを使用する)
gazeboインストールできなかったので別途以下をフォロー
wslから無条件でGUIが開いて感動した(ドライバー周りで起こられると思った)
vscode のclangdのIntellisenseで以下が出続けていた(colcon buildはできていた)が、vscodeのclangdの拡張でclangdをバージョンアップしたら直った
rclcpp/rclcpp.hpp' file not found
sub_ = create_subscription<std_msgs::msg::String>(
"topic", rclcpp::QoS(10),
std::bind(&HappySubscriber::callback, this, std::placeholders::_1));
std::bindしなければ以下のエラーがでる
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:83:8: note: candidate: ‘template<class CallbackT, typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<std_msgs::msg::String_<std::allocator<void> > >)> >::value, void>::type* <anonymous> > void rclcpp::AnySubscriptionCallback<MessageT, Alloc>::set(CallbackT) [with CallbackT = CallbackT; typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<_Tp>)> >::value>::type* <anonymous> = <enumerator>; MessageT = std_msgs::msg::String_<std::allocator<void> >; Alloc = std::allocator<void>]’
83 | void set(CallbackT callback)
| ^~~
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:83:8: note: template argument deduction/substitution failed:
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:81:17: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
81 | >::type * = nullptr
| ^~~~~~~
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:97:8: note: candidate: ‘template<class CallbackT, typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<std_msgs::msg::String_<std::allocator<void> > >, const rclcpp::MessageInfo&)> >::value, void>::type* <anonymous> > void rclcpp::AnySubscriptionCallback<MessageT, Alloc>::set(CallbackT) [with CallbackT = CallbackT; typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<_Tp>, const rclcpp::MessageInfo&)> >::value>::type* <anonymous> = <enumerator>; MessageT = std_msgs::msg::String_<std::allocator<void> >; Alloc = std::allocator<void>]’
97 | void set(CallbackT callback)
| ^~~
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:97:8: note: template argument deduction/substitution failed:
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:95:17: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
95 | >::type * = nullptr
| ^~~~~~~
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:111:8: note: candidate: ‘template<class CallbackT, typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<const std_msgs::msg::String_<std::allocator<void> > >)> >::value, void>::type* <anonymous> > void rclcpp::AnySubscriptionCallback<MessageT, Alloc>::set(CallbackT) [with CallbackT = CallbackT; typename std::enable_if<rclcpp::function_traits::same_arguments<CallbackT, std::function<void(std::shared_ptr<const _Tp>)> >::value>::type* <anonymous> = <enumerator>; MessageT = std_msgs::msg::String_<std::allocator<void> >; Alloc = std::allocator<void>]’
111 | void set(CallbackT callback)
| ^~~
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:111:8: note: template argument deduction/substitution failed:
/opt/ros/foxy/include/rclcpp/any_subscription_callback.hpp:109:17: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
109 | >::type * = nullptr
| ^~~~~~~
pubsubのメッセージを使いたくなったらstd_msgs::msg::Int32
を使う
serviceで独自定義したメッセージをインストールするのにはまった
最小構成は多分以下
上記のcmakeとpackage.xmlを参考にsourceたたきまくったらなんかbuildできるようになっていた。
インテリセンスも効いていなかったが、これはC++の拡張機能をOFFにしていたことが原因
chap4
empty_world表出できなかった。
以下2つで改善
https://github.com/AI-Robot-Book/happy_mini_turtlebot3_sim/commits/main/ にて、c3e7c3ce8f6f296e0b094ba9429833e7199eab22 をチェックアウトする
gazeboをインストールする。流れは以下
vscodeでcpp ros foxyのヘッダーファイル読み込んでくれなかったが以下を参考にしたら解消した
特に以下のアトリビュート
"C_Cpp.intelliSenseEngine": "Tag Parser", (clang使わないならdefaultに値を設定)
"browse": {
"path": [
"${default}"
]
}