0
$\begingroup$

Rosanswers logo

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="[email protected]">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 the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "serial" with any
  of the foll

Originally posted by massyp on ROS Answers with karma: 17 on 2019-07-10

Post score: 1


Original comments

Comment by [email protected] on 2019-07-14:
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.

Comment by massyp on 2019-07-15:
No, I have installed that package but there is a problem in the path to the serial.h file

Comment by gvdhoorn on 2019-07-15:
Please edit your question and show us your current CMakeLists.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.

Comment by massyp on 2019-07-15:
The CmakeLists.txt is edited now

Comment by massyp on 2019-07-15:
Ok, I will search slowly in my directories to see what's wrong with the installation

Comment by gvdhoorn on 2019-07-15:
It's more likely that things weren't working because your CMakeLists.txt was not correct.

See the latest edit of my answer.

Comment by massyp on 2019-07-15:
Ok, thank you very much. I will post I comment when I resolve it

Comment by gvdhoorn on 2019-07-15:
Just mark the question as solved by clicking on the checkmark to the left of the answer.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2019-07-10

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by massyp on 2019-07-10:
No, I don't. I will try and come back

Comment by massyp on 2019-07-10:
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!!!

Comment by gvdhoorn on 2019-07-10:
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.

Comment by massyp on 2019-07-10:
I can't put all of that in a comment

Comment by gvdhoorn on 2019-07-10:
And you shouldn't post it in a comment.

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

Comment by massyp on 2019-07-10:
Yes, it's done, so you have all the elements in the first answer I think.

Comment by massyp on 2019-07-10:
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

Comment by gvdhoorn on 2019-07-10:
Don't post this sort of thing in a comment ..

I thought we'd just gone through this.

Comment by massyp on 2019-07-11:
I edited the answer

$\endgroup$

Your Answer

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