Open11

ROS2とPythonで作って学ぶAIロボット入門 写経メモ(C++で書き換えます)

awayatakumaawayatakuma

p36でエラー

libcurl: (6) Could not resolve host: fuel.ignitionrobotics.org

~/.ignition/fuel/config.yamlを作成し、以下一行加えるでOK

 url: https://api.ignitionrobotics.org

参考
https://qiita.com/seigot/items/93cc4203da5da596fb3e

awayatakumaawayatakuma

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以下にいる

awayatakumaawayatakuma

教本の教示通りtiryoh/ros2-desktop-vnc:foxyをpullしてきてデスクトップ上に構築された仮想環境でやっているが、コーディング・ホストへのコピペなどがつらくなってきた

awayatakumaawayatakuma

vscode のclangdのIntellisenseで以下が出続けていた(colcon buildはできていた)が、vscodeのclangdの拡張でclangdをバージョンアップしたら直った
rclcpp/rclcpp.hpp' file not found

awayatakumaawayatakuma
    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
      |                 ^~~~~~~
awayatakumaawayatakuma

pubsubのメッセージを使いたくなったらstd_msgs::msg::Int32を使う