ROS2 Debugging Techniques
I'm just getting started learning ROS2 and I'm going through the tutorials. I am trying to create a subscriber to /cmd_vel. I'm working off the examples_rclcpp_minimal_subscriber member_functions code. All I did was change the topic name and type to /cmd_vel and geometry_msgs/Twist and I get all sorts of unhelpful errors, no line numbers, and its complaining about Strings which I don't even have in the code now.
member_functions.cpp
// Copyright 2016 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "geometry_msgs/msg/twist.hpp"
using std::placeholders::_1;
class MinimalSubscriber : public rclcpp::Node
{
public:
MinimalSubscriber()
: Node("minimal_subscriber")
{
subscription_ = this->create_subscription<geometry_msgs::msg::Twist>(
"/cmd_vel/managed", std::bind(&MinimalSubscriber::topic_callback, this, _1));
}
private:
void topic_callback(const geometry_msgs::msg::Twist::SharedPtr msg)
{
RCLCPP_INFO(this->get_logger(), "I heard: '%i, %i, %i'", msg->linear[0], msg->linear[1], msg->linear[2]);
}
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr subscription_;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
RCLCPP_INFO("derp");
rclcpp::spin(std::make_shared<MinimalSubscriber>());
rclcpp::shutdown();
return 0;
}
Error
nick@nick-XPS-15-9550:~/ros2_overlay_ws/src/examples$ colcon build Starting >>> examples_rclcpp_minimal_action_client Starting >>> examples_rclcpp_minimal_action_server Starting >>> examples_rclcpp_minimal_client Starting >>> examples_rclcpp_minimal_publisher
--- stderr: examples_rclcpp_minimal_publisher CMakeFiles/publisher_lambda.dir/lambda.cpp.o: In function `rclcpp::Publisher<std_msgs::msg::String_<std::allocator<void>
>, std::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_publisher_options_t const&, std::shared_ptr<std::allocator<std_msgs::msg::String_<std::allocator<void>
> > > const&)': lambda.cpp:(.text._ZN6rclcpp9PublisherIN8std_msgs3msg7String_ISaIvEEES4_EC2EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK23rcl_publisher_options_tRKSt10shared_ptrISaIS5_EE[_ZN6rclcpp9PublisherIN8std_msgs3msg7String_ISaIvEEES4_EC5EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK23rcl_publisher_options_tRKSt10shared_ptrISaIS5_EE]+0x22): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std_msgs::msg::String_<std::allocator<void>
> >()' collect2: error: ld returned 1 exit status make[2]: *** [publisher_lambda] Error 1 make[1]:
*** [CMakeFiles/publisher_lambda.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... CMakeFiles/publisher_not_composable.dir/not_composable.cpp.o: In function `rclcpp::Publisher<std_msgs::msg::String_<std::allocator<void>
>, std::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_publisher_options_t const&, std::shared_ptr<std::allocator<std_msgs::msg::String_<std::allocator<void>
> > > const&)': not_composable.cpp:(.text._ZN6rclcpp9PublisherIN8std_msgs3msg7String_ISaIvEEES4_EC2EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK23rcl_publisher_options_tRKSt10shared_ptrISaIS5_EE[_ZN6rclcpp9PublisherIN8std_msgs3msg7String_ISaIvEEES4_EC5EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK23rcl_publisher_options_tRKSt10shared_ptrISaIS5_EE]+0x22): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std_msgs::msg::String_<std::allocator<void>
> >()' collect2: error: ld returned 1 exit status make[2]: *** [publisher_not_composable] Error 1 make[1]: *** [CMakeFiles/publisher_not_composable.dir/all] Error 2 CMakeFiles/publisher_member_function.dir/member_function.cpp.o: In function `rclcpp::Publisher<std_msgs::msg::String_<std::allocator<void>
>, std::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_publisher_options_t const&, std::shared_ptr<std::allocator<std_msgs::msg::String_ ...