0
$\begingroup$

Rosanswers logo

HI, I am new to ROS so this might be a completely ignorant question. So far I was using pyserial so run serial communication in ROS but now I am trying to use C++ for serial communication. I looked around and realized that https://github.com/wjwwood/serial library is suitable for me. I downloaded it and installed it exactly like the instructions. However when I tried to run the serial example I get the error while running catkin_make that serial.h is not found. I am assuming that I have to add the path of the new library to the ROS and I am not sure how to do that. I would appreciate any help in this matter.

Thank you,

TM

EDIT (By wjwwood):

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)


## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependencies might have been
##     pulled in transitively but can be declared for certainty nonetheless:
##     * add a build_depend tag for "message_generation"
##     * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
add_message_files(
   FILES
   Num.msg
#   Message2.msg
)

## Generate services in the 'srv' folder
add_service_files(
    FILES 
    AddTwoInts.srv
#   Service2.srv
)

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
generate_messages(
   DEPENDENCIES
   std_msgs
 )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
)


## Declare a cpp library
# add_library(beginner_tutorials
#   src/${PROJECT_NAME}/beginner_tutorials.cpp
# )

## Declare a cpp executable
# add_executable(beginner_tutorials_node src/beginner_tutorials_node.cpp)

## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
#add_dependencies( talker beginner_tutorials_generate_messages_cpp)


#beginner_tutorials_node
## Specify libraries to link a library or executable target against
# target_link_libraries(beginner_tutorials_node
#   ${catkin_LIBRARIES}
# )

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
# install(TARGETS beginner_tutorials beginner_tutorials_node
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_beginner_tutorials.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)


include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})

add_executable(serial_example src/serial_example.cc)
target_link_libraries(serial_example ${catkin_LIBRARIES})


add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})

package.xml:

 <?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.0.0</version>
  <description>The beginner_tutorials package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag --> 
  <!-- Example:  -->
  <!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
  <maintainer email="[email protected]">andromeda</maintainer>


  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <license>TODO</license>


  <!-- Url tags are optional, but mutiple are allowed, one per tag -->
  <!-- Optional attribute type can be: website, bugtracker, or repository -->
  <!-- Example: -->
  <!-- <url type="website">http://wiki.ros.org/beginner_tutorials</url> -->


  <!-- Author tags are optional, mutiple are allowed, one per tag -->
  <!-- Authors do not have to be maintianers, but could be -->
  <!-- Example: -->
  <!-- <author email="[email protected]">Jane Doe</author> -->


  <!-- The *_depend tags are used to specify dependencies -->
  <!-- Dependencies can be catkin packages or system dependencies -->
  <!-- Examples: -->
  <!-- Use build_depend for packages you need at compile time: -->
 <build_depend>message_generation</build_depend>
  <!-- Use buildtool_depend for build tool packages: -->
  <!--   <buildtool_depend>catkin</buildtool_depend> -->
  <!-- Use run_depend for packages you need at runtime: -->
 <run_depend>message_runtime</run_depend>
  <!-- Use test_depend for packages you need only for testing: -->
  <!--   <test_depend>gtest</test_depend> -->
  <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>

  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- You can specify that this package is a metapackage here: -->
    <!-- <metapackage/> -->

    <!-- Other tools can request additional information be placed here -->

  </export>
</package>

Output from catkin_make:

