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

ROS built-in primitive types not declared

asked 2017-02-24 20:04:59 -0600

Kening Ren gravatar image

updated 2017-02-25 03:52:47 -0600

gvdhoorn gravatar image

Hello, I am new in using ROS. I see a problem with ROS built-in primitive type, such as int16.

Here is the code, it is very simple.

#include <ros/ros.h>

int main(int argc, char** argv)                                                                   
{                                                                                                 
  int16 i = 0;
  ros::init(argc, argv, "data_broadcaster");                                                      
  ros::NodeHandle n;

  ros::Rate loop_rate(100);

  while(ros::ok())                                                                                
  {
    loop_rate.sleep();
    i = i + 4;
    if (i == 360) i = 0;                                                                          
  }                                                                                               
  return 0;                                                                                       
}

I run catkin_make to build the code and get the following error.

[ 50%] Building CXX object data_capturer/CMakeFiles/data_broadcaster.dir/src/data_broadcaster.cpp.o
/home/kening/catkin_ws_2/src/data_capturer/src/data_broadcaster.cpp: In function ‘int main(int, char**)’:
/home/kening/catkin_ws_2/src/data_capturer/src/data_broadcaster.cpp:5:3: error: ‘int16’ was not declared in this scope
   int16 i = 0;
   ^
/home/kening/catkin_ws_2/src/data_capturer/src/data_broadcaster.cpp:17:5: error: ‘i’ was not declared in this scope
     i = i + 4;
     ^
data_capturer/CMakeFiles/data_broadcaster.dir/build.make:62: recipe for target 'data_capturer/CMakeFiles/data_broadcaster.dir/src/data_broadcaster.cpp.o' failed
make[2]: *** [data_capturer/CMakeFiles/data_broadcaster.dir/src/data_broadcaster.cpp.o] Error 1
CMakeFiles/Makefile2:837: recipe for target 'data_capturer/CMakeFiles/data_broadcaster.dir/all' failed
make[1]: *** [data_capturer/CMakeFiles/data_broadcaster.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

My CMakeLists.txt is:

cmake_minimum_required(VERSION 2.8.3)
project(data_capturer)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)
catkin_package()
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(data_broadcaster src/data_broadcaster.cpp)
add_dependencies(data_broadcaster
  ${data_broadcaster_EXPORTED_TARGETS}
  ${catkin_EXPORTED_TARGETS}
)
target_link_libraries(data_broadcaster
  ${catkin_LIBRARIES}
)

My package.xml is:

<?xml version="1.0"?>
<package>
  <name>data_capturer</name>
  <version>0.0.0</version>
  <description>The data_capturer package</description>
  <maintainer email="myemail@whereisit.com">Ku</maintainer>
  <license>BSD</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>

  <export>
  </export>
</package>

I could not figure out why int16 is not declared. Did I forget to include any header file. Or is there something wrong with my CMakeLists.txt and package.xml?

Please help. Thank you. -Kening

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-02-25 04:00:07 -0600

gvdhoorn gravatar image

updated 2017-02-25 04:01:43 -0600

I see a problem with ROS built-in primitive type, such as int16.

The only place where int16 is a legal identifier in a ROS context (ignoring custom type definitions in the various languages that have client libraries) is in the ROS msg specification. You cannot use those directly in any client code, as they are mapped onto types native to the language in which the client library is written.

For C++, int16 is mapped onto int16_t. int16 is not a type in C++, so the compiler error is to be expected.

Did I forget to include any header file

Add #include <cstdint> to your .cpp file and try again.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-02-24 20:04:59 -0600

Seen: 376 times

Last updated: Feb 25 '17