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

Trouble With Serial communication

asked 2014-06-14 11:05:03 -0500

nicobari gravatar image

updated 2014-06-15 00:58:30 -0500

William gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-06-17 08:51:15 -0500

nicobari gravatar image

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/rel... . 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

edit flag offensive delete link more
3

answered 2014-06-15 01:09:50 -0500

William gravatar image

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

edit flag offensive delete link more

Comments

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 )

nicobari gravatar image nicobari  ( 2014-06-15 06:08:25 -0500 )edit
2

answered 2014-06-14 13:20:49 -0500

ahendrix gravatar image

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)

edit flag offensive delete link more

Comments

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

nicobari gravatar image nicobari  ( 2014-06-14 14:23:38 -0500 )edit

Can you include your CMakeLists, package.xml, the commands you're using to compile and the exact compiler output in your question please?

ahendrix gravatar image ahendrix  ( 2014-06-14 15:27:14 -0500 )edit

I had to post as an answer as I was not allowed to post more than 300 words

nicobari gravatar image nicobari  ( 2014-06-14 20:46:25 -0500 )edit

For future reference, you can edit your question to include more information.

ahendrix gravatar image ahendrix  ( 2014-06-15 01:20:12 -0500 )edit

Thanks for the tip, but I am still having problem with compiling the serial example

nicobari gravatar image nicobari  ( 2014-06-16 18:23:42 -0500 )edit

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.

ahendrix gravatar image ahendrix  ( 2014-06-16 18:47:45 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-14 11:05:03 -0500

Seen: 2,482 times

Last updated: Jun 17 '14