Base path: /home/andromeda/catkin_ws
Source space: /home/andromeda/catkin_ws/src
Build space: /home/andromeda/catkin_ws/build
Devel space: /home/andromeda/catkin_ws/devel
Install space: /home/andromeda/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/andromeda/catkin_ws/build"
####
####
#### Running command: "make -j4 -l4" in "/home/andromeda/catkin_ws/build"
####
[  0%] [  0%] [  0%] Built target std_msgs_generate_messages_py
Built target std_msgs_generate_messages_cpp
Built target std_msgs_generate_messages_lisp
[  9%] Built target listener
[ 18%] Building CXX object beginner_tutorials/CMakeFiles/serial_example.dir/src/serial_example.cc.o
[ 36%] Built target beginner_tutorials_generate_messages_cpp
[ 72%] [ 81%] Built target beginner_tutorials_generate_messages_py
Built target talker
[100%] Built target beginner_tutorials_generate_messages_lisp
[100%] Built target beginner_tutorials_generate_messages
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc: In function ‘void enumerate_ports()’:
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:49:8: error: ‘PortInfo’ is not a member of ‘serial’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:49:8: error: ‘PortInfo’ is not a member of ‘serial’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:49:24: error: template argument 1 is invalid
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:49:24: error: template argument 2 is invalid
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:49:40: error: invalid type in declaration before ‘=’ token
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:49:42: error: ‘list_ports’ is not a member of ‘serial’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:51:8: error: ‘PortInfo’ is not a member of ‘serial’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:51:8: error: ‘PortInfo’ is not a member of ‘serial’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:51:24: error: template argument 1 is invalid
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:51:24: error: template argument 2 is invalid
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:51:36: error: expected initializer before ‘iter’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:53:8: error: ‘iter’ was not declared in this scope
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:53:30: error: request for member ‘end’ in ‘devices_found’, which is of non-class type ‘int’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:55:1: error: ‘PortInfo’ is not a member of ‘serial’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:55:18: error: expected ‘;’ before ‘device’
/home/andromeda/catkin_ws/src/beginner_tutorials/src/serial_example.cc:57:27: error: ‘device’ was not declared in this scope
make[2]: *** [beginner_tutorials/CMakeFiles/serial_example.dir/src/serial_example.cc.o] Error 1
make[1]: *** [beginner_tutorials/CMakeFiles/serial_example.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

Originally posted by nicobari on ROS Answers with karma: 86 on 2014-06-14

Post score: 0

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

If you're using ROS on ubuntu, you should be able to install the serial library through apt:

sudo apt-get install ros-hydro-serial

(Change hydro to the name of your ROS distribution if you're using a different version of ROS)


Originally posted by ahendrix with karma: 47576 on 2014-06-14

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by nicobari on 2014-06-14:
Thanks for replying, I am running hydro on Ubuntu 12.04 and installed the serial package. After Installing I copied the example https://github.com/wjwwood/serial/blob/master/examples/serial_example.cc and tried to compile it which gives a bunch of errors like xxxx is not a member of serial. I am assuming the serial package I installed is not the same as https://github.com/wjwwood/serial. Is there an example which shows how to use the Ros-hydro-serial? Thanks again.

Regards, TM

Comment by ahendrix on 2014-06-14:
Can you include your CMakeLists, package.xml, the commands you're using to compile and the exact compiler output in your question please?

Comment by nicobari on 2014-06-14:
I had to post as an answer as I was not allowed to post more than 300 words

Comment by ahendrix on 2014-06-15:
For future reference, you can edit your question to include more information.

Comment by nicobari on 2014-06-16:
Thanks for the tip, but I am still having problem with compiling the serial example

Comment by ahendrix on 2014-06-16:
It looks like you have mismatched versions of the sample and the library. You should find the version of the example that goes with the version of the library that you're using.

$\endgroup$
0
$\begingroup$

Rosanswers logo

You never declare a dependency on serial and you never use if in your CMakeLists.txt.

I would recommend adding a <build_depend>serial</build_depend> in your package.xml, as well as adding serial to the file of things being found in the line find_package(catkin ....


Originally posted by William with karma: 17335 on 2014-06-15

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by nicobari on 2014-06-15:
Update: I implemented the changes recommended by you but I still get the same error. Now my find package looks like: find_package(catkin REQUIRED COMPONENTS

catkin REQUIRED

roscpp rospy std_msgs message_generation serial )

$\endgroup$
0
$\begingroup$

Rosanswers logo

So this is how I resolved the compile errors (haven't run the code), I downloaded 1.1.7 version of serial library from https://github.com/wjwwood/serial/releases. Removed ros-hydro-serial by sudo apt-get -purge remove ros-hydro-serial . I installed the serial 1.1.7 according to the instructions and noted that SerialConfig.cmake was installed in /tmp/usr/local/share/serial/cmake which I added to ROS_PACKAGE_PATH. Then in beginner_tutorials package I added set(SERIAL_DIR /tmp/usr/local/share/serial/cmake) above find_package(catkin REQUIRED ..... serial) along with the changes suggested by William who is the author of the serial library. It seems like when I use sudo apt-get install ros-hydro-serial the header files get installed in /opt/ros/hydro/include/serial but I couldn't find any library files in /opt/ros/hydro/lib/. so compiler used to give error saying xxx not found in class serial. Also like ahendrix said I made sure that I have the right version of the serial_example.cc

Thanks for the help, TM


Originally posted by nicobari with karma: 86 on 2014-06-17

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.