Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit of port of naive to ros 2 #8

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ros2/naive/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.8)
bgill92 marked this conversation as resolved.
Show resolved Hide resolved
project(naive)
bgill92 marked this conversation as resolved.
Show resolved Hide resolved

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
bgill92 marked this conversation as resolved.
Show resolved Hide resolved
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

add_executable(naive src/node.cpp src/incrementer.cpp)
target_include_directories(naive PUBLIC include)
bgill92 marked this conversation as resolved.
Show resolved Hide resolved
ament_target_dependencies(naive rclcpp std_msgs)

install(TARGETS
naive
DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
16 changes: 16 additions & 0 deletions ros2/naive/include/naive/incrementer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

bgill92 marked this conversation as resolved.
Show resolved Hide resolved
#include <string>
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int64.hpp"

class Incrementer {
public:
Incrementer(std::shared_ptr<rclcpp::Node> node, const std::string& in_topic, const std::string& out_topic);
bgill92 marked this conversation as resolved.
Show resolved Hide resolved
private:
static constexpr int QUEUE_SIZE = 10;
bgill92 marked this conversation as resolved.
Show resolved Hide resolved
std::shared_ptr<rclcpp::Node> node_;
std::shared_ptr<rclcpp::Publisher<std_msgs::msg::Int64>> pub_;
std::shared_ptr<rclcpp::Subscription<std_msgs::msg::Int64>> sub_;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing final newline

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. I didn't realize the importance of the final newline.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what purpose it serves but Git and GitHub will warn you about omitting it so I make sure it's always there. You might have noticed in previous PR diffs how there was a little red symbol on the bottom line to indicate this.

21 changes: 21 additions & 0 deletions ros2/naive/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>naive</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
bgill92 marked this conversation as resolved.
Show resolved Hide resolved
<maintainer email="bilal.gill@picknik.ai">bilal</maintainer>
<license>TODO: License declaration</license>
bgill92 marked this conversation as resolved.
Show resolved Hide resolved

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rclcpp</depend>
<depend>std_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
15 changes: 15 additions & 0 deletions ros2/naive/src/incrementer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "naive/incrementer.hpp"

#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int64.hpp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use quoted includes instead of <> includes here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Should #include "naive/incrementer.hpp" remain a quoted include because it is a header file that is a part of this project?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the path to that header is not relative to the path of the .cpp file including it. The CppCoreGuidelines recommends triangle brackets in this instance. Basically the only time you use quotes is when the header is in the same directory as the .cpp file.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf12-prefer-the-quoted-form-of-include-for-files-relative-to-the-including-file-and-the-angle-bracket-form-everywhere-else


Incrementer::Incrementer(std::shared_ptr<rclcpp::Node> node, const std::string& in_topic, const std::string& out_topic)
griswaldbrooks marked this conversation as resolved.
Show resolved Hide resolved
: node_{std::move(node)},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is moving the shared pointer a valuable thing to do? The overhead of incrementing and decrementing the ref count is pretty miniscule.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub_{node_->create_publisher<std_msgs::msg::Int64>(out_topic,QUEUE_SIZE)},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does

Suggested change
pub_{node_->create_publisher<std_msgs::msg::Int64>(out_topic,QUEUE_SIZE)},
pub_{node_->create_publisher(out_topic, QUEUE_SIZE)},

work? Probably not but can you check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, the compiler does not like that. More template nastiness.

--- stderr: naive                             
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp: In constructor ‘Incrementer::Incrementer(std::shared_ptr<rclcpp::Node>, const string&, const string&)’:
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:13:52: error: no matching function for call to ‘rclcpp::Node::create_publisher(const string&, const int&)’
   13 |   pub_{node_->create_publisher(out_topic,queue_size)},
      |                                                    ^
In file included from /opt/ros/galactic/include/rclcpp/executors/single_threaded_executor.hpp:28,
                 from /opt/ros/galactic/include/rclcpp/executors.hpp:22,
                 from /opt/ros/galactic/include/rclcpp/rclcpp.hpp:156,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/include/naive/incrementer.hpp:38,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:1:
/opt/ros/galactic/include/rclcpp/node.hpp:200:3: note: candidate: ‘template<class MessageT, class AllocatorT, class PublisherT> std::shared_ptr<PublisherT> rclcpp::Node::create_publisher(const string&, const rclcpp::QoS&, const rclcpp::PublisherOptionsWithAllocator<AllocatorT>&)’
  200 |   create_publisher(
      |   ^~~~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/node.hpp:200:3: note:   template argument deduction/substitution failed:
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:13:52: note:   couldn’t deduce template parameter ‘MessageT’
   13 |   pub_{node_->create_publisher(out_topic,queue_size)},
      |                                                    ^
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:19:59: error: no matching function for call to ‘std::shared_ptr<rclcpp::Publisher<std_msgs::msg::Int64_<std::allocator<void> > > >::shared_ptr(<brace-enclosed initializer list>)’
   19 |                                                         })} {}
      |                                                           ^
