Last active
February 19, 2016 16:10
-
-
Save gerkey/1f1187bce077ba6e737a to your computer and use it in GitHub Desktop.
ROS 1 message reuse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8.3) | |
find_package(sensor_msgs REQUIRED) | |
include_directories(${sensor_msgs_INCLUDE_DIRS}) | |
link_directories(${sensor_msgs_LIBRARY_DIRS}) | |
add_executable(foo foo.cpp) | |
target_link_libraries(foo ${sensor_msgs_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sensor_msgs/LaserScan.h> | |
#include <stdio.h> | |
int | |
main(void) | |
{ | |
sensor_msgs::LaserScan scan; | |
for(int i=0; i<100; i++) | |
scan.ranges.push_back(42.0*i); | |
for(std::vector<float>::const_iterator it = scan.ranges.begin(); | |
it != scan.ranges.end(); | |
++it) | |
printf("%f\n", *it); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install ros-indigo-sensor-msgs | |
# cd to directory with CMakeLists.txt and foo.cpp | |
export CMAKE_PREFIX_PATH=/opt/ros/indigo:$CMAKE_PREFIX_PATH | |
mkdir build | |
cd build | |
cmake .. | |
make |
Thanks for the tip; it turns out that target_link_libraries
can also be skipped, at least in my minimal testing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
link_directories
line is probably unnecessary.