Ask Your Question
0

fatal error: serial/serial.h: no such file or directory in ros

asked 2019-07-10 04:23:34 -0600

massyp gravatar image

updated 2019-07-15 07:31:22 -0600

Hello evrybody,

I'm using ROS kenetic and I'm trying to read data from serial port of my laptop. For this I use the code below and I use the header file serial.h to instantiate my serial object. When I execute Catkin_make it return' me this error :

/home/stage/catkin_ws/src/mon_noeud/src/Imu_node.cpp:2:27: fatal error: serial/serial.h: No such file or directory
compilation terminated.
mon_noeud/CMakeFiles/Imu_node.dir/build.make:62: recipe for target 'mon_noeud/CMakeFiles/Imu_node.dir/src/Imu_node.cpp.o' failed
make[2]: *** [mon_noeud/CMakeFiles/Imu_node.dir/src/Imu_node.cpp.o] Error 1
CMakeFiles/Makefile2:3488: recipe for target 'mon_noeud/CMakeFiles/Imu_node.dir/all' failed
make[1]: *** [mon_noeud/CMakeFiles/Imu_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

I hope someone can help me with this

#include <ros/ros.h>
#include <serial/serial.h>
#include <std_msgs/String.h>
#include <std_msgs/Empty.h>

serial::Serial ser;

int main(int argc, char** argv){

ros::init(argc,argc,"Imu_node");
ros::NodeHandle nh;
ros::Publisher read_port = nh.advertise<std_msgs::String>("read", 1000);
ros::Rate loop_rate(200);

try 
{
   ser.setPort("/dev/ttyACM0");
   ser.setBaudrate(9600);
   serial::Timeout to = serial::Timeout::simpleTimeout(1000);
   ser.setTimeout(to);
   ser.open();
}
catch (serial::IOException& e)
{
   ROS_ERROR_STREAM("Unable to open port ");
   return -1;
}

if(ser.isOpen()){
    ROS_INFO_STREAM("serial port initialized");
} 
else{
     return -1;
     }

while(ros::ok()){

 if(ser.available()){
    ROS_INFO_STREAM("reading from serial port ");
    std_msgs::String result;
    result.data = ser.read(ser.available());
    ROS_INFO_STREAM("Read: " << result.data);
    read_pub.publish(result);

                    }


    ros::spinOnce();
    r.sleep();
             } 

}

Edit:

this first code is the cmakelist :

cmake_minimum_required(VERSION 2.8.3)
project(mon_noeud)

find_package(catkin REQUIRED COMPONENTS
   message_generation
   message_runtime
   roscpp
   rospy
   serial 
)
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES mon_noeud
#  CATKIN_DEPENDS message_generation message_runtime roscpp rospy
#  DEPENDS system_lib
) 
include_directories(include)

set(serial_SRCS serial/src/serial.cc include/serial/serial.h include/serial/v8stdint.h)
if(UNIX)
list(APPEND serial_SRCS src/impl/unix.cc)
else()
list(APPEND serial_SRCS src/impl/win.cc)
endif()

## Add serial library
add_library(serial ${serial_SRCS})
if(UNIX AND NOT APPLE)
target_link_libraries(serial rt)
endif()
add_executable(Imu_node src/Imu_node.cpp)
target_link_libraries(Imu_node serial)
target_link_libraries(Imu_node ${catkin_LIBRARIES})

and this one for the package.xml

 <package format="2"><name>mon_noeud</name><version>0.0.0</version><description>The mon_noeud package</description><maintainer email="stage@todo.todo">stage</maintainer><license>TODO</license>
 <buildtool_depend>catkin</buildtool_depend><build_depend>message_generation</build_depend><build_depend>message_generation</build_depend><build_depend>roscpp</build_depend><build_depend>rospy</build_depend><build_export_depend>roscpp</build_export_depend><build_export_depend>rospy</build_export_depend><exec_depend>message_runtime</exec_depend><exec_depend>roscpp</exec_depend><exec_depend>rospy</exec_depend><!-- The export tag contains other, unspecified, tags --><export><!----></export></package>

the error after addind the serial object to the package.xml and Cmakelist.txt :

Could not find a package configuration file provided by "serial" with any
  of the following names:
    serialConfig.cmake
    serial-config.cmake
  Add the installation prefix of "serial" to CMAKE_PREFIX_PATH or set
  "serial_DIR" to a directory containing one of the above files.  If "serial"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  mon_noeud/CMakeLists.txt:10 (find_package)
-- Could not find the required component 'serial'. The following CMake error indicates that you either need to install ...
(more)
edit retag flag offensive close merge delete