In file included from /usr/include/c++/9/memory:81,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/include/naive/incrementer.hpp:37,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:1:
/usr/include/c++/9/bits/shared_ptr.h:367:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Tp>&, std::nothrow_t) [with _Tp = rclcpp::Publisher<std_msgs::msg::Int64_<std::allocator<void> > >]’
  367 |       shared_ptr(const weak_ptr<_Tp>& __r, std::nothrow_t)
      |       ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:367:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/shared_ptr.h:358:2: note: candidate: ‘template<class _Alloc, class ... _Args> std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...)’
  358 |  shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:358:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:307:17: note: candidate: ‘constexpr std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t) [with _Tp = rclcpp::Publisher<std_msgs::msg::Int64_<std::allocator<void> > >; std::nullptr_t = std::nullptr_t]’
  307 |       constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
      |                 ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:307:17: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/9/bits/shared_ptr.h:290:2: note: candidate: ‘template<class _Yp, class _Del, class> std::shared_ptr<_Tp>::shared_ptr(std::unique_ptr<_Up, _Ep>&&)’
  290 |  shared_ptr(unique_ptr<_Yp, _Del>&& __r)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:290:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:282:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::auto_ptr<_Up>&&)’
  282 |  shared_ptr(auto_ptr<_Yp>&& __r);
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:282:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:275:11: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Yp>&)’
  275 |  explicit shared_ptr(const weak_ptr<_Yp>& __r)
      |           ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:275:11: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:263:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Yp>&&)’
  263 |  shared_ptr(shared_ptr<_Yp>&& __r) noexcept
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:263:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:254:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = rclcpp::Publisher<std_msgs::msg::Int64_<std::allocator<void> > >]’
  254 |       shared_ptr(shared_ptr&& __r) noexcept
      |       ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:254:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/9/bits/shared_ptr.h:246:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&)’
  246 |  shared_ptr(const shared_ptr<_Yp>& __r) noexcept
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:246:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:234:2: note: candidate: ‘template<class _Yp> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&, std::shared_ptr<_Tp>::element_type*)’
  234 |  shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) noexcept
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:234:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:212:2: note: candidate: ‘template<class _Deleter, class _Alloc> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter, _Alloc)’
  212 |  shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:212:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:193:2: note: candidate: ‘template<class _Yp, class _Deleter, class _Alloc, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter, _Alloc)’
  193 |  shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:193:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:173:2: note: candidate: ‘template<class _Deleter> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter)’
  173 |  shared_ptr(nullptr_t __p, _Deleter __d)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:173:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:156:2: note: candidate: ‘template<class _Yp, class _Deleter, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter)’
  156 |  shared_ptr(_Yp* __p, _Deleter __d)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:156:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:139:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*)’
  139 |  shared_ptr(_Yp* __p) : __shared_ptr<_Tp>(__p) { }
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:139:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:129:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Tp>&) [with _Tp = rclcpp::Publisher<std_msgs::msg::Int64_<std::allocator<void> > >]’
  129 |       shared_ptr(const shared_ptr&) noexcept = default;
      |       ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:129:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/9/bits/shared_ptr.h:127:17: note: candidate: ‘constexpr std::shared_ptr<_Tp>::shared_ptr() [with _Tp = rclcpp::Publisher<std_msgs::msg::Int64_<std::allocator<void> > >]’
  127 |       constexpr shared_ptr() noexcept : __shared_ptr<_Tp>() { }
      |                 ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:127:17: note:   candidate expects 0 arguments, 1 provided
make[2]: *** [CMakeFiles/naive.dir/build.make:76: CMakeFiles/naive.dir/src/incrementer.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/naive.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< naive [2.35s, exited with code 2]

sub_{node_->create_subscription<std_msgs::msg::Int64>(in_topic, QUEUE_SIZE, [this](const std_msgs::msg::Int64::UniquePtr msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does

Suggested change
sub_{node_->create_subscription<std_msgs::msg::Int64>(in_topic, QUEUE_SIZE, [this](const std_msgs::msg::Int64::UniquePtr msg)
sub_{node_->create_subscription<std_msgs::msg::Int64>(in_topic, QUEUE_SIZE, [this](const auto& msg)

work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, in the ROS1 implementation the function parameter is auto&, but when I tried to keep it in the ROS2 implementation, this is the error that I got (I think the error is saying it can't deduce the type?):

In file included from /opt/ros/galactic/include/rclcpp/client.hpp:32,
                 from /opt/ros/galactic/include/rclcpp/callback_group.hpp:23,
                 from /opt/ros/galactic/include/rclcpp/any_executable.hpp:20,
                 from /opt/ros/galactic/include/rclcpp/memory_strategy.hpp:25,
                 from /opt/ros/galactic/include/rclcpp/memory_strategies.hpp:18,
                 from /opt/ros/galactic/include/rclcpp/executor_options.hpp:20,
                 from /opt/ros/galactic/include/rclcpp/executor.hpp:36,
                 from /opt/ros/galactic/include/rclcpp/executors/multi_threaded_executor.hpp:26,
                 from /opt/ros/galactic/include/rclcpp/executors.hpp:21,
                 from /opt/ros/galactic/include/rclcpp/rclcpp.hpp:156,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/include/naive/incrementer.hpp:38,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:1:
/opt/ros/galactic/include/rclcpp/function_traits.hpp: In instantiation of ‘struct rclcpp::function_traits::function_traits<Incrementer::Incrementer(std::shared_ptr<rclcpp::Node>, const string&, const string&)::<lambda(const auto:37&)> >’:
/opt/ros/galactic/include/rclcpp/subscription_traits.hpp:97:8:   required from ‘struct rclcpp::subscription_traits::has_message_type<Incrementer::Incrementer(std::shared_ptr<rclcpp::Node>, const string&, const string&)::<lambda(const auto:37&)>, std::allocator<void>, void, void, void, void>’
/opt/ros/galactic/include/rclcpp/node.hpp:220:5:   required by substitution of ‘template<class MessageT, class CallbackT, class AllocatorT, class CallbackMessageT, class SubscriptionT, class MessageMemoryStrategyT> std::shared_ptr<SubscriptionT> rclcpp::Node::create_subscription(const string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = std_msgs::msg::Int64_<std::allocator<void> >; CallbackT = Incrementer::Incrementer(std::shared_ptr<rclcpp::Node>, const string&, const string&)::<lambda(const auto:37&)>; AllocatorT = std::allocator<void>; CallbackMessageT = <missing>; SubscriptionT = <missing>; MessageMemoryStrategyT = <missing>]’
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:15:84:   required from here
/opt/ros/galactic/include/rclcpp/function_traits.hpp:51:9: error: decltype cannot resolve address of overloaded function
   51 |   using arguments = typename tuple_tail<
      |         ^~~~~~~~~
/opt/ros/galactic/include/rclcpp/function_traits.hpp:57:9: error: decltype cannot resolve address of overloaded function
   57 |   using argument_type = typename std::tuple_element<N, arguments>::type;
      |         ^~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/function_traits.hpp:59:9: error: decltype cannot resolve address of overloaded function
   59 |   using return_type = typename function_traits<decltype( &FunctionT::operator())>::return_type;
      |         ^~~~~~~~~~~
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp: In constructor ‘Incrementer::Incrementer(std::shared_ptr<rclcpp::Node>, const string&, const string&)’:
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:15:84: error: no matching function for call to ‘rclcpp::Node::create_subscription<std_msgs::msg::Int64>(const string&, const int&, Incrementer::Incrementer(std::shared_ptr<rclcpp::Node>, const string&, const string&)::<lambda(const auto:37&)>)’
   15 |                                                                                   })} {}
      |                                                                                    ^
In file included from /opt/ros/galactic/include/rclcpp/executors/single_threaded_executor.hpp:28,
                 from /opt/ros/galactic/include/rclcpp/executors.hpp:22,
                 from /opt/ros/galactic/include/rclcpp/rclcpp.hpp:156,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/include/naive/incrementer.hpp:38,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:1:
/opt/ros/galactic/include/rclcpp/node.hpp:229:3: note: candidate: ‘template<class MessageT, class CallbackT, class AllocatorT, class CallbackMessageT, class SubscriptionT, class MessageMemoryStrategyT> std::shared_ptr<SubscriptionT> rclcpp::Node::create_subscription(const string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>&, typename MessageMemoryStrategyT::SharedPtr)’
  229 |   create_subscription(
      |   ^~~~~~~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/node.hpp:229:3: note:   substitution of deduced template arguments resulted in errors seen above
/home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:15:85: error: no matching function for call to ‘std::shared_ptr<rclcpp::Subscription<std_msgs::msg::Int64_<std::allocator<void> > > >::shared_ptr(<brace-enclosed initializer list>)’
   15 |                                                                                   })} {}
      |                                                                                     ^
In file included from /usr/include/c++/9/memory:81,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/include/naive/incrementer.hpp:37,
                 from /home/bilal/ws/src/ros2-testing-templates/naive/src/incrementer.cpp:1:
/usr/include/c++/9/bits/shared_ptr.h:367:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Tp>&, std::nothrow_t) [with _Tp = rclcpp::Subscription<std_msgs::msg::Int64_<std::allocator<void> > >]’
  367 |       shared_ptr(const weak_ptr<_Tp>& __r, std::nothrow_t)
      |       ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:367:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/shared_ptr.h:358:2: note: candidate: ‘template<class _Alloc, class ... _Args> std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...)’
  358 |  shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:358:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:307:17: note: candidate: ‘constexpr std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t) [with _Tp = rclcpp::Subscription<std_msgs::msg::Int64_<std::allocator<void> > >; std::nullptr_t = std::nullptr_t]’
  307 |       constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
      |                 ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:307:17: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/9/bits/shared_ptr.h:290:2: note: candidate: ‘template<class _Yp, class _Del, class> std::shared_ptr<_Tp>::shared_ptr(std::unique_ptr<_Up, _Ep>&&)’
  290 |  shared_ptr(unique_ptr<_Yp, _Del>&& __r)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:290:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:282:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::auto_ptr<_Up>&&)’
  282 |  shared_ptr(auto_ptr<_Yp>&& __r);
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:282:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:275:11: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Yp>&)’
  275 |  explicit shared_ptr(const weak_ptr<_Yp>& __r)
      |           ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:275:11: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:263:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Yp>&&)’
  263 |  shared_ptr(shared_ptr<_Yp>&& __r) noexcept
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:263:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:254:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = rclcpp::Subscription<std_msgs::msg::Int64_<std::allocator<void> > >]’
  254 |       shared_ptr(shared_ptr&& __r) noexcept
      |       ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:254:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/9/bits/shared_ptr.h:246:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&)’
  246 |  shared_ptr(const shared_ptr<_Yp>& __r) noexcept
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:246:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:234:2: note: candidate: ‘template<class _Yp> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&, std::shared_ptr<_Tp>::element_type*)’
  234 |  shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) noexcept
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:234:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:212:2: note: candidate: ‘template<class _Deleter, class _Alloc> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter, _Alloc)’
  212 |  shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:212:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:193:2: note: candidate: ‘template<class _Yp, class _Deleter, class _Alloc, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter, _Alloc)’
  193 |  shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:193:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:173:2: note: candidate: ‘template<class _Deleter> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter)’
  173 |  shared_ptr(nullptr_t __p, _Deleter __d)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:173:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:156:2: note: candidate: ‘template<class _Yp, class _Deleter, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter)’
  156 |  shared_ptr(_Yp* __p, _Deleter __d)
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:156:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:139:2: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*)’
  139 |  shared_ptr(_Yp* __p) : __shared_ptr<_Tp>(__p) { }
      |  ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:139:2: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/shared_ptr.h:129:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Tp>&) [with _Tp = rclcpp::Subscription<std_msgs::msg::Int64_<std::allocator<void> > >]’
  129 |       shared_ptr(const shared_ptr&) noexcept = default;
      |       ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:129:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/9/bits/shared_ptr.h:127:17: note: candidate: ‘constexpr std::shared_ptr<_Tp>::shared_ptr() [with _Tp = rclcpp::Subscription<std_msgs::msg::Int64_<std::allocator<void> > >]’
  127 |       constexpr shared_ptr() noexcept : __shared_ptr<_Tp>() { }
      |                 ^~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:127:17: note:   candidate expects 0 arguments, 1 provided
make[2]: *** [CMakeFiles/naive.dir/build.make:76: CMakeFiles/naive.dir/src/incrementer.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/naive.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< naive [1.71s, exited with code 2]

{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is wrong

std_msgs::msg::Int64 incremented;
incremented.data = msg->data + 1;
pub_->publish(incremented);
})} {}
19 changes: 19 additions & 0 deletions ros2/naive/src/node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "naive/incrementer.hpp"

#include "rclcpp/rclcpp.hpp"

int main(int argc, char **argv) {

griswaldbrooks marked this conversation as resolved.
Show resolved Hide resolved
rclcpp::init(argc,argv);

auto const node = std::make_shared<rclcpp::Node>("incrementer");
griswaldbrooks marked this conversation as resolved.
Show resolved Hide resolved

Incrementer incrementer{node, "/in", "/out"};

rclcpp::spin(node);

rclcpp::shutdown();

return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, this is unnecessary. It's specified that if a program reaches the end, it will always return 0 so it's safe to remove this.

griswaldbrooks marked this conversation as resolved.
Show resolved Hide resolved

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these extra newlines, especially the newline after return is harming readability. And don't forget to add a trailing newline at the end of the file.