Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ROS built-in primitive types not declared

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:

<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

ROS built-in primitive types not declared

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="">

#include <ros/ros.h>

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

n; ros::Rate loop_rate(100);

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

}

I run catkin_make 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)’:
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

2

My CMakeLists.txt 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 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>

<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>

<run_depend>std_msgs</run_depend> <export> </export> </package>

</package>

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

Please help. Thank you. -Kening