Ask Your Question
0

MessagePoolMemoryStrategy initialization fails with sensor_msgs/msg/imu

asked 2019-05-11 06:50:14 -0600

mann gravatar image

updated 2019-05-11 06:50:28 -0600

My setup:

ROS2 crystal, colcon build system, Ubuntu 18.04.1, gcc compiler:7.3.0

Hi , I tried initializing the message pool memory strategy for two different message types, the "Twist" message from geometry_msgs and "Imu" msg from sensor_msgs. Here is the code:

#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/imu.hpp"
#include <rclcpp/strategies/message_pool_memory_strategy.hpp>   
#include "geometry_msgs/msg/twist.hpp"

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

  rclcpp::init(argc, argv);    
  auto memory_strategy_twist       =std::make_shared<rclcpp::strategies::message_pool_memory_strategy::MessagePoolMemoryStrategy  <geometry_msgs::msg::Twist, 1>>(); 

  auto memory_strategy_imu         = std::make_shared<rclcpp::strategies::message_pool_memory_strategy::MessagePoolMemoryStrategy <sensor_msgs::msg::Imu,1 >>();                                             

  rclcpp::shutdown();
  return EXIT_SUCCESS;

}

I get a compiler error:

/home/xxxx/demo1/src/test1-1.cpp: In function ‘int main(int, char**)’:
/home/xxxx/demo1/src/test1-1.cpp:15:143: error: wrong number of template arguments (1, should be at
 least 2)                                                                                         
 :strategies::message_pool_memory_strategy::MessagePoolMemoryStrategy<sensor_msgs::msg::Imu    >>()
;                                                                                                 
                                                                                        ^~~

when I comment out the initialization for memory_strategy_imu , the build is successful. Any Ideas on how I can get it to compile for Imu message types?

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(demo1)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)                                                                      
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)


add_executable(Demo_test
  src/test1-1.cpp                                                                                   )                                                                                               
 ament_target_dependencies(Demo_test
   "rclcpp"                                                                                                                                                                                                                                                                       "sensor_msgs"
   "geometry_msgs")

 install(TARGETS
   Demo_test
 DESTINATION bin)  
ament_package()

package.xml:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
  <name>demo1</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="xxx">xxx</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <build_depend>rclcpp</build_depend> 
  <build_depend>sensor_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>

  <exec_depend>geometry_msgs</exec_depend>  
  <exec_depend>rclcpp</exec_depend>  
  <exec_depend>sensor_msgs</exec_depend>  

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-05-11 07:42:04 -0600

gvdhoorn gravatar image

updated 2019-05-11 07:53:01 -0600

I'm not 100% sure, but I believe it looks like sensor_msgs::msg::Imu fails the rosidl_generator_traits::has_fixed_size(..) check (base version here, specialised for sensor_msgs::msg::Imu in include/std_msgs/msg/header__traits.hpp), causing the std::enable_if<..> to fail (here), causing your compilation to fail.

sensor_msgs::msg::Imu is not a fixed size message as it contains a std_msgs::msg::Header, which contains a string, which is (potentially) unbounded.

Checking std_msgs/msg/header__traits.hpp confirms this:

template<>
struct has_fixed_size<std_msgs::msg::Header>
  : std::integral_constant<bool, false> {};

I would actually expect all messages that have a Header to fail the check in a similar way.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-05-11 06:50:14 -0600

Seen: 29 times

Last updated: May 11