ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 Debugging Techniques

asked 2019-02-07 15:52:57 -0600

updated 2019-02-07 16:56:02 -0600

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_ ...
(more)
edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
4

answered 2019-02-07 16:12:39 -0600

tfoote gravatar image

This is a linking error not a compile error which is why there are no line numbers. To fix that you will need to make sure to update your CMakeLists.txt to make sure to link against geometry_msgs in place of the examples std_msgs. And you'll likely need to add it as a dependency in the CMakeLists.txt at the top and in the package.xml for proper book keeping.

You'll also note that this error is for publisher_member_function where you look to be showing example code for the subscriber. If you want more help you'll need to help us reproduce your problem more fully. If you're only changing a few lines of the tutorial maybe a full diff of the directory would be helpful. Please edit your question to provide more information if this isn't enough to get you going.

edit flag offensive delete link more

Comments

Ah okay. I have tried to update my CMakesLists.txt and package.xml but am still getting an error. I have updated my question with both those files.

shoemakerlevy9 gravatar image shoemakerlevy9  ( 2019-02-07 16:54:21 -0600 )edit
3

answered 2019-02-12 07:54:57 -0600

alsora gravatar image

As @tfoote pointed out, you have to add geometry_msgs package to the dependencies.

However, even after that, there are 2 errors in your C++ code

  1. RCLCPP_INFO("derp"); This is not allowed, as the first argument to RCLCPP_* should be a logger object.

  2. msg->linear[0] this is not correct. The linear field of the message is of type Vector3, but it's not a vector. Look at the implementation of this type here and you will see that you have to access to its fields using msg->linear.x, msg->linear.y, msg->linear.z

edit flag offensive delete link more
2

answered 2019-02-08 09:43:18 -0600

akifusenet gravatar image

I've tried compiling your code and different than your case it gave me compilation errors.

After I changed one RCLCPP_INFO line in callback and commented out the one in the main function, it successfully compiled.

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_INFO(this->get_logger(), "I heard: '%i, %i, %i'", msg->linear.x, msg->linear.y, msg->linear.z);
  }
  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;
}
edit flag offensive delete link more
0

answered 2020-11-17 08:09:43 -0600

fredBeauj gravatar image

I got a similar linker error because I was using a static library from package A that depended on message foo and when linking an executable in package B that depends on A, the linker got this

[ 83%] Linking CXX executable B

/usr/bin/c++ node.cpp.o -o B_exe install/A/lib/libfoo_msgs__rosidl_typesupport_cpp.so libA.a

I couldn't figure out how to tell cmake to switch the order of libs it got from ament, so I just build a shared library for A, then the linker order is not important

/usr/bin/c++ node.cpp.o -o B_exe install/A/lib/libfoo_msgs__rosidl_typesupport_cpp.so libA.so
edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2019-02-07 15:52:57 -0600

Seen: 6,621 times

Last updated: Nov 17 '20