Comments

For your last question, that should because you didn't install the "serial" package. Install it using " sudo apt install ros-kinetic-serial ". Or install from the source code.

skyofyao@gmail.com gravatar imageskyofyao@gmail.com ( 2019-07-14 01:35:07 -0600 )edit

No, I have installed that package but there is a problem in the path to the serial.h file

massyp gravatar imagemassyp ( 2019-07-15 07:21:05 -0600 )edit

Please edit your question and show us your currentCMakeLists.txt.

No, I have installed that package but there is a problem in the path to the serial.h file

The last error message that you've shown ("cannot find pkg cfg file for serial") suggests that the package is not (properly) installed.

We're not even getting to the point where the path to serialh.h is incorrect.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-15 07:23:29 -0600 )edit

The CmakeLists.txt is edited now

massyp gravatar imagemassyp ( 2019-07-15 07:29:27 -0600 )edit

Ok, I will search slowly in my directories to see what's wrong with the installation

massyp gravatar imagemassyp ( 2019-07-15 07:51:16 -0600 )edit

It's more likely that things weren't working because your CMakeLists.txt was not correct.

See the latest edit of my answer.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-15 07:58:13 -0600 )edit

Ok, thank you very much. I will post I comment when I resolve it

massyp gravatar imagemassyp ( 2019-07-15 08:11:39 -0600 )edit

Just mark the question as solved by clicking on the checkmark to the left of the answer.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-15 08:15:13 -0600 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2019-07-10 04:34:36 -0600

gvdhoorn gravatar image

updated 2019-07-15 07:39:10 -0600

have you added the serial package as a dependency to your CMakeLists.txt?


Edit: you haven't added the serial dependency to your CMakeLists.txt, so the include paths are never updated with it and that's most likely why the header can't be found:

find_package(catkin REQUIRED COMPONENTS
  message_generation
  message_runtime
  roscpp
  rospy
)

Refer to catkin documentation » How to do common tasks » Package format 2 (recommended) » C++ catkin library dependencies for information on how to add Catkin package dependencies, but summarising:

add the serial dependency at the end of the list of COMPONENTS in the find_package(catkin ..) call:

find_package(catkin REQUIRED COMPONENTS
  message_generation
  message_runtime
  roscpp
  rospy
  serial
)

You'll also want to add it to the catkin_package(CATKIN_DEPENDS ..) line.

And you'll need to add it as a depend to your package.xml.


Edit:

I followed your steps but the error still persist, I think the problem is with the configuration file of the serial directory.

so how did you install the serial package?


Edit 2:

find_package(catkin REQUIRED COMPONENTS
   message_generation
   message_runtime
   roscpp
   rospy
   serial 
)

[..]

include_directories(include)

Your include path doesn't appear to be setup correctly.

As-is, none of the packages you find_package(catkin .. COMPONENTS ..) is present on the include path, leading to the error you see.

You'll want to add ${catkin_INCLUDE_DIRS} to the include_directories(..) statement.

Again, please catkin documentation » How to do common tasks » Package format 2 (recommended) » C++ catkin library dependencies where this is explained and shown.

edit flag offensive delete link more

Comments

No, I don't. I will try and come back

massyp gravatar imagemassyp ( 2019-07-10 05:05:31 -0600 )edit

Hi, I think that I installed correctly the library, but when I make catkin_make it show the same error and I don't knew how to add this dependence to my cmakelist.txt!!!

massyp gravatar imagemassyp ( 2019-07-10 06:15:18 -0600 )edit

Then you'll have to show us your CMakeLists.txt and package.xml.

Please remove all the boilerplate comments from both files before posting them here. Include just the regular lines.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-10 06:31:21 -0600 )edit

I can't put all of that in a comment

massyp gravatar imagemassyp ( 2019-07-10 06:50:00 -0600 )edit

And you shouldn't post it in a comment.

Just edit your original question: click the edit button/link underneath your original question.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-10 08:47:23 -0600 )edit

Yes, it's done, so you have all the elements in the first answer I think.

massyp gravatar imagemassyp ( 2019-07-10 08:51:49 -0600 )edit

I followed your steps but the error still persist, I think the problem is with the configuration file of the serial directory. It gives me this error :

the answer is edited with the new error

massyp gravatar imagemassyp ( 2019-07-10 09:11:27 -0600 )edit

Don't post this sort of thing in a comment ..

I thought we'd just gone through this.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-10 09:12:32 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-07-10 04:23:34 -0600

Seen: 223 times

Last updated: Jul